CSRF tokens on state-changing requests
Why it matters
Cross-site request forgery (CWE-352) allows a malicious page to trigger authenticated state-changing requests in a victim's browser using their existing session cookie. Without CSRF protection, any site can silently transfer funds, change email addresses, or delete accounts on behalf of a logged-in user. OWASP A01 (Broken Access Control) ranks CSRF among the most exploited web vulnerabilities. NIST 800-53 SC-23 requires session authenticity protection. The attack requires no special privileges — a single malicious link is sufficient. Cookies with SameSite=Lax or Strict are the minimal defense; APIs accepting cookie-authenticated requests need explicit origin validation on top.
Severity rationale
High because a successful CSRF attack lets any website perform authenticated actions as the victim without their knowledge, with no interaction beyond visiting a page.
Remediation
For Next.js apps, validate the Origin header on every state-changing route and ensure cookies are SameSite=Lax at minimum:
export function validateOrigin(req: Request): boolean {
const origin = req.headers.get('origin')
const host = req.headers.get('host')
if (!origin || !host) return false
return new URL(origin).host === host
}
For richer CSRF protection, use the csrf-csrf double-submit cookie pattern in src/middleware.ts. Do not rely on SameSite=None — it provides zero CSRF protection.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Security Hardening Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-352 — Cross-Site Request Forgery (CSRF)
- owasp:2021 · A01 — Broken Access Control
- nist:rev5 · SC-23 — Session Authenticity
Taxons
History
- 2026-04-18·v1.0.0·Initial import from security-hardening·automated