Cookie-based login with no CSRF protection on state-changing requests

Last updated November 11, 2026
Steps
- List every route that changes something: updates, deletes, payments, settings, invites. Make sure none of them run on GET. Move them to POST, PUT, PATCH or DELETE.
- Use your framework's built-in protection first. Next.js Server Actions only accept POST and compare the Origin header to the Host (or X-Forwarded-Host) header; if you sit behind a proxy, set serverActions.allowedOrigins instead of turning the check off.
- For custom API routes (Route Handlers, Express, etc.) that use cookie sessions, add a check: reject state-changing requests where Sec-Fetch-Site is cross-site, and when that header is missing, require a matching Origin header or a valid CSRF token.
- If you use tokens, use a framework-supported synchronizer token or a signed double-submit cookie tied to the session. Never put the token in the URL or logs.
- Set session cookies with SameSite=Lax or Strict, Secure and HttpOnly, and prefer the __Host- prefix. Treat this as extra protection, not the only one.
- Test it: from a page on a different origin, submit a form that POSTs to one of your routes while logged in. The request should be rejected.
- Fix any XSS first, too. OWASP warns that cross-site scripting can defeat every CSRF defense.
Why it matters
OWASP says a CSRF attack tricks an authenticated user's browser into performing an unwanted action on a trusted site, and that it works because browsers automatically include cookies, including session cookies. The attacker can do anything the victim is allowed to do, such as change a password or make a purchase. OWASP recommends using built-in framework protection first, never using GET for state-changing operations, and treating SameSite cookies as defense in depth, since SameSite=Lax still sends cookies on top-level GET navigations. The Next.js data security guide says Server Actions are invoked only with POST and check that the Origin matches the Host, which blocks most CSRF for Server Actions. Custom routes don't get that check automatically. MITRE tracks this weakness as CWE-352, Cross-Site Request Forgery.
Sources
OWASP Cheat Sheet Series: Cross-Site Request Forgery Prevention Cheat Sheet — https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
Next.js docs: Data Security (Server Actions, allowed origins) — https://nextjs.org/docs/app/guides/data-security
MITRE CWE-352: Cross-Site Request Forgery (CSRF) — https://cwe.mitre.org/data/definitions/352.html
Related patterns
- CORS that trusts any origin (and sends cookies)
- Server Actions with no auth check inside them
- JWTs or session tokens stored in localStorage
- Rendering user or AI output as raw HTML (XSS)
- API routes with no auth check
- Sessions that stay valid after logout, password change or timeout
- Session cookies missing Secure, HttpOnly or SameSite
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.