Skip to content

fix: allow cross-site navigate-mode cookie auth when csrf is configured#16177

Open
aqib-io wants to merge 1 commit intopayloadcms:mainfrom
aqib-io:fix/16031-cross-site-navigation-auth
Open

fix: allow cross-site navigate-mode cookie auth when csrf is configured#16177
aqib-io wants to merge 1 commit intopayloadcms:mainfrom
aqib-io:fix/16031-cross-site-navigation-auth

Conversation

@aqib-io
Copy link
Copy Markdown

@aqib-io aqib-io commented Apr 5, 2026

What?

Allow cookie-based authentication for cross-site top-level navigations (e.g. clicking a link from an email) when csrf is configured.

Why?

When csrf is configured and a user clicks a link from an external source (email client, OAuth callback, another site), the Sec-Fetch-Site: cross-site header causes the cookie to be rejected. This makes the user appear logged out on the first load.

How?

  • Added Sec-Fetch-Mode: navigate check to cookie extraction in extractJWT.ts
  • Sec-Fetch-Mode is a forbidden header that cannot be spoofed by JavaScript — only set by the browser for genuine page navigations
  • Combined with SameSite=Lax (Payload default), cross-site POST/XHR attacks remain blocked
  • Added 13 unit tests covering all cookie extraction scenarios

Fixes #16031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-site navigation (e.g. email links) logs out authenticated users in 3.79.1

1 participant