Skip to main content
HighAI codeOWASP A01:2021CWE-352

How to fix: Form Missing CSRF Protection

An HTML form was found without a CSRF token field. AI-generated form scaffolding commonly omits CSRF protection, assuming the developer will add it later.

Why it matters

Without CSRF protection, any website can submit forms on behalf of an authenticated user by tricking them into visiting a malicious page. This enables attackers to change passwords, transfer funds, delete accounts, or perform any privileged action the user can perform.

CSRF attacks exploit the browser's automatic inclusion of cookies in cross-origin requests. When a form lacks a CSRF token, a malicious page can create a form that submits to your site and the victim's authenticated session is automatically included.

How to fix it

  1. 1Add CSRF tokens to all state-changing forms: a cryptographically random value stored in the session and verified on submission.
  2. 2Use the SameSite=Strict cookie attribute to prevent cross-origin cookie inclusion.
  3. 3For JSON APIs, verify the Content-Type header is application/json (browsers cannot set this cross-origin in forms).
  4. 4Use framework CSRF middleware: csurf (Express), Django's CsrfViewMiddleware, Rails' protect_from_forgery.

Code examples

Next.js CSRF with SameSite cookies

TypeScript
// Set session cookie with SameSite=Strict
res.setHeader('Set-Cookie', [
  `session=${token}; HttpOnly; Secure; SameSite=Strict; Path=/`
]);

// For forms, include CSRF token
<form method="POST" action="/api/action">
  <input type="hidden" name="_csrf" value={csrfToken} />
  ...
</form>

References

Detected automatically by VulnRadar. The check id is vibe-missing-csrf, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is Form Missing CSRF Protection?
VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-missing-csrf, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Form Missing CSRF Protection map to?
It maps to CWE-352. In the OWASP Top 10 it falls under A01:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for form missing csrf protection

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Form Missing CSRF Protection | VulnRadar