fix sso deeplinking behaviors (#1214)

hopefully

<!-- 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. -->

Some path normalizationing

#### Type of change

- [ ] 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:
7w1 authored and GitHub committed 2026-07-22 11:53:22 -05:00
commit d6a5411986
4 files changed
+45 -4

No files matched your search

+8 -2
View File
@@ -156,7 +156,14 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
const mobile = screenSize === ScreenSize.Mobile;
const routes = createRoutesFromElements(
<Route>
<Route
element={
<>
<TauriDeepLinkBridge />
<Outlet />
</>
}
>
<Route
index
loader={() => {
@@ -192,7 +199,6 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
>
<Suspense fallback={<SplashScreen>{null}</SplashScreen>}>
<>
<TauriDeepLinkBridge />
<AuthLayout />
<UnAuthRouteThemeManager />
</>
@@ -38,6 +38,12 @@ describe('mapDeepLinkToLoginPath', () => {
expect(path).toContain('state=s1');
});
it('passes normalized moe.sable.app://login OIDC callback through', () => {
const path = mapDeepLinkToLoginPath('moe.sable.app://login?code=c1&state=s1');
expect(path).toContain('code=c1');
expect(path).toContain('state=s1');
});
it('returns undefined for an unrelated url', () => {
expect(mapDeepLinkToLoginPath('https://example.com/whatever')).toBeUndefined();
});
+18 -1
View File
@@ -79,14 +79,31 @@ describe('parseTauriSsoCallback', () => {
});
describe('parseTauriOidcCallback', () => {
it('parses code and state', () => {
it('parses code and state from single-slash format', () => {
expect(parseTauriOidcCallback('moe.sable.app:/login?code=c1&state=s1')).toEqual({
code: 'c1',
state: 's1',
});
});
it('parses code and state from authority/hostname format (moe.sable.app://login)', () => {
expect(parseTauriOidcCallback('moe.sable.app://login?code=c1&state=s1')).toEqual({
code: 'c1',
state: 's1',
});
});
it('rejects the wrong path', () => {
expect(parseTauriOidcCallback('moe.sable.app:/other?code=c1&state=s1')).toBeUndefined();
expect(parseTauriOidcCallback('moe.sable.app://other?code=c1&state=s1')).toBeUndefined();
});
it('rejects a different protocol', () => {
expect(parseTauriOidcCallback('sable://login?code=c1&state=s1')).toBeUndefined();
expect(parseTauriOidcCallback('https://login?code=c1&state=s1')).toBeUndefined();
});
it('rejects an unrelated hostname with a login path', () => {
expect(parseTauriOidcCallback('moe.sable.app://evil/login?code=c1&state=s1')).toBeUndefined();
});
});
+13 -1
View File
@@ -75,7 +75,19 @@ export const parseTauriOidcCallback = (
try {
const callbackUrl = new URL(rawUrl);
if (callbackUrl.protocol !== TAURI_OIDC_PROTOCOL) return undefined;
if (callbackUrl.pathname !== TAURI_OIDC_PATH) return undefined;
// `moe.sable.app:/login?...` → hostname === '', pathname === '/login'
// `moe.sable.app://login?...` → hostname === 'login', pathname === '/' or ''
const hasLoginPath =
callbackUrl.pathname === TAURI_OIDC_PATH || callbackUrl.pathname === `${TAURI_OIDC_PATH}/`;
const isSingleSlashFormat = callbackUrl.hostname === '' && hasLoginPath;
const isAuthorityFormat =
callbackUrl.hostname === 'login' &&
(callbackUrl.pathname === '/' || callbackUrl.pathname === '');
if (!isSingleSlashFormat && !isAuthorityFormat) return undefined;
const code = callbackUrl.searchParams.get('code');
const state = callbackUrl.searchParams.get('state');