Skip to content

fix(next-auth): harden getToken parsing and bind OAuth check cookies to provider#13469

Merged
gustavovalverde merged 2 commits into
v4from
fix/v4-jwt-and-oauth-check-hardening
Jul 20, 2026
Merged

fix(next-auth): harden getToken parsing and bind OAuth check cookies to provider#13469
gustavovalverde merged 2 commits into
v4from
fix/v4-jwt-and-oauth-check-hardening

Conversation

@gustavovalverde

Copy link
Copy Markdown
Collaborator

Two hardening fixes for the 4.x line, matching behavior already shipped in @auth/core@0.41.3.

getToken() returned an uncaught URIError when the Authorization header carried malformed percent-encoding, turning a garbage header into a request crash. It now treats the token as absent and returns null.

OAuth state, nonce, and PKCE check cookies were not tied to the provider that created them, so a check minted in one provider's flow could be redeemed in another's callback. The sealed cookie payload now records the issuing provider and the callback rejects any mismatch. Cookies minted before this change carry no provider field and are also rejected; users mid-sign-in during an upgrade see one failed callback and succeed on retry.

…headers

A request carrying a malformed percent-encoded bearer token (for example
`Authorization: Bearer %`) made getToken throw an uncaught URIError to the
caller instead of failing authentication cleanly. Decoding now treats a
malformed encoding as an invalid token and returns null, matching how
undecodable tokens are already handled.

Fixes GHSA-xmf8-cvqr-rfgj
The state, nonce, and PKCE check cookies used shared, non provider-specific
names, so a check cookie minted during a sign-in with one provider could be
replayed against a callback for a different provider. The sealed payload now
records the id of the provider that created it, and the callback rejects any
check cookie whose recorded provider does not match the provider handling the
request. Cookies minted before this change carry no provider id and are
rejected.
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
auth-docs Error Error Jul 20, 2026 10:44pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
next-auth-docs Ignored Ignored Jul 20, 2026 10:44pm
proxy Ignored Ignored Jul 20, 2026 10:44pm

Request Review

@gustavovalverde
gustavovalverde merged commit 5bca239 into v4 Jul 20, 2026
8 of 10 checks passed
@gustavovalverde
gustavovalverde deleted the fix/v4-jwt-and-oauth-check-hardening branch July 20, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant