From e8fe3663e088e8b095ccf1742be13ad194e4a590 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:47:12 +0400 Subject: [PATCH 01/12] fix(desktop): enable Tauri single-instance deep-link forwarding --- src-tauri/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index f2170a6..b4f79f0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -32,7 +32,7 @@ tauri-plugin-http = { version = "2", features = ["rustls-tls", "unsafe-headers"] # Fixed upstream in plugins-workspace#3711 — unpin once 2.6.3+ lands. tauri-plugin-deep-link = "=2.6.1" # Route a second process launch (deep-link activation) back to one window. -tauri-plugin-single-instance = "2" +tauri-plugin-single-instance = { version = "2", features = ["deep-link"] } # OS-backed credential storage: Windows Credential Manager, macOS Keychain, # Linux Secret Service (pure-Rust zbus + rust crypto — no libdbus/openssl). keyring = { version = "3", features = [ From 06f66c8ae7eae5b31d406c9e3b7d2f2a3a882a43 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:47:29 +0400 Subject: [PATCH 02/12] fix(desktop): initialize single-instance before deep-link plugin on Windows --- src-tauri/src/lib.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3762a71..62a6a10 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -80,7 +80,24 @@ fn is_dev_origin(_url: &tauri::Url) -> bool { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { - tauri::Builder::default() + // Windows/Linux deliver dev-ledger:// URLs by launching a second process. + // Tauri requires single-instance to be the FIRST registered plugin, with + // its "deep-link" feature enabled, to forward URLs to the running app. + // Registering it later in setup() cannot reliably intercept that launch. + let builder = tauri::Builder::default(); + + #[cfg(desktop)] + let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { + // The plugin's deep-link feature forwards the URL automatically + // before calling this callback. Do not parse or log credential-bearing + // URLs from argv; the JS handler performs flow+PKCE validation. + if let Some(w) = app.get_webview_window("main") { + let _ = w.unminimize(); + let _ = w.set_focus(); + } + })); + + builder .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_http::init()) .plugin(tauri_plugin_deep_link::init()) @@ -91,22 +108,6 @@ pub fn run() { sha256_hex ]) .setup(|app| { - #[cfg(desktop)] - { - // Single instance must be registered before other plugin work: a - // second launch (e.g. a dev-ledger:// deep-link activation while the - // app is already running) focuses the existing window and the - // deep-link plugin forwards the URL to it. - let _ = - app.handle() - .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { - if let Some(w) = app.get_webview_window("main") { - let _ = w.unminimize(); - let _ = w.set_focus(); - } - })); - } - // The main window is created in code (not tauri.conf.json) so the // on_navigation guard can be attached: only bundled-app origins may // navigate inside the webview. From a9bd2ea9a30c048b7131456e4079cc3544d36f36 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:47:49 +0400 Subject: [PATCH 03/12] test(desktop): guard Windows single-instance forwarding and OAuth handoff binding --- test/desktop-deep-link-delivery.test.mjs | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/desktop-deep-link-delivery.test.mjs diff --git a/test/desktop-deep-link-delivery.test.mjs b/test/desktop-deep-link-delivery.test.mjs new file mode 100644 index 0000000..4b030f2 --- /dev/null +++ b/test/desktop-deep-link-delivery.test.mjs @@ -0,0 +1,39 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' + +// Tauri 2 Windows/Linux deep links launch a second process. The original +// instance must intercept it BEFORE any plugin setup or window creation. +// Docs: https://v2.tauri.app/plugin/deep-linking/#desktop +const src = (p) => readFileSync(new URL('../' + p, import.meta.url), 'utf8') + +test('single-instance enables Tauri deep-link forwarding explicitly', () => { + const cargo = src('src-tauri/Cargo.toml') + assert.match(cargo, /tauri-plugin-single-instance\s*=\s*\{[^\n]*features\s*=\s*\["deep-link"\]/) + assert.match(cargo, /tauri-plugin-deep-link\s*=/) +}) + +test('single-instance initializes first, not inside setup, so Windows forwards the URI', () => { + const rust = src('src-tauri/src/lib.rs') + const first = rust.indexOf('builder.plugin(tauri_plugin_single_instance::init(') + const opener = rust.indexOf('.plugin(tauri_plugin_opener::init())') + const deepLink = rust.indexOf('.plugin(tauri_plugin_deep_link::init())') + const setup = rust.indexOf('.setup(|app|') + assert.ok(first >= 0 && opener >= 0 && deepLink >= 0 && setup >= 0) + assert.ok(first < opener && opener < deepLink && deepLink < setup, + 'single-instance must precede all other plugins and setup') + assert.doesNotMatch(rust.slice(setup), /app\.handle\(\)\s*\.plugin\(tauri_plugin_single_instance/) + assert.match(rust, /app\.deep_link\(\)\.register\("dev-ledger"\)/) + assert.match(rust, /get_webview_window\("main"\)/) +}) + +test('desktop login consumes deep links only after binding them to the pending flow', () => { + const ts = src('src/desktop/auth.ts') + assert.ok(ts.includes("import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link'")) + assert.ok(ts.includes('await onOpenUrl((urls) =>')) + assert.ok(ts.includes('const current = await getCurrent()')) + assert.ok(ts.includes('flow !== pendingFlow')) + assert.ok(ts.includes('!pendingVerifier')) + assert.ok(ts.includes("fetch('/api/auth/desktop?op=exchange'")) + assert.ok(ts.includes('body: JSON.stringify({ flow, code, verifier })')) +}) From 64cc9b72ef594f96069cceb12be3edd5beec7c1a Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:49:55 +0400 Subject: [PATCH 04/12] fix(desktop): pin compatible deep-link 2.6.3 with upstream Linux build fix --- src-tauri/Cargo.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b4f79f0..3454194 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,10 +27,9 @@ tauri-plugin-opener = "2" # hosted CSRF guard expects. tauri-plugin-http = { version = "2", features = ["rustls-tls", "unsafe-headers"] } # dev-ledger:// handoff from the system-browser OAuth flow. -# Pinned to 2.6.1: 2.6.2's load_desktop_ini does not compile against -# rust-ini 0.21.3 on Linux (ParseOption gained required fields). -# Fixed upstream in plugins-workspace#3711 — unpin once 2.6.3+ lands. -tauri-plugin-deep-link = "=2.6.1" +# Pin the upstream patch fixing rust-ini 0.21.3 build compatibility +# (plugins-workspace#3711). Single-instance deep-link forwarding requires >=2.6.2. +tauri-plugin-deep-link = "=2.6.3" # Route a second process launch (deep-link activation) back to one window. tauri-plugin-single-instance = { version = "2", features = ["deep-link"] } # OS-backed credential storage: Windows Credential Manager, macOS Keychain, From 3c365a37928c6b8c5c452c539cd7afb94584f8d6 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:50:33 +0400 Subject: [PATCH 05/12] build(desktop): lock compatible Tauri deep-link patch and forwarded feature graph --- src-tauri/Cargo.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 49d90e9..cbdcf15 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4266,9 +4266,9 @@ dependencies = [ [[package]] name = "tauri-plugin-deep-link" -version = "2.6.1" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac7a92a46ab5c88f44532ca50906d6e448a948d4ddf8c5376ab125e3260f736" +checksum = "ab551d9bec27bb79d1c7fe5ed38c5cfd1cebb86efa745acc65f5853f345f6e56" dependencies = [ "dunce", "plist", @@ -4364,6 +4364,7 @@ dependencies = [ "serde", "serde_json", "tauri", + "tauri-plugin-deep-link", "thiserror 2.0.21", "tokio", "tracing", From 30364070b4ae3ae17f0321525c0934bce8223cc1 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:06:21 +0400 Subject: [PATCH 06/12] fix(desktop): expose privacy-safe deep-link receipt and mismatched-flow diagnostics --- src/desktop/auth.ts | 74 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/src/desktop/auth.ts b/src/desktop/auth.ts index 1f7e5f0..e772a8c 100644 --- a/src/desktop/auth.ts +++ b/src/desktop/auth.ts @@ -32,15 +32,21 @@ let pendingFlow: string | null = null; let pendingVerifier: string | null = null; let pendingRemember = false; let noticeHandler: ((msg: string | null) => void) | null = null; +// Deep links may arrive before the React login gate mounts. Keep only a +// non-sensitive status message in memory; never retain URLs, codes or state. +let lastNotice: string | null = null; +let exchangeInProgress = false; export function onDesktopAuthNotice(cb: (msg: string | null) => void): () => void { noticeHandler = cb; + cb(lastNotice); return () => { if (noticeHandler === cb) noticeHandler = null; }; } function notice(msg: string | null) { + lastNotice = msg; try { noticeHandler?.(msg); } catch { @@ -76,24 +82,53 @@ export function startDesktopLogin(remember: boolean): void { }); } -// True when the URL is our registered deep link — anything else is ignored. +// Parse the complete registered scheme and host. Prefix matching would +// mistakenly accept dev-ledger://auth-foreign, etc. Never log URLs or codes. export function isAuthDeepLink(url: string): boolean { - return url.startsWith(`${DESKTOP_SCHEME}://auth`); + try { + const parsed = new URL(url); + return parsed.protocol === `${DESKTOP_SCHEME}:` + && parsed.hostname === 'auth' + && (parsed.pathname === '' || parsed.pathname === '/') + && !parsed.username && !parsed.password && !parsed.hash; + } catch { + return false; + } } -async function handleAuthUrl(url: string): Promise { - let parsed: URL; +// A harmless probe lets us distinguish native window activation from an +// event that actually reached the JavaScript listener. It never exchanges +// credentials or changes authentication state. +function isDiagnosticLink(url: string): boolean { try { - parsed = new URL(url); + const parsed = new URL(url); + return parsed.protocol === `${DESKTOP_SCHEME}:` + && parsed.hostname === 'diagnostic' + && !parsed.search && !parsed.hash + && (parsed.pathname === '' || parsed.pathname === '/'); } catch { + return false; + } +} + +async function handleAuthUrl(url: string): Promise { + if (exchangeInProgress) return; // Ignore repeated delivery of the same URL. + if (!isAuthDeepLink(url)) return; + const parsed = new URL(url); + const flows = parsed.searchParams.getAll('flow'); + const codes = parsed.searchParams.getAll('code'); + // Duplicate parameters or an unsolicited link must never reach the API. + if (flows.length !== 1 || codes.length !== 1 || !codes[0]) { + notice('An invalid sign-in link was received. Start a new sign-in from Dev Ledger.'); return; } - const flow = parsed.searchParams.get('flow') ?? ''; - const code = parsed.searchParams.get('code') ?? ''; + const flow = flows[0]; + const code = codes[0]; // A stale/foreign deep link (old browser attempt, another app's spoof) // must never drive an exchange — the flow id is the binding between // THIS app instance's login intent and the server's handoff. - if (!pendingFlow || flow !== pendingFlow || !code || !pendingVerifier) { + if (!pendingFlow || flow !== pendingFlow || !pendingVerifier) { + notice('A sign-in link reached Dev Ledger, but does not match an active login. Start again.'); return; } const verifier = pendingVerifier; @@ -101,6 +136,8 @@ async function handleAuthUrl(url: string): Promise { pendingFlow = null; pendingVerifier = null; pendingRemember = false; + exchangeInProgress = true; + notice('Sign-in link received. Completing secure handoff...'); try { // Relative path — routed through the transport shim (plugin-http), so // the exchange needs no CORS accommodation on the server. @@ -126,6 +163,8 @@ async function handleAuthUrl(url: string): Promise { window.location.reload(); } catch { notice('The Dev Ledger service is unreachable — sign-in could not finish.'); + } finally { + exchangeInProgress = false; } } @@ -136,15 +175,20 @@ async function handleAuthUrl(url: string): Promise { // registered. export async function initDesktopAuth(): Promise { await loadToken(); - await onOpenUrl((urls) => { - for (const u of urls) { - if (isAuthDeepLink(u)) void handleAuthUrl(u); + const accept = (u: string) => { + if (isDiagnosticLink(u)) { + notice('Windows protocol link reached the Dev Ledger JavaScript listener.'); + return; } - }).catch(() => {}); - const current = await getCurrent().catch(() => null); - for (const u of current ?? []) { if (isAuthDeepLink(u)) void handleAuthUrl(u); - } + }; + await onOpenUrl((urls) => { + for (const u of urls) accept(u); + }).catch(() => { + notice('The desktop sign-in listener could not start. Restart Dev Ledger.'); + }); + const current = await getCurrent().catch(() => null); + for (const u of current ?? []) accept(u); } // Sign out: revoke the server-side token + session, clear the keychain, From 46e1b42f335c4666d81fcd9fff7a01dc36a37335 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:06:42 +0400 Subject: [PATCH 07/12] test(desktop): guard JavaScript deep-link receipt diagnostics and silent-drop prevention --- test/desktop-deep-link-delivery.test.mjs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/desktop-deep-link-delivery.test.mjs b/test/desktop-deep-link-delivery.test.mjs index 4b030f2..3e28042 100644 --- a/test/desktop-deep-link-delivery.test.mjs +++ b/test/desktop-deep-link-delivery.test.mjs @@ -37,3 +37,25 @@ test('desktop login consumes deep links only after binding them to the pending f assert.ok(ts.includes("fetch('/api/auth/desktop?op=exchange'")) assert.ok(ts.includes('body: JSON.stringify({ flow, code, verifier })')) }) + +test('JS receives diagnostic protocol activations without an OAuth exchange', () => { + const ts = src('src/desktop/auth.ts') + assert.match(ts, /parsed\.hostname === 'diagnostic'/) + assert.ok(ts.includes('Windows protocol link reached the Dev Ledger JavaScript listener.')) + assert.match(ts, /if \(isDiagnosticLink\(u\)\)/) + assert.match(ts, /if \(isAuthDeepLink\(u\)\) void handleAuthUrl\(u\)/) +}) + +test('auth URLs report mismatched and malformed returns without exposing code or state', () => { + const ts = src('src/desktop/auth.ts') + assert.match(ts, /parsed\.hostname === 'auth'/) + assert.match(ts, /parsed\.searchParams\.getAll\('flow'\)/) + assert.match(ts, /parsed\.searchParams\.getAll\('code'\)/) + assert.match(ts, /if \(!pendingFlow \|\| flow !== pendingFlow \|\| !pendingVerifier\)/) + assert.ok(ts.includes('A sign-in link reached Dev Ledger, but does not match an active login.')) + assert.match(ts, /if \(exchangeInProgress\) return/) + assert.match(ts, /exchangeInProgress = true/) + assert.match(ts, /exchangeInProgress = false/) + assert.match(ts, /cb\(lastNotice\)/, 'late React subscribers must receive the last safe notice') + assert.doesNotMatch(ts, /console\.(log|warn|error)\(/, 'desktop auth must not emit credential-bearing console logs') +}) From f7cc5237c20ab4f0a1e8ffe30823fd5f7ac15ff9 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:33:01 +0400 Subject: [PATCH 08/12] fix(desktop): preserve unchecked memory-only token through auth completion --- src/desktop/auth.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/desktop/auth.ts b/src/desktop/auth.ts index e772a8c..e6f5a30 100644 --- a/src/desktop/auth.ts +++ b/src/desktop/auth.ts @@ -32,6 +32,19 @@ let pendingFlow: string | null = null; let pendingVerifier: string | null = null; let pendingRemember = false; let noticeHandler: ((msg: string | null) => void) | null = null; +// Invoked after the bearer is available to the transport shim, without +// reloading the webview (which would erase unchecked memory-only sessions). +let completedHandler: (() => void) | null = null; +// In-memory duplicate suppression: a delivered single-use link may be +// activated again by the browser after its successful exchange. +let lastHandledFlow: string | null = null; + +export function onDesktopAuthCompleted(cb: () => void): () => void { + completedHandler = cb; + return () => { + if (completedHandler === cb) completedHandler = null; + }; +} // Deep links may arrive before the React login gate mounts. Keep only a // non-sensitive status message in memory; never retain URLs, codes or state. let lastNotice: string | null = null; @@ -56,6 +69,7 @@ function notice(msg: string | null) { export function startDesktopLogin(remember: boolean): void { notice(null); + lastHandledFlow = null; pendingFlow = crypto.randomUUID(); pendingRemember = remember; // 64 hex chars of CSPRNG entropy — the PKCE verifier. The server only @@ -124,6 +138,9 @@ async function handleAuthUrl(url: string): Promise { } const flow = flows[0]; const code = codes[0]; + // Re-delivered links are inert: the first exchange already consumed the + // one-use credential, so replay must not overwrite a successful status. + if (flow === lastHandledFlow) return; // A stale/foreign deep link (old browser attempt, another app's spoof) // must never drive an exchange — the flow id is the binding between // THIS app instance's login intent and the server's handoff. @@ -133,6 +150,7 @@ async function handleAuthUrl(url: string): Promise { } const verifier = pendingVerifier; const remember = pendingRemember; + lastHandledFlow = flow; pendingFlow = null; pendingVerifier = null; pendingRemember = false; @@ -158,9 +176,11 @@ async function handleAuthUrl(url: string): Promise { // KEEP ME SIGNED IN: checked → OS keychain (restored on next launch); // unchecked → memory only for this app session (keychain cleared). await storeToken(body.token, { persistent: remember }); - // Authenticated — a reload re-runs the standard boot gate, which now - // resolves through the bearer token exactly like a cookie session. - window.location.reload(); + // Notify React to recheck /api/user INSIDE this webview. A reload + // destroys memoryToken for unchecked logins; no token may be written + // to sessionStorage/localStorage/cookies as a workaround. + notice('Sign-in completed. Loading your dashboard...'); + completedHandler?.(); } catch { notice('The Dev Ledger service is unreachable — sign-in could not finish.'); } finally { From 8bbd05ead4278312cd5ff7f2a601e1d9db71bb33 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:33:12 +0400 Subject: [PATCH 09/12] fix(desktop): expose in-process auth completion callback to React gate --- src/desktop/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/index.ts b/src/desktop/index.ts index dfa6e2b..e8d7847 100644 --- a/src/desktop/index.ts +++ b/src/desktop/index.ts @@ -13,7 +13,7 @@ import { initDesktopAuth } from './auth'; export { isDesktop, API_BASE, DESKTOP_SCHEME } from './runtime'; export { openExternalUrl } from './links'; -export { startDesktopLogin, desktopLogout, onDesktopAuthNotice } from './auth'; +export { startDesktopLogin, desktopLogout, onDesktopAuthNotice, onDesktopAuthCompleted } from './auth'; export async function initDesktop(): Promise { if (!isDesktop()) return; From 2c8a9131eb4b0df664fba8bfe6677f67bba6383c Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:33:25 +0400 Subject: [PATCH 10/12] fix(desktop): recheck authenticated identity in-place after handoff --- src/main.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index c1cafb0..847f28d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -28,6 +28,7 @@ import { initDesktop, isDesktop, onDesktopAuthNotice, + onDesktopAuthCompleted, startDesktopLogin, } from "./desktop"; import type { Identity } from "./store/live"; @@ -68,12 +69,20 @@ function Gate() { // Desktop sign-in status line — a rejected/expired handoff surfaces here // on the login screen instead of failing silently. const [deskNotice, setDeskNotice] = useState(null); + // A successful desktop handoff must revalidate the bearer in this SAME + // webview. Never reload: unchecked sign-ins live exclusively in memory. + const [authGeneration, setAuthGeneration] = useState(0); useEffect(() => { if (!DESKTOP) return; return onDesktopAuthNotice(setDeskNotice); }, []); + useEffect(() => { + if (!DESKTOP) return; + return onDesktopAuthCompleted(() => setAuthGeneration((n) => n + 1)); + }, []); + useEffect(() => { let live = true; void desktopReady.then(() => @@ -90,7 +99,12 @@ function Gate() { setPersistent(body?.persistent === true); setMe(ok ? (body as Identity) : null); setAuth(ok ? "in" : "out"); - if (ok) setBooting(true); + if (ok) { + setDeskNotice(null); + setBooting(true); + } else if (DESKTOP && authGeneration > 0) { + setDeskNotice('Desktop token received, but /api/user did not authenticate it.'); + } // Analytics only: when this session was created by an initiated // login this tab session, emit the funnel-completing event once. // Auth state itself is untouched — consume only reads a flag. @@ -99,12 +113,18 @@ function Gate() { captureGoogleEvent("login", { method: "github" }); } }) - .catch(() => live && setAuth("out")) + .catch(() => { + if (!live) return; + setAuth("out"); + if (DESKTOP && authGeneration > 0) { + setDeskNotice('Desktop token received, but the service could not verify it.'); + } + }) ); return () => { live = false; }; - }, []); + }, [authGeneration]); // Inactivity heartbeat: while authenticated WITHOUT "keep me signed in", // renew the server-side lease every 60s (plus immediately on focus/visible From 8ae48ed551decf08f5dff35f8cc036ea599dcbe7 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:33:40 +0400 Subject: [PATCH 11/12] test(desktop): prevent reload regression for unchecked login and duplicate handoff notices --- test/desktop-deep-link-delivery.test.mjs | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/desktop-deep-link-delivery.test.mjs b/test/desktop-deep-link-delivery.test.mjs index 3e28042..19adedc 100644 --- a/test/desktop-deep-link-delivery.test.mjs +++ b/test/desktop-deep-link-delivery.test.mjs @@ -59,3 +59,33 @@ test('auth URLs report mismatched and malformed returns without exposing code or assert.match(ts, /cb\(lastNotice\)/, 'late React subscribers must receive the last safe notice') assert.doesNotMatch(ts, /console\.(log|warn|error)\(/, 'desktop auth must not emit credential-bearing console logs') }) + +test('unchecked desktop auth completion preserves the memory-only bearer', () => { + const auth = src('src/desktop/auth.ts') + const keyring = src('src/desktop/keys.ts') + const root = src('src/main.tsx') + const index = src('src/desktop/index.ts') + + // A full webview reload loses module-scoped memoryToken and signs the user + // right back out after a successful exchange with Remember unchecked. + assert.doesNotMatch(auth, /window\.location\.reload\(\)/) + assert.match(auth, /await storeToken\(body\.token, \{ persistent: remember \}\)/) + assert.match(auth, /completedHandler\?\.\(\)/) + assert.match(auth, /export function onDesktopAuthCompleted\(/) + assert.match(index, /onDesktopAuthCompleted/) + assert.match(root, /return onDesktopAuthCompleted\(\(\) => setAuthGeneration\(\(n\) => n \+ 1\)\)/) + assert.match(root, /\}, \[authGeneration\]\)/, 'bearer validation reruns in the same webview') + assert.match(root, /setAuth\(ok \? "in" : "out"\)/) + assert.match(keyring, /memoryToken = token/) + assert.match(keyring, /await invoke\('keyring_delete', \{ key: TOKEN_KEY \}\)/) + assert.doesNotMatch(auth, /sessionStorage|localStorage|document\.cookie/) + assert.doesNotMatch(keyring, /sessionStorage|localStorage|document\.cookie/) +}) + +test('duplicate desktop handoffs cannot overwrite a completed login warning', () => { + const auth = src('src/desktop/auth.ts') + assert.match(auth, /let lastHandledFlow: string \| null = null/) + assert.match(auth, /lastHandledFlow = null;\s*pendingFlow = crypto\.randomUUID\(\)/) + assert.match(auth, /if \(flow === lastHandledFlow\) return/) + assert.match(auth, /lastHandledFlow = flow;\s*pendingFlow = null/) +}) From 33ddd829cf2e0db8e8fe9017188d29772cf9e4c9 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 04:34:26 +0400 Subject: [PATCH 12/12] test(desktop): check web-storage writes without rejecting security comments --- test/desktop-deep-link-delivery.test.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/desktop-deep-link-delivery.test.mjs b/test/desktop-deep-link-delivery.test.mjs index 19adedc..2609d79 100644 --- a/test/desktop-deep-link-delivery.test.mjs +++ b/test/desktop-deep-link-delivery.test.mjs @@ -78,8 +78,8 @@ test('unchecked desktop auth completion preserves the memory-only bearer', () => assert.match(root, /setAuth\(ok \? "in" : "out"\)/) assert.match(keyring, /memoryToken = token/) assert.match(keyring, /await invoke\('keyring_delete', \{ key: TOKEN_KEY \}\)/) - assert.doesNotMatch(auth, /sessionStorage|localStorage|document\.cookie/) - assert.doesNotMatch(keyring, /sessionStorage|localStorage|document\.cookie/) + assert.doesNotMatch(auth, /(?:sessionStorage|localStorage)\.setItem\(|document\.cookie\s*=/) + assert.doesNotMatch(keyring, /(?:sessionStorage|localStorage)\.setItem\(|document\.cookie\s*=/) }) test('duplicate desktop handoffs cannot overwrite a completed login warning', () => {