Skip to content

fix(auth): protect rotated refresh tokens from stale runtime snapshots - #16

Merged
Bl0ck154 merged 2 commits into
mainfrom
integrate/oauth-token-generation-20261028
Oct 28, 2026
Merged

Bl0ck154 merged 2 commits into
mainfrom
integrate/oauth-token-generation-20261028

Conversation

@Bl0ck154

Copy link
Copy Markdown
Owner

Bug

A successful OAuth token refresh rotates the refresh token in accounts.json. If the active Codex auth.json still contains an older snapshot, the next reconciliation can overwrite the new token with the old, single-use refresh token. This makes switching back or refreshing later fail.

Fix

Extract the credential-generation safeguard from upstream PR Lampese#185 without importing the unrelated OAuth refresh policy overhaul:

  • Add optional, backward-compatible last_refresh_at to saved accounts.
  • Preserve generations when importing auth.json and when writing it out on account switches.
  • Record a new generation on successful OAuth token refresh or re-login.
  • Reconcile live credentials only if they belong to the same workspace and are not older than the saved generation.
  • Keep unknown-identity and workspace isolation protections unchanged.

Regression coverage

Four storage tests:

  • Older runtime snapshot (including missing timestamp) cannot overwrite a rotated token.
  • A newer runtime generation can update the saved credentials.
  • Legacy accounts.json without the field still deserializes.
  • Re-login retains new credentials even if the runtime still has an older snapshot.

This patch is separated from upstream Lampese#185 because the full PR conflicts with our workspace-aware OAuth changes. Rust CI and platform compile checks are pending. Do not merge if they fail.

@Bl0ck154
Bl0ck154 marked this pull request as ready for review October 28, 2026 16:27
@Bl0ck154
Bl0ck154 merged commit d1189dd into main Oct 28, 2026
6 of 7 checks passed
@Bl0ck154
Bl0ck154 deleted the integrate/oauth-token-generation-20261028 branch October 28, 2026 16:27
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