Login form has CSRF protection
Why it matters
Login CSRF (CAPEC-62) lets an attacker log a victim into an attacker-controlled account using a forged cross-site request. This enables account takeover indirectly: the victim, now logged into the attacker's account, may enter sensitive data that the attacker can later retrieve. CWE-352 (CSRF) on a login endpoint is classified under OWASP A01 (Broken Access Control); PCI-DSS v4.0 Req-6.2.4 explicitly lists cross-site request forgery among the software attacks that engineering practices must prevent. SameSite=Lax provides meaningful browser-enforced protection for most cases, but explicit CSRF token validation is required for custom endpoints that process sensitive actions on navigation.
Severity rationale
Critical because login CSRF can silently associate a victim's activity with an attacker's account, enabling credential harvesting and session theft without any direct compromise of the victim's credentials.
Remediation
If using NextAuth, CSRF protection is built into the credential callback — do not bypass the standard signin form flow. For custom endpoints, add explicit CSRF token validation:
import { csrf } from '@edge-csrf/nextjs'
const csrfProtect = csrf({ cookie: { secure: true } })
export async function POST(request: Request) {
const csrfError = await csrfProtect(request)
if (csrfError) return Response.json({ error: 'Invalid CSRF token' }, { status: 403 })
// login logic
}
Verify session cookies have SameSite=Lax set (see the session-tokens-secure check) as a defense-in-depth layer. Do not rely on SameSite alone when you can add a CSRF token.
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 Authentication 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
- capec · CAPEC-62 — Cross-Site Request Forgery
- pci-dss:4.0 · Req 6.2.4
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-authentication·automated