Skip to content

fix(auth): recover duplicate desktop GitHub OAuth callbacks without replaying codes - #101

Draft
Aliferous3 wants to merge 1 commit into
mainfrom
fix/desktop-oauth-callback-replay
Draft

Aliferous3 wants to merge 1 commit into
mainfrom
fix/desktop-oauth-callback-replay

Conversation

@Aliferous3

Copy link
Copy Markdown
Owner

Production evidence

On 2026-11-01 at 08:57 UTC, the browser showed GitHub token exchange failed. Vercel logged bad_verification_code at 08:57:46.901, yet Supabase shows an authenticated session at 08:57:46.303 and a desktop handoff code issued at 08:57:49.032, not consumed. This repeatedly points to overlapping/replayed callbacks using GitHub's single-use code; exact initiator of duplication is not yet known.

Server-only recovery fix (no new installer or schema migration)

  • For normal desktop OAuth callbacks, derive the one-time handoff code from HMAC-SHA256(SESSION_SECRET, domain_separator || github_oauth_code || flow_uuid || desktop_PKCE_challenge). Only its SHA-256 hash is stored in the existing desktop_auth_codes table. GitHub's original code and the server secret are never persisted or logged.
  • When a second, correctly state-validated desktop callback encounters GitHub's bad_verification_code, check whether the first callback has actually issued the exact corresponding handoff. Bounded polling accommodates provisioning/insert latency; on match redirect to that same PKCE-bound deep link, rather than showing an OAuth error. Never mint a token, new session, or handoff from a failed exchange alone.
  • Duplicate handoff activation remains single-use and cannot be redeemed without the desktop's memory-held PKCE verifier. Existing session revocation/expiry protections remain.
  • Add secret-free code-exchange age/state-fingerprint diagnostics from draft PR diagnostics(auth): investigate GitHub desktop code exchange rejections safely #99, and tests for deterministic handoff, strict flow/challenge match, no accidental issue, and duplicate callback correlation.

Scope, safeguards and status

  • Changes only to lib/desktop-auth.mjs, api/auth/callback.mjs, and their two test files.
  • No database migration, extra hosted services, payment, UI changes, or client rebuild.
  • This deliberately does not change the already-tested Windows in-process memory-token fix in draft PR fix(desktop): deliver Windows OAuth deep links to the running app #100. An end-to-end installed app re-test will still be required.
  • If the GitHub code is genuinely invalid and NO matching handoff was issued, the existing error remains; no fabricated login occurs.
  • Draft; do not merge or deploy without explicit user approval.

@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
dev-ledger Ready Ready Preview Nov 1, 2026 9:09am UTC

This branch was successfully deployed

1 active deployment
Preview — 3d718aaa Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant