fix(auth): build the tauri sso redirect url without a relative base (#1924)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).

<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
Erwan Leboucher authored and GitHub committed 2026-08-23 10:51:54 +02:00
commit 118305eb9c
3 files changed
+35 -5

No files matched your search

@@ -0,0 +1,5 @@
---
default: patch
---
Fix the login page crashing with "Invalid URL" on Android WebView below 130
+20
View File
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import { type as osType } from '@tauri-apps/plugin-os';
import {
buildTauriSsoRedirectUrl,
isTauriSsoCallbackTarget,
parseTauriOidcCallback,
parseTauriSsoCallback,
rememberTauriSsoNonce,
@@ -48,6 +49,10 @@ describe('buildTauriSsoRedirectUrl', () => {
expect(url.searchParams.get('server')).toBeNull();
expect(url.searchParams.get('sso_nonce')).toBeTruthy();
});
it('builds the url without resolving against a non-special base', () => {
expect(buildTauriSsoRedirectUrl()).toMatch(/^sable:\/\/login\/lp\/sso-callback\?/);
});
});
describe('takeTauriSsoNonce', () => {
@@ -78,6 +83,21 @@ describe('parseTauriSsoCallback', () => {
});
});
describe('isTauriSsoCallbackTarget', () => {
it('accepts the authority shape', () => {
expect(isTauriSsoCallbackTarget('login', '/lp/sso-callback')).toBe(true);
});
it('accepts the opaque-path shape Chromium below 130 produces', () => {
expect(isTauriSsoCallbackTarget('', '//login/lp/sso-callback')).toBe(true);
});
it('rejects another host and another opaque path', () => {
expect(isTauriSsoCallbackTarget('evil', '/lp/sso-callback')).toBe(false);
expect(isTauriSsoCallbackTarget('', '//evil/lp/sso-callback')).toBe(false);
});
});
describe('parseTauriOidcCallback', () => {
it('parses code and state from single-slash format', () => {
expect(parseTauriOidcCallback('moe.sable.app:/login?code=c1&state=s1')).toEqual({
+10 -5
View File
@@ -39,18 +39,19 @@ export const takeTauriSsoNonce = (): string | undefined => {
}
};
// Built as a string: resolving a relative path against a non-special base throws on Chromium < 130.
export const buildTauriSsoRedirectUrl = (server?: string): string => {
const redirectUrl = new URL(SSO_CALLBACK_PATH, getAppBaseUrl());
const params = new URLSearchParams();
if (server) {
redirectUrl.searchParams.set('server', server);
params.set('server', server);
}
const nonce = crypto.randomUUID();
rememberTauriSsoNonce(nonce);
redirectUrl.searchParams.set('sso_nonce', nonce);
params.set('sso_nonce', nonce);
return redirectUrl.toString();
return `${getAppBaseUrl()}${SSO_CALLBACK_PATH}?${params}`;
};
export const TAURI_OIDC_CLIENT_URI = 'https://app.sable.moe';
@@ -103,11 +104,15 @@ export const parseTauriOidcCallback = (
}
};
// Chromium < 130 gives a non-special scheme an opaque path, leaving the authority in the pathname.
export const isTauriSsoCallbackTarget = (hostname: string, pathname: string): boolean =>
hostname === TAURI_SSO_HOST || pathname === `//${TAURI_SSO_HOST}${SSO_CALLBACK_PATH}`;
export const parseTauriSsoCallback = (rawUrl: string): TauriSsoCallback | undefined => {
try {
const callbackUrl = new URL(rawUrl);
if (callbackUrl.protocol !== TAURI_SSO_PROTOCOL) return undefined;
if (callbackUrl.hostname !== TAURI_SSO_HOST) return undefined;
if (!isTauriSsoCallbackTarget(callbackUrl.hostname, callbackUrl.pathname)) return undefined;
const loginToken = callbackUrl.searchParams.get('loginToken');
if (!loginToken) return undefined;