Skip to content

fix(clerk-js): discard a stored session token that was never a mint - #9358

Merged
zourzouvillys merged 1 commit into
theo/js-session-token-cleanfrom
theo/js-session-token-shape-check
Aug 7, 2026
Merged

fix(clerk-js): discard a stored session token that was never a mint#9358
zourzouvillys merged 1 commit into
theo/js-session-token-cleanfrom
theo/js-session-token-shape-check

Conversation

@zourzouvillys

Copy link
Copy Markdown
Contributor

Stacked on #9299 — this targets theo/js-session-token-clean, so the diff under review is the two files here.

Follow-up to #9299 (comment).

validateToken documents that a value which could not have come from a mint of ours is discarded, but only checked type, length and expiry. A corrupt or truncated store entry therefore counted as fresh and suppressed acquisition until it expired.

This is hygiene, not a security boundary, and the code comment says so rather than implying otherwise. Only the backend can tell a real token from a well-formed forgery, and anything that can write the store can send the same values to the API directly — so what this closes is a reliability gap (a broken entry costing a real user their token for its remaining lifetime), not an attack. Server-side handling of unverifiable tokens is already covered separately.

The shape is matched version-agnostically (^v\d+\.…). Pinning it to the current version would mean this SDK rejecting a token the backend had minted ahead of it, and re-running the loader on every page load until the SDK caught up — the second test guards against that tightening.

Verification

Both new tests confirmed non-vacuous:

  • ignores a planted value that could never have been a mint — fails on the unpatched validator, passes with it.
  • reuses a mint whose version this build predates — fails if the regex is pinned to ^v1\., passes with ^v\d+\..

protectSession + protect + fapiClient suites: 98 passed, 1 skipped, 4 todo. Lint and typecheck are unchanged from the base — the single lint warning and the two TS6059 errors both reproduce on theo/js-session-token-clean untouched.

No changeset: this folds into the feature changeset already on #9299.

`validateToken` documented that a value which could not have come from a mint of
ours is discarded, but only checked type, length and expiry — so a corrupt or
truncated store entry counted as fresh and suppressed acquisition until it
expired, up to the lifetime ceiling.

This is hygiene, not a security boundary, and is deliberately not framed as one:
only the backend can tell a real token from a well-formed forgery, and anything
that can write the store can send the same values to the API directly. What it
buys is that a broken entry starts a fresh run immediately.

The shape is matched version-agnostically. Pinning it to the current version
would mean an SDK rejecting a token the backend had minted ahead of it, and
re-running the loader on every page load until the SDK caught up — a test guards
against that tightening.
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview Aug 7, 2026 1:34am
swingset Ready Ready Preview Aug 7, 2026 1:34am

Request Review

@zourzouvillys
zourzouvillys merged commit 09bfef2 into theo/js-session-token-clean Aug 7, 2026
11 checks passed
@zourzouvillys
zourzouvillys deleted the theo/js-session-token-shape-check branch August 7, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant