All existing tests pass. Now I have a clear picture — let me present findings before writing the plan.
CodeRabbit Finding Triage
I pulled all 9 CodeRabbit comments from PR #614 and cross-checked each against the current feat/desktop-clerk-loopback HEAD. Four are already fixed (likely by late commits); five still apply:
Already fixed — skip
| # | Severity | File | Status |
|---|
| 2 | Minor | api/app/src/trpc.ts:95 | if (!cookieSession.userId) { return null; } is already braced |
| 3 | Minor | client-auth-bridge.tsx imports/interface | Imports + interface members are already sorted |
| 5 | Blocker | cli-auth-client.tsx JSX attrs + lint | Attrs sorted, block statements present, 65_535 separator present |
| 6 | Blocker | desktop-auth-client.tsx block statements | All early returns already braced |
Biome check passes clean on all 6 flagged files — confirmed.
Still applicable — need fixes
| # | Severity | File:line | Issue |
|---|
| 9 | 🔴 Critical | apps/desktop/src/main/auth-store.ts:67-74 | clearPersisted() sets memory = null before rmSync. If rmSync throws, next load() silently restores the stale token from disk. Sign-out looks successful but isn't. |
| 7 | 🟠 Major | apps/desktop/src/main/auth-flow.ts:111 | JWT arrives via ?token= on the loopback URL, which window.location.href = lands in the user's browser history. Real bearer credential leaks into browser history + any URL logging. |
| 8 | 🟠 Major | apps/desktop/src/main/auth-store.ts:50-65, 97-100 | persist() swallows encryption/writeFileSync errors. setToken() returns void, so auth-flow.ts:95-97 treats the sign-in as successful even when nothing was written to disk. |
| 4 | 🟡 Warning | apps/app/src/.../_components/client-auth-bridge.tsx:25-49 | useEffect returns early on !(isLoaded && isSignedIn) — once Clerk loads as signed-out, the bridge is stuck in "loading" forever instead of flipping to "error". Also props in the dep array re-fires on every render. |
| 1 | 🟡 Minor | api/app/src/__tests__/resolve-clerk-session.test.ts | Missing the expired-Bearer-without-cookie case — the main desktop unhappy path is currently uncovered. |
One architectural decision needed
Finding #7 (JWT in callback URL) is not a mechanical fix. The options:
A) Keep as-is — accept the browser-history exposure. Mitigations: the JWT is already 24h-bounded; loopback is 127.0.0.1 only; the tab prompts users to close it.
B) POST to loopback from the web bridge — ClientAuthBridge does a fetch('http://127.0.0.1:<port>/callback', { method: 'POST', body: { token, state } }) instead of a redirect. JWT never enters the URL bar. Requires CORS on the loopback server and a success page rendered by the web app instead. Moderate complexity.
C) Code-exchange flow (PKCE-style) — desktop generates code_verifier; web bridge returns a short opaque code; desktop exchanges the code for the JWT via a new platform endpoint. Highest complexity, highest security. Probably overkill for localhost.
My recommendation: B. It kills the browser-history leak with bounded scope (one new POST route, one CORS origin, no new server endpoint). A is defensible for a v1 but CodeRabbit's concern is legitimate — browser history persists across machine handoffs. C is overkill for loopback.
How do you want to handle #7? A, B, or C? Once you pick, I'll write the plan covering all 5 remaining findings.