Skip to content

diagnostics(auth): investigate GitHub desktop code exchange rejections safely - #99

Draft
Aliferous3 wants to merge 7 commits into
mainfrom
fix/desktop-oauth-exchange-diagnostics
Draft

Aliferous3 wants to merge 7 commits into
mainfrom
fix/desktop-oauth-exchange-diagnostics

Conversation

@Aliferous3

@Aliferous3 Aliferous3 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Evidence and scope

Production Vercel logs for the user's failed desktop login at 2026-10-31 23:38:37 UTC show GitHub returned bad_verification_code at /api/auth/callback (flow=desktop). This is before the desktop deep link or token storage. The exact cause of GitHub's rejection is not yet established; we should not claim this patch repairs desktop login.

Changes

  • Validate that incoming code and state are single string query parameters. Previously repeated codes were arrays, which URLSearchParams would silently serialize to a comma-joined, invalid code.
  • On GitHub token-exchange failure, record only the elapsed seconds since the sealed-session authorization attempt began. Do not log OAuth codes, states, tokens, client credentials, browser headers or query URLs.
  • Preserve existing form-urlencoded exchange protocol, state consumption, CSRF guarantees, existing desktop/web OAuth isolation, and response semantics.
  • Add regression tests for repeated code parameters and for safely identifying a desktop bad_verification_code exchange without leaking credentials.

Diagnostic next step

If this recurs on a fresh OAuth attempt, inspect oauth_age_sec in production logs. A small age makes a stale 10-minute GitHub authorization less likely; then investigate code reuse/duplicate callbacks or provider-side issuance. No automatic retries: GitHub authorization codes are single-use.

Do not merge without explicit approval

This is a controlled diagnostic PR, not an asserted root-cause fix. No installer rebuild required unless desktop-side code changes later.

November 1 investigation update

Production session+handoff records coincide with bad_verification_code failures, consistent with overlapping callbacks. Added a bounded SHA-256 fingerprint of high-entropy random OAuth state (not the raw state or authorization code) to accepted and rejected desktop token exchanges, plus elapsed time. This detects matching callback attempts without an optional correlation key, which is absent on this deployment. Unit tests model two callback requests with the same initial sealed cookie and prove the server currently accepts one and records GitHub's single-use rejection for the second. This PR is diagnostic only and does not claim to eliminate callback duplication.

@vercel

vercel Bot commented Oct 31, 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:02am UTC

This branch was successfully deployed

1 active (outdated) deployment
Preview — b904564b 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