Fix it in your stack

Tested fixes for CWE-352 in Express, Flask, Spring Boot, ASP.NET Core, Django, Rails and Laravel: the vulnerable code, the fix, a plausible fix that still fails, and the regression tests.

Definition

MITRE’s description of CWE-352: The web application does not, or cannot, sufficiently verify whether a request was intentionally provided by the user who sent the request, which could have originated from an unauthorized actor.

Common consequences MITRE lists

  • Confidentiality, Integrity, Availability, Non-Repudiation, Access Control: Gain Privileges or Assume Identity; Bypass Protection Mechanism; Read Application Data; Modify Application Data; DoS: Crash, Exit, or Restart

Why it matters

Any site the user visits can trigger state-changing requests that carry their cookies, so settings, payments or account details change without the user meaning it.

How to prevent it

  • Reject cross-site state-changing requests by checking Sec-Fetch-Site or Origin, and use a synchronizer or double-submit token where those signals are unavailable.
  • Set session cookies with SameSite=Lax or Strict as defense in depth; it does not stop requests from sibling subdomains, which count as same-site.
  • Never change state on GET, HEAD or other safe methods.
  • Ask the user to re-authenticate or confirm before high-impact changes such as email, password or payout details.

Guides on this site

Practice

References

  1. CWE-352 in the MITRE CWE list (version 4.20)
  2. 2025 CWE Top 25 Most Dangerous Software Weaknesses (MITRE CWE Program)
  3. OWASP Cross-Site Request Forgery Prevention Cheat Sheet

List data from MITRE; the name, definition and consequences are from MITRE’s CWE 4.20 catalogue. A guide is listed as the main subject when the weakness is what the guide is about, and as covering it when a dedicated section or worked example addresses it.

CWE content: Copyright © 2006–2026, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. CWE™ is free to use by any organization or individual for any research, development, and/or commercial purposes, per these CWE Terms of Use. Accordingly, The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. Any copy you make for such purposes is authorized on the condition that you reproduce MITRE’s copyright designation and this license in any such copy. CWE is a trademark of The MITRE Corporation. CWE Terms of Use.