Skip to content

Revoke only the replayed sign-in on refresh token reuse - #457

Merged
tnkuehne merged 2 commits into
mainfrom
scoped-refresh-replay
Nov 28, 2026
Merged

tnkuehne merged 2 commits into
mainfrom
scoped-refresh-replay

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Better Auth rotates refresh tokens. When a rotated token is presented again after the reuse window, the OAuth provider deletes every refresh token the user holds for that client.

A browser session can end up in two cookie stores. For example, iOS copies a site's cookies into an app added to the Home Screen. Once one copy rotates, the other presents the old token. The user is then signed out of every app sign-in on all devices.

Change

  • The OAuth provider patch limits the replay teardown to the tokens issued from the same authorization code. Every refresh and access token carries that code's ID across all rotations.
  • This applies in the refresh path and in both revocation paths.
  • A replay still ends the whole affected sign-in. The user's other sign-ins with the client stay valid.
  • Tokens without an authorization code, such as device grants, keep the teardown of all of the user's refresh tokens for that client and the opaque access tokens issued from them. Signed JWT access tokens stay valid until they expire, as before.

Tests

organization-sso.integration.test.ts covers:

  • three app sign-ins of one user, where replaying one sign-in's rotated token ends only that sign-in, through both refresh and revocation
  • the device grant fallback, which still ends all device grants

Without the patch, the new app sign-in test fails.

A rotated refresh token presented again made the OAuth provider delete every
token the user held for that client. A browser session copied into a second
cookie store, such as an app added to the iOS Home Screen, then signed the
user out of all devices once one copy rotated.

The provider patch now limits that teardown to the tokens issued from the
same authorization code, in the refresh and both revocation paths. Tokens
without an authorization code, such as device grants, keep the teardown of all
of the user's tokens for that client.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 62520d5 Nov 27 2026, 11:57 PM

@tnkuehne
tnkuehne merged commit b7b4e6f into main Nov 28, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the scoped-refresh-replay branch November 28, 2026 00:13
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