feat(clerk-js): Monotonic token replacement based on oiat#8097
Draft
nikosdouvlis wants to merge 2 commits intonikos/plat-2469-oiat-jwt-header-typefrom
Draft
feat(clerk-js): Monotonic token replacement based on oiat#8097nikosdouvlis wants to merge 2 commits intonikos/plat-2469-oiat-jwt-header-typefrom
nikosdouvlis wants to merge 2 commits intonikos/plat-2469-oiat-jwt-header-typefrom
Conversation
🦋 Changeset detectedLatest commit: 91b664b The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dc3c6e9 to
cf6803d
Compare
4 tasks
f0b2a14 to
cbc83a0
Compare
Prevent multi-tab race conditions where an edge-minted token with stale claims overwrites a fresher DB-minted token. Uses `oiat ?? iat` as the claim freshness metric. A token with oiat (JWT header) uses oiat as its claim freshness. A token without oiat is origin-minted (coupled FF), so iat represents claim freshness. Four guard points: 1. tokenCache handleBroadcastMessage - replaces old iat comparison 2. tokenCache setInternal - async compare-and-swap at resolve time 3. Session #dispatchTokenEvents - before token:update emit 4. AuthCookieService updateSessionCookie - cookie chokepoint with session scoping (different sessions always allowed through) Guard 4 catches the sleeping tab edge case where in-memory guards pass (stale baseline) but the cookie has a fresher value from another tab.
cf6803d to
43ad1e4
Compare
43ad1e4 to
91b664b
Compare
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.
Why
With Session Minter, edge-minted tokens can have fresh
iat(just minted) but stale claims (copied from an old parent). In multi-tab scenarios, a background tab's stale edge token can overwrite a fresher DB-minted token in the__sessioncookie, causing claim regression.The old broadcast guard compared
iat, which doesn't reflect claim freshness for edge tokens.What
Introduces
oiat ?? iatas the unified claim freshness metric:oiat(header): oiat = when claims were last read from DBoiat: origin-minted (coupled FF), so iat = when claims were last read from DBNew shared comparator (
tokenFreshness.ts) used across 4 guard points:tokenCache.ts handleBroadcastMessage- replaces the old iat comparisontokenCache.ts setInternal- async compare-and-swap at resolve timeSession.ts #dispatchTokenEvents- before token:update emitAuthCookieService.ts updateSessionCookie- cookie chokepoint with session scopingGuard 4 is the most important. It compares against the actual
__sessioncookie value (shared state), not in-memory state. This catches the sleeping tab edge case where a tab wakes up with a stale baseline, fetches an edge token, and tries to overwrite a fresher cookie that another tab maintained.The cookie guard scopes by
sidso session switches (different oiat timelines) always pass through.Full decision table and edge case analysis in
docs/plans/session-minter-sdk-changes.md.Stacks on #8096.
Test plan