OWASP Cheat Sheet: Cross-Site Request Forgery Prevention Cheat Sheet / GUIDANCE
Cross-Site Request Forgery Prevention Cheat Sheet
A Cross-Site Request Forgery (CSRF) attack occurs when a malicious web site, email, blog, instant message, or program tricks an authenticated user's web browser into performing an unwanted action on a trusted site. If a target user is authenticated to the site, unprotected target sites cannot distinguish between legitimate authorized requests and forged authenticated requests. Since browser requests automatically include all cookies including session cookies, this attack works unless proper authorization is used, which means that the target site's challenge-response mechanism does not verify the identity and authority of the requester. In effect, CSRF attacks make a target system perform attacker-specified functions via the victim's browser without the victim's knowledge (normally until after the unauthorized actions have been committed). However, successful CSRF attacks can only exploit the capabilities exposed by the vulnerable application and the user's privileges. Depending on the user's credentials, the attacker can transfer funds, change a password, make an unauthorized purchase, elevate privileges for a target account, or take any action that the user is permitted to do. In short, the following principles should be followed to defend against CSRF: IMPORTANT: Remember that Cross-Site Scripting (XSS) can defeat all CSRF mitigation techniques! While Cross-Site Scripting (XSS) vulnerabilities can bypass CSRF protections, CSRF tokens are still essential for web applications that rely on cookies for authentication. Consider the client and authentication method to determine the best approach for CSRF protection in your application. - See the OWASP XSS Prevention Cheat Sheet for detailed guidance on how to prevent XSS flaws. - First, check if your framework has built-in […]
- Category
- OWASP API
- Version / scope
- OWASP Cheat Sheet Series; commit 7af0ef1b745f1a38ce905c00c5a592d5b3a515a9
- Affected / relevant technologies
- Web applications / APIs
- Evidence
- Documentation: pinned-source excerpt checked. Execution: not tested. Editorial: curated reference.
Defensive analysis and explicitly authorized assessment only. This website performs no scans, exploitation, model calls or infrastructure changes. Indicators below are investigation opportunities, not proof of compromise or guaranteed detectors.
Mechanism and prerequisites
Match the design and deployment assumptions in the cited revision. Use authorized review evidence; do not send production secrets to test systems.
Potential impact
This is preventive engineering guidance, not a new Top 10 risk, a CVE or proof of an exploitable deployment.
Versioned source scope
This record contains normalized, sometimes shortened source excerpts with editorial safety context. Markup and executable example blocks are omitted. Source-field verification does not establish device testing, a working detector or local applicability.
Publisher: OWASP. Release: OWASP Cheat Sheet Series; commit 7af0ef1b745f1a38ce905c00c5a592d5b3a515a9. Source checked: 2026-11-18.
Source object: OWASP Cheat Sheet: Cross-Site Request Forgery Prevention Cheat Sheet.
Attribution and source terms (OWASP contributors · CC BY-SA 4.0)Detection and investigation
- Publisher review topics: Token-Based Mitigation; Rollout & testing recommendations; Client-side CSRF Mitigation Techniques; Defense In Depth Techniques; User Interaction-Based CSRF Defense
Preserve source timestamps, asset identity and collection context. Correlate independent evidence before attributing malicious intent. In OT, review passive evidence with the process owner; do not induce failures, replay commands or write to controllers to test a hypothesis.
Mitigation and response
- The synchronizer token pattern is one of the most popular and recommended methods to mitigate CSRF.
- - Include an appropriate Vary header, in order to ensure that caches handle the response appropriately. For example, Vary: Sec-Fetch-Site, Origin. See more Fetch Metadata specification. - Note that the Vary header does not impact CSRF defenses in any way. It is a response header, so it is applied after the server has already made its allow/deny decision based on CSRF protections. Its purpose is operational rather than defensive. - If the server responds differently based on HTTP headers (e.g., Sec-Fetch-Site, Origin), caches must vary on those headers. Without this, CDNs or proxies may reuse a response generated for a different context, causing broken behavior or contributing to cache-poisoning scenarios. Adding the appropriate Vary header ensures caches keep these responses separate. - Start in “log only” mode. Record requests that would be blocked and review for false positives before enforcing. This is the safest way to discover legitimate flows that need whitelisting. - Monitor UA coverage. Track which user agents include Sec-Fetch- and which don’t; ensure your fallback logic covers missing-header cases. Use metrics to decide when to enforce stricter policies. - Document […]
Apply changes through the asset owner's approved change and recovery process. Documentation review is separate from successful testing or verified production protection.
Related technical context
No protocol-specific mapping is asserted for this entry.
Related security reading
Continue directly to another reference. Editorial reading connections do not assert official CWE/CAPEC/ATT&CK/OWASP equivalence or mappings.
Authoritative sources and attribution
Identifiers and source titles belong to OWASP, MITRE, the CVE Program, CISA, NIST or the cited vendor. Source excerpts are attributed and adapted under the linked publisher license; editorial context is separate. This is not an official framework mirror. Review baseline: 2026-11-18. Live documents can change; check exact current applicability.
- Publisher reference: OWASP Cheat Sheet: Cross-Site Request Forgery Prevention Cheat Sheet — source accessed 2026-11-18
- cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.md — source accessed 2026-11-18
Source review supports bounded reference text. It is not execution evidence, a completeness claim, a CVSS assessment, a compliance certification or verification of production security.
