fix: refresh-token family revocation on theft#562
Open
David-282 wants to merge 1 commit into
Open
Conversation
|
@David-282 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@GBOYEE has applied to work on this issue as part of the Stellar Wave Program's 6th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @GBOYEE to this issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two related security bugs in the refresh token flow that together prevented theft detection from working correctly.
Bug 1 — Refresh tokens were never rotated.
On a successful
POST /auth/refresh, the old refresh token was never revoked and no new refresh token was issued. Only a new access token was returned. This meantisRevokedwas never set totrueduring normal rotation, making theft detection permanently non-functional since a reused token could never be identified as revoked.Bug 2 — Theft response only revoked the token's family, not all user tokens.
handleReusecalledrevokeFamily(storedToken.familyId)— but an attacker who had already rotated the stolen token may have started a new family. Revoking only the original family leaves the attacker's newer tokens active.Related Issue
Fixes #528
Changes
src/services/refreshTokenService.tsrotateRefreshToken()— revokes the consumed token and issues a fresh access + refresh token pair in the same family, maintaining the theft-detection lineage across rotationshandleReuse()to callrevokeAllUserTokens()instead ofrevokeFamily(), ensuring all tokens across all families are invalidated when theft is detectedsrc/controllers/authController.tsrefreshToken()to callrotateRefreshToken()on success, so the response now returns both a newaccessTokenand a newrefreshTokentests/integration/refreshToken.test.tsSecurity Impact
Before this fix, refresh tokens were effectively permanent — they were never rotated and theft was undetectable. After this fix, each refresh token is single-use, theft signals a full user session wipe, and the attacker cannot maintain access regardless of how many times they rotate the stolen token.
Testing
Tests cover the full theft detection lifecycle. CI will run the full suite. Local
npm installwas not possible due to abetter-sqlite3native compilation incompatibility with Node 24 in the local environment — this is a pre-existing environment issue unrelated to this change.Checklist
main