Repository navigation
test(auth): pin oauth refresh-token reuse detection and document its limits - #1490
Conversation
Drive oauthProvider's real token endpoint through authorization_code -> refresh -> replay and assert better-auth's reuse detection (RFC 9700 §4.14.2): replaying a rotated refresh token is refused and revokes every refresh and opaque access token that user holds for that client, including sibling grants, while another user's grant survives. Also pins the refreshTokenReuseInterval retry window and the sliding refreshTokenExpiresIn. Runs over better-auth's memory adapter and Lunora's SQL store, since rotation relies on incrementOne with a revoked-is-null guard and family revocation on deleteMany with an `in` filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Explain what a replayed rotated refresh token does under oauthProvider: the (client, user) family is revoked, JWT access tokens outlive it, expiry slides with each rotation, and refreshTokenReuseInterval defaults to 0 so a lost response retry also revokes. Note the non-atomic revocation upstream tracks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A replay of a rotated refresh token after refreshTokenReuseInterval has elapsed must still revoke the family; assert it with an injected clock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mcp() is oauthProvider underneath with refreshTokenReuseInterval defaulting to 30 seconds; say so and clarify which token the replay revokes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
createMemoryAuth seeded its memoryAdapter store inline, and the refresh-reuse suite copied that loop. memoryTables builds the store from the resolved options so both can share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- pin that a replay leaves the same user's grant to another client alive - pin that an expired refresh token does not revoke its family - assert the replaying user's family is revoked in the other-user case - assert invalid_grant on every refused refresh, not just a 400 - treat a failed introspection as an error, never as "revoked" - register the client and sign in through the typed API and HTTP, dropping the hand-typed ProviderAuth and its cast; reuse signInAndCookie and memoryTables; hoist the pure helpers to module scope Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only access tokens issued with a refresh token are revoked; JWT access tokens depend on disableJwtPlugin; a replay inside refreshTokenReuseInterval gets the rotation's tokens and revokes nothing; and mcp() binds tokens to its resource, so its access tokens are JWTs that outlive revocation, on top of its 30 s default window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters: 4
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including
|
PR Summary by QodoTest OAuth refresh-token reuse and document its limits
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can turn these tips off under Display > Comment parts |
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #1490 +/- ##
===========================================
+ Coverage 83.97% 88.46% +4.48%
===========================================
Files 2089 248 -1841
Lines 126052 15958 -110094
Branches 32259 4503 -27756
===========================================
- Hits 105855 14117 -91738
+ Misses 19447 1711 -17736
+ Partials 750 130 -620 🚀 New features to boost your workflow:
|
Summary
A regression test for OAuth refresh-token reuse detection, plus docs on where it stops. Void added reuse detection in voidzero-dev/void#631. Lunora gets it from better-auth's
oauthProvider(1.7.16): replaying a rotated refresh token revokes the token family for that client and user. Nothing tested that until now.oauth-refresh-reuse.behaviour.test.ts). It runs the real flow over HTTP: sign-up and sign-in, client registration, PKCE authorization code, refresh, then a replay. It runs against both better-auth's memory adapter and Lunora's SQL store. It checks that:invalid_grant;clientIdfilter, dropping theuserIdfilter, no revocation on replay, revocation on expiry, the wrong error code). Each patch made the matching tests fail on both backends, and the original file was restored, with its checksum verified.packages/auth/docs/plugins.mdx). They state the limits:resourceis requested anddisableJwtPluginis unset) stay valid until they expire. Undermcp()that is the normal case, so use a shortaccessTokenExpiresIn.refreshTokenReuseInterval(default 0, or 30s undermcp()) gets live tokens back and is not detected.__tests__/helpers/memory-tables.ts, whichcreateMemoryAuthnow also uses.No production code changes.
Test plan
@lunora/auth: eslint,lint:types, tests 603/603Checklist
packages/auth/docs/plugins.mdx)🤖 Generated with Claude Code