appsec.fyi

CSRF — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

CSRF: A Practical Guide

Curated and synthesized by . Last updated 2026-06-29. Synthesized from 75 of 75 curated resources. Browse all 75 CSRF resources →

Problem Framing

Cross-Site Request Forgery (CSRF), also known as XSRF, is a prevalent and dangerous web application vulnerability that manipulates a user's browser into executing unwanted actions on a trusted web application where the user is authenticated [1][2][3][4][5]. This attack vector capitalizes on the trust web applications place in authenticated user sessions by exploiting the browser's automatic inclusion of session cookies with outgoing requests [1][6][7]. The core of a CSRF attack is tricking a logged-in user into unknowingly submitting a malicious request, which the vulnerable application then processes as legitimate due to the presence of the valid session cookie [2][7][8]. The impact can range from minor data manipulation to complete account takeover, financial loss, and reputational damage [1][6].

A CSRF attack typically requires three conditions to be met: a valuable action that can be performed, session management solely reliant on cookies (or similar automatically sent credentials), and the absence of unpredictable parameters within the request [5]. Attackers exploit these conditions by crafting malicious requests, often embedded in seemingly innocuous web pages, emails, or other content, that are sent to the vulnerable application when the victim interacts with them [1][2]. Even actions that are typically considered "safe," like retrieving data via GET requests, can be vulnerable if they trigger state changes or are inadequlemently protected [2][9]. The OWASP Top Ten has consistently listed CSRF as a significant threat, although modern browser protections have somewhat reduced its prevalence [7][10].

Core Mechanics

At its heart, a CSRF attack leverages the browser's fundamental behavior: automatically attaching session cookies to requests destined for a particular domain [1][2][7][8]. When a user logs into a web application, the server establishes a session and typically returns a session identifier, commonly stored in a cookie. Subsequent requests from that user's browser to the same application will include this session cookie, authenticating the user without explicit re-entry of credentials for each request [1].

An attacker's goal is to induce the user's browser to send a crafted, malicious request to the target application. This is typically achieved through social engineering, where the victim is lured to a malicious website or clicks on a deceptive link [1][2]. The malicious content might contain:

When the victim's browser processes these embedded requests, it automatically includes the session cookie associated with the target application. Because the request appears legitimate to the server—carrying valid authentication credentials—the application proceeds to execute the action specified in the malicious request [1][2][7]. This action could be anything from changing the user's email address or password to making unauthorized purchases or even initiating a mass email campaign [1][14][15][6][3]. The critical failure point for the application is the lack of verification to ensure that the request was intentionally initiated by the user, rather than being forged by an attacker [6][2][8].

Notable Techniques and Attack Vectors

CSRF attacks manifest in various forms, often exploiting specific application designs or security weaknesses. Understanding these techniques is crucial for effective detection and prevention.

GET-Based CSRF

This is one of the simpler forms of CSRF. If a state-changing operation can be triggered by a GET request with predictable parameters, an attacker can easily craft a malicious link. This link can be embedded in an tag, a tag, or even a simple hyperlink that the victim clicks [6][2][3][12][9][5]. For example, changing an email address might be as simple as a URL like http://vulnerable-site.com/change-email?email=attacker@evil.com. The browser, when trying to load the tag, will send the request with the user's session cookie, executing the change [3][12].

POST-Based CSRF

When state-changing actions are implemented using POST requests, attackers typically need to trick the user into submitting an HTML form. This form is often hidden and configured with JavaScript to auto-submit, minimizing user interaction [6][11][3][12][4][9]. The attacker hosts this form on their own domain, and when the victim visits the page, the browser submits the form with the user's session cookie.

JSON Endpoint Exploitation

Modern applications frequently use JSON for data transfer via AJAX requests. Exploiting JSON endpoints for CSRF is more complex because AJAX requests are subject to the Same-Origin Policy (SOP), and application/json content types can trigger CORS preflight requests [13][12][4]. However, several bypass techniques exist:

Method Override Attacks

Some frameworks allow parameters like _method=POST or _method=DELETE within POST requests to override the HTTP method. If an application is protected against CSRF for POST requests but not for overridden methods, an attacker can craft a GET request that includes this override parameter, effectively turning a GET request into a POST or other state-changing request [18][19][17].

SameSite Cookie Bypass

The SameSite cookie attribute is a powerful defense against CSRF. However, several bypass techniques can circumvent it:

Bypassing CSRF Token Validation

While CSRF tokens are a robust defense, they can be bypassed if not implemented correctly:

Stored CSRF

When user-generated content (like comments or profile descriptions) can contain HTML or JavaScript, attackers can store malicious CSRF payloads persistently within the application. Any user who views this compromised content will unknowingly trigger the CSRF attack [6][28][7]. This is particularly dangerous for GET-based CSRF where a simple image tag can initiate the attack.

Detection and Prevention

Effective CSRF defense requires a layered approach, combining robust token management with browser-level security features.

Synchronizer Token Pattern (STP)

This is the most widely recommended and effective defense [1][28][29]. The core principle is to generate a unique, unpredictable, and secret token for each user session or, preferably, each request [29][30][31].

Double Submit Cookie Pattern

An alternative stateless approach where the server generates a pseudorandom value and sets it as a cookie and also includes it as a parameter (e.g., hidden form field or custom header) in state-changing requests [1][29].

SameSite Cookies

Introduced as a browser-level defense, SameSite attributes instruct the browser on when to send cookies with cross-site requests [1][32][24][33].

Fetch Metadata Headers

Modern browsers provide Fetch Metadata headers (Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest) that indicate the context of a request. Applications can leverage these headers, particularly Sec-Fetch-Site, to block cross-site requests that are not explicitly permitted [12][29]. For instance, allowing requests only where Sec-Fetch-Site is same-origin or same-site provides a robust defense.

Referer and Origin Header Validation

While less reliable than token-based methods or SameSite attributes, validating the Origin and Referer headers can offer a defense-in-depth layer [28][29][35]. Attackers can sometimes spoof or omit these headers, making them less secure as a sole protection mechanism. However, checking for their presence and expected values can help mitigate simpler attacks [36][35].

Avoiding State-Changing GET Requests

A fundamental best practice is to never use GET requests for operations that change server state. GET requests are designed for idempotency and data retrieval, not for performing actions [2][9][3]. Using POST, PUT, or DELETE for state changes, and protecting these methods with other CSRF defenses, is crucial [37][9].

Tooling

Several tools can assist in the identification and exploitation of CSRF vulnerabilities, as well as in implementing defenses.

Recent Developments and Trends

The landscape of CSRF defense has evolved significantly, with browser-level protections playing an increasingly prominent role.

Where to Go Deeper

For a thorough understanding and practical application of CSRF knowledge, the following resources are highly recommended:

Sources cited in this guide

  1. How to protect Node.js apps from CSRF attacks — snyk.io
  2. Cross-site request forgery - Wikipedia — en.wikipedia.org
  3. What is CSRF? Attacks, Mitigation, Prevention - Acunetix — acunetix.com
  4. Cross-Site Request Forgery (CSRF) Attack Guide | Hackviser — hackviser.com
  5. https://portswigger.net/web-security/csrf — portswigger.net
  6. The Bug Bounty Guide to Exploiting CSRF Vulnerabilities - YesWeHack — yeswehack.com
  7. CSRF Attacks - Rapid7 — rapid7.com
  8. Side-by-Side Comparison of SSRF vs. CSRF | Attaxion — attaxion.com
  9. Avoiding CSRF Attacks with API Design — thedreaming.org
  10. Samesite by Default and What It Means for Bug Bounty Hunters — blog.reconless.com
  11. CSRF: Cross Site Request Forgery Example - Imperva — imperva.com
  12. Cross-site request forgery (CSRF) - Security - MDN Web Docs — developer.mozilla.org
  13. CSRF in the Age of JSON — directdefense.com
  14. AVideo CSRF — CVE-2025-3100 (Critical) — dailycve.com
  15. Top CSRF HackerOne Reports — github.com
  16. CSRF & Bypasses - Cobalt — cobalt.io
  17. CSRF & Bypasses | Cobalt — cobalt.io
  18. Lab: SameSite Lax Bypass via Method Override | PortSwigger — portswigger.net
  19. CSRF (Cross Site Request Forgery) | HackTricks — book.hacktricks.xyz
  20. Web Security Academy: CSRF SameSite Lax Bypass via Method Override — medium.com
  21. CSRF Attacks: Bypassing SameSite Cookies — blog.cybersamir.com
  22. Advanced CSRF: How to Bypass SameSite Cookie Protections — sajjapremsai.github.io
  23. Lab: SameSite Lax Bypass via Cookie Refresh | PortSwigger — portswigger.net
  24. Bypassing SameSite Cookie Restrictions - CSRF | PortSwigger — portswigger.net
  25. Bypass SameSite Cookies Default to Lax and get CSRF — medium.com
  26. CSRF: Advanced Exploitation Guide - Intigriti — intigriti.com
  27. Steal CSRF/Auth/Unique key Header with XSS — medium.com
  28. CSRF - OWASP Foundation — owasp.org
  29. Cross-Site Request Forgery Prevention Cheat Sheet | OWASP — cheatsheetseries.owasp.org
  30. In Praise of CSRF Tokens – Tim MalcomVetter – Medium — medium.com
  31. https://medium.com/@jrozner/wiping-out-csrf-ded97ae7e83f — medium.com
  32. Preventing CSRF with the SameSite Cookie Attribute — invicti.com
  33. https://scotthelme.co.uk/csrf-is-dead/ — scotthelme.co.uk
  34. CSRF Protection - Clerk Docs — clerk.com
  35. https://mixmax.com/blog/modern-csrf — mixmax.com
  36. CWE-352: Cross-Site Request Forgery — cwe.mitre.org
  37. Web Application Security: Anti-CSRF & Cookie SameSite Options — bitsight.com
  38. 0xInfection/XSRFProbe — github.com
  39. 0ang3el/EasyCSRF — github.com
  40. ruby - Sinatra CSRF Authenticity tokens - Stack Overflow — stackoverflow.com
  41. A Deep Dive into CSRF Protection in Rails – Ruby Inside – Medium — medium.com
  42. WordPress Front End Security: CSRF and Nonces | CSS-Tricks — css-tricks.com
  43. WordPress Front End Security: CSRF and Nonces | CSS-Tricks — css-tricks.com
  44. Samesite by Default and What It Means for Bug Bounty Hunters — blog.reconless.com
  45. Authlib (Python) CSRF (Cache-Backed OAuth State) — CVE-2025-68158 — dailycve.com
  46. oauth 2.0 - How does CSRF work without state parameter in OAuth2.0? - Stack — stackoverflow.com
  47. Facebook GraphQL CSRF – These aren't the access_tokens you're looking for — philippeharewood.com
  48. Chaining Stored XSS and CSRF in Typemill CMS: A Deep Dive into Attribute Injection — infosecwriteups.com
  49. Advanced Techniques to Bypass CSRF Defenses — medium.com
  50. https://medium.com/@shub66452/account-takeover-using-csrf-json-based-a0e6efd1bffc — medium.com
  51. Self-XSS + CSRF to Stored XSS — medium.com
  52. CVE-2025-12821: WordPress NewsBlogger CSRF Allowing RCE — sentinelone.com
  53. CVE-2026-40925: CSRF in WWBN AVideo Configuration Endpoint — radar.offseq.com
  54. CVE-2025-9611: Microsoft Playwright MCP Server CSRF Flaw — sentinelone.com
  55. CVE-2025-23797: WP Options Editor CSRF Vulnerability — sentinelone.com
  56. CVE-2026-34394: Wwbn Avideo CSRF Vulnerability — sentinelone.com
  57. Cookies: HTTP State Management Mechanism (RFC 6265bis) — httpwg.org
📚 This guide is synthesized from the full text of resources curated in the CSRF library, and refreshed as new material is added.