Skip to content

fix: accept only refresh cookies in verifyRefreshCookie - #264

Merged
Bccorb merged 1 commit into
mainfrom
fix/signed-cookie-kind
Nov 1, 2026
Merged

Bccorb merged 1 commit into
mainfrom
fix/signed-cookie-kind

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Every adapter cookie (pre-auth, registration, access, refresh) is an HS256 JWT signed with the same cookieSecret. verifyRefreshCookie checked only the signature, so any of them verified as a refresh cookie, and hasSeamlessSession in @seamless-auth/nextjs reported a session when one sat in the refresh cookie slot.

verifyRefreshCookie now also requires the refresh cookie's shape: a non-empty string sub, a non-empty string refreshToken, and no upstream token. Only refresh cookies carry a refresh token, and they never carry an upstream token, so the shape tells them apart without a new claim. Refresh cookies issued by earlier versions already have this shape, so existing sessions keep working.

The silent refresh path (refreshAccessToken) goes through the same function and gets the same check.

Tests

  • packages/core/tests/verifyRefreshCookie.test.js: accepts a refresh cookie; refuses pre-auth, access, mixed, empty, non-string and subject-less payloads, and a foreign secret
  • packages/nextjs/tests/session.test.js: hasSeamlessSession is false for a pre-auth or access cookie copied into the refresh slot

The new cases fail on main (8 failures) and pass with the change. pnpm test: core 596, express 264, nextjs 259, fastify 271, all passing. pnpm check:types-current passes.

@Bccorb Bccorb added security Security-relevant issue P1 Next labels Nov 1, 2026
@Bccorb
Bccorb merged commit 241a207 into main Nov 1, 2026
4 checks passed
@Bccorb
Bccorb deleted the fix/signed-cookie-kind branch November 1, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Next security Security-relevant issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant