Repository navigation
fix(sessions): close refresh rotation gaps and add a replay window - #613
Merged
Merged
Conversation
Revoking a session by id now walks the rotation chain to its head, for users and admins, so a session that rotated after it was listed is ended rather than left live (#592). The refresh lookup finds a row by its fingerprint alone, so a rotated token is reuse however long after its rotation it returns, instead of an unknown token once the rotated row's idle window passed (#593). A rotated token presented again within REFRESH_REPLAY_WINDOW_SECONDS (default 10) is answered with the same successor, up to three times, so concurrent refreshes from separate adapter instances no longer read as reuse. Only the immediate predecessor of a live head qualifies. The successor token is stored AES-256-GCM sealed under a key derived from the lookup secret and the rotated token, and cleared when the window lapses or the chain is revoked (#598). Closes #592 Closes #593 Closes #598
Matches the five second refresh dedupe window the Node adapter keeps and the conformance harness expects, so a replay presented after it is reuse.
This was referenced Nov 19, 2026
Merged
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.
Closes #592, closes #593, closes #598. All three touch refresh rotation in
sessionService.tsand/refresh, so they land in one PR.Changes
#592: revoke by id ends the chain head.
DELETE /sessions/:idandDELETE /admin/sessions/by-id/:idcallrevokeSessionChaininstead ofhardRevokeSession. The walk starts at the row given and followsreplacedBySessionIdto the head, so a session that rotated after it was listed is revoked. Two more changes torevokeSessionChain:revokedReason.#593: reuse detection no longer expires.
findRefreshSessionByTokenlooks the row up by its fingerprint only and no longer filters on revoked, expired or idle./refreshchecks any row withreplacedBySessionIdset first: it is either answered from the replay window or treated as reuse (401 refresh_token_reused, chain revoked). Revocation and expiry are checked after that, for rows that never rotated, usingclassifyRefreshRefusal(src/lib/refreshRefusal.ts). That function replacesclassifyExpiredRefreshToken.#598: refresh replay window.
REFRESH_REPLAY_WINDOW_SECONDSafter a rotation (default 5, capped at 60,0disables; 5 matches the Node adapter's completed-refresh cache and the conformance harness), the rotated token gets the same successor back: the samerefreshTokenandsessionId, and a freshly signed access token for that session. This works up to three times per rotation.validateSessionRecord, which rejects one that is revoked, rotated, expired, cut off or orphaned, and its owner must not be revoked.REFRESH_TOKEN_LOOKUP_SECRET, domain tag + rotated token), and the AAD binds both session ids. A database copy alone cannot open it. After opening, the plaintext's lookup is checked against the successor row.system_configkey, becauseSystemConfigSchemalives in@seamless-auth/types. This follows the same reasoning asLOGIN_RESPONSE_FLOOR_MS.Migration:
20261118120000-add-refresh-replay.cjsaddssessions."rotatedAt","replayTokenCiphertext"and"replayCount"(integer, not null, default 0).Docs:
docs/security-posture.md(new sections: reuse detection does not expire, refresh replay window) anddocs/configuration.md.Contract change
No routes, request or response schemas, token claims, JWKS entries or status codes are added or removed.
npm run generate:apileavesopenapi.jsonandadapter-manifest.jsonunchanged. Two/refreshoutcomes change:200with the samerefreshTokenandsessionId. Before, the losing call got401 refresh_token_reusedand the user was signed out.401 refresh_token_reusedwith the chain revoked. Before, it was401 invalid_refresh_tokenand nothing was revoked.Affected repos:
seamless-auth-server(Log injection rationale documents an unrelated type, not the log lines it describes #285)seamless-auth-go(refactor: remove web mode #37)seamless-auth-python(refactor: make email be the primary verification method and allow it to be the only verfication method #42)seamless-auth-rust(Otp sanatization #43)Each adapter keeps working unchanged. Its issue can be closed with a test that two parallel refreshes both succeed against an API that includes this change. Adapters should keep treating
refresh_token_reusedas terminal.Verification
npm run typecheck: clean.npm run lint: clean.npm run format:check: clean.npm run test:run: 195 files, 3441 tests passed, 1 todo.npm run coverage: 99.07 / 95.81 / 99.33 / 99.28 (lines / branches / functions / statements). The touched files are at 100% line coverage.TEST_DB=postgreson a scratch database: 19 files, 283 tests passed. This includes the newtests/postgres/refreshRotation.spec.ts:sessionExchangereuse tests now age the rotation past the window before presenting reuse.