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-07-01. Synthesized from 76 of 76 curated resources. Browse all 76 CSRF resources →

Problem Framing

Cross-Site Request Forgery (CSRF), also known as XSRF, is a pervasive and often underestimated attack vector that leverages the trust established between a web application and a user's browser [1][2]. At its core, CSRF exploits the browser's automatic inclusion of session cookies with outgoing requests. An attacker crafts a malicious request, delivered through social engineering or a compromised website, that tricks a logged-in user's browser into submitting this request to a trusted application without the user's knowledge or explicit consent [3][4][5].

The impact of a successful CSRF attack can range from minor annoyances to catastrophic breaches. For individual users, this can mean unauthorized transactions, changes to account settings, or even account takeover [6][3]. For organizations, a compromised administrative account can lead to full system compromise, data breaches, reputational damage, and financial losses [6][7][8]. The fundamental mechanism relies on the web application trusting the authenticated session (typically represented by a cookie) and executing state-changing actions based on this trust, without a mechanism to verify user intent [1][5].

While often contrasted with Cross-Site Scripting (XSS), which exploits the trust a user has in a website, CSRF exploits the trust a website has in a user's browser [1]. This subtle distinction highlights that CSRF attacks do not necessarily require script execution on the target site itself; rather, they rely on the browser's default behavior of sending credentials with requests [4].

Core Mechanics

The underlying principle of CSRF is the exploitation of authenticated user sessions maintained via browser cookies [6][3]. When a user logs into a web application, the server typically issues a session cookie that the browser stores. For subsequent requests to the same domain, the browser automatically includes this session cookie, implicitly authenticating the user [1][5].

An attacker crafts a malicious link or embedded form that directs the user's browser to send a specific HTTP request to the vulnerable application. This request is designed to perform a state-changing action, such as updating a user's email address, changing a password, or initiating a financial transaction [9][10][3][4]. Because the user is authenticated and the browser automatically includes the session cookie with the forged request, the server processes it as a legitimate, user-initiated action [1][5].

Key conditions that enable a CSRF attack include:

CSRF attacks can be categorized by the HTTP method used:

In modern web development, APIs often use JSON and AJAX requests. While the Same-Origin Policy (SOP) generally prevents cross-origin AJAX requests from reading responses, CSRF can still be a threat if the request itself is allowed to execute and modify state [16][17]. This often requires manipulating the Content-Type header or exploiting permissive CORS policies [16][15].

Notable Techniques and Vulnerabilities

The landscape of CSRF vulnerabilities is constantly evolving, with attackers finding novel ways to bypass defenses. Several recent reports highlight these trends:

Insufficient CSRF Token Validation: Many vulnerabilities arise from the incomplete or absent validation of CSRF tokens. For example, in Typemill CMS, a combination of Stored XSS and CSRF allowed for bypassing frontend validation and injecting malicious scripts, ultimately enabling admin session hijacking [9]. In other cases, applications might skip validation if a token is missing or empty, allowing an attacker to simply omit the token parameter [18][15][14]. Similarly, PAC4J software was found vulnerable to CSRF where an attacker could bypass protection by computing hash collisions for deterministic String.hashCode() functions, effectively reducing the security space of the CSRF token [19].

SameSite Cookie Mishandling: The SameSite cookie attribute is a powerful defense against CSRF. However, misconfigurations or bypasses remain a significant concern. When SameSite=None is used without proper security considerations, or when SameSite=Lax is exploited via methods that are not strictly top-level navigations or bypasses, CSRF can occur [20][21][22][23][24][25]. For instance, in WWBN AVideo, the explicit SameSite=None policy combined with a lack of CSRF token validation on configuration endpoints allowed attackers to overwrite critical settings [20][22]. Bypasses of SameSite=Lax often involve leveraging GET requests for state changes or utilizing redirect chains that might refresh cookies [21][26][27][23][17][25]. Some frameworks' handling of method overrides (e.g., _method=DELETE in GET requests) can also be exploited to bypass CSRF protections tied to specific HTTP methods [27][14].

GET Requests for State Changes: A persistent issue is the use of GET requests for operations that should be POST-based, such as modifying user data or performing actions [3][11][5][28][29]. Applications like KTM System e-BOK have been found vulnerable to CSRF in password and email change functionalities, often due to improper handling of state-changing GET requests [30]. Similarly, AVideo Platform's mass email functionality was exploitable via CSRF because it used GET parameters and lacked CSRF token validation [31].

Chaining CSRF with Other Vulnerabilities: CSRF is often more dangerous when chained with other vulnerabilities like Cross-Site Scripting (XSS). XSS can be used to steal CSRF tokens, making forgery trivial [32][33]. In some scenarios, a stored XSS vulnerability can allow an attacker to inject CSRF payloads that are executed when users view compromised content [9][3][8]. This chaining can lead to complex attack scenarios, including full account takeover [32][34][35].

Bypassing CSRF via OAuth Flows: Certain OAuth implementations can be susceptible to CSRF if not properly secured. Authlib, for example, had a vulnerability where cache-backed state storage did not verify the caller's session, allowing any session to use a valid state parameter, leading to account linking and potential takeover [36].

Impact on Specific Software: Numerous real-world examples demonstrate the impact of CSRF across various applications:

Detection and Prevention

Robust defense against CSRF requires a multi-layered approach, combining application-level controls with browser-based security features.

Prevention Strategies

Synchronizer Token Pattern (STP)

The most common and effective method is the Synchronizer Token Pattern (STP), also known as the anti-CSRF token [6][11][41][42][43]. This involves generating a unique, unpredictable token for each user session or even each request [6][41].

// Example HTML form with a CSRF token

<form action="/transfer" method="POST"> <input type="hidden" name="authenticity_token" value="a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6" /> <input type="text" name="recipient" /> <input type="text" name="amount" /> <button type="submit">Transfer</button> </form>

Double Submit Cookie Pattern

An alternative for stateless applications is the Double Submit Cookie pattern [6][41]. In this approach, a token is stored in a cookie and also sent as a parameter in the request (e.g., in a form field or custom header). The server validates that the cookie token matches the request token [6][4][41].

SameSite Cookie Attribute

The SameSite attribute is a browser-level defense that restricts when cookies are sent with cross-site requests [6][44][45][46][47][23][48].

It's crucial to understand that SameSite protections are browser-dependent and can be bypassed in certain scenarios, especially with older browser versions or specific configurations [6][21][23].

Fetch Metadata Headers

Modern browsers can send Fetch-Metadata headers (e.g., Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest) that provide context about a request's origin [49]. Servers can leverage these headers to block cross-site requests, particularly for non-simple requests, providing an additional layer of CSRF defense [49][41]. For example, blocking requests where Sec-Fetch-Site is not same-origin or same-site can be effective [49].

Other Mitigation Techniques

Detection Strategies

Identifying CSRF vulnerabilities involves manual testing and automated scanning:

Tooling

Several tools and libraries are invaluable for detecting, analyzing, and mitigating CSRF vulnerabilities:

Recent Developments

The security landscape continues to evolve, with new techniques and defenses emerging:

Where to Go Deeper

For those seeking to deepen their understanding of CSRF and its mitigation, the following resources are highly recommended:

Sources cited in this guide

  1. Cross-site request forgery - Wikipedia — en.wikipedia.org
  2. What Is CSRF? - Palo Alto Networks — paloaltonetworks.com
  3. The Bug Bounty Guide to Exploiting CSRF Vulnerabilities - YesWeHack — yeswehack.com
  4. CSRF: Cross Site Request Forgery Example - Imperva — imperva.com
  5. What is CSRF? Attacks, Mitigation, Prevention - Acunetix — acunetix.com
  6. How to protect Node.js apps from CSRF attacks — snyk.io
  7. CVE-2025-12821: WordPress NewsBlogger CSRF Allowing RCE — sentinelone.com
  8. CSRF Attacks - Rapid7 — rapid7.com
  9. Chaining Stored XSS and CSRF in Typemill CMS: A Deep Dive into Attribute Injection — infosecwriteups.com
  10. Manipulating User Email: A CSRF PoC From TCM Academy — medium.com
  11. CSRF - OWASP Foundation — owasp.org
  12. https://portswigger.net/web-security/csrf — portswigger.net
  13. CSRF: Advanced Exploitation Guide - Intigriti — intigriti.com
  14. CSRF (Cross Site Request Forgery) | HackTricks — book.hacktricks.xyz
  15. Cross-Site Request Forgery (CSRF) Attack Guide | Hackviser — hackviser.com
  16. CSRF in the Age of JSON — directdefense.com
  17. CSRF & Bypasses | Cobalt — cobalt.io
  18. CSRF & Bypasses - Cobalt — cobalt.io
  19. Vulnerabilities in PAC4J software — cert.pl
  20. CVE-2026-40925: CSRF in WWBN AVideo Configuration Endpoint — radar.offseq.com
  21. CSRF Attacks: Bypassing SameSite Cookies — blog.cybersamir.com
  22. CVE-2026-34394: Wwbn Avideo CSRF Vulnerability — sentinelone.com
  23. Bypassing SameSite Cookie Restrictions - CSRF | PortSwigger — portswigger.net
  24. Samesite by Default and What It Means for Bug Bounty Hunters — blog.reconless.com
  25. Bypass SameSite Cookies Default to Lax and get CSRF — medium.com
  26. Lab: SameSite Lax Bypass via Cookie Refresh | PortSwigger — portswigger.net
  27. Lab: SameSite Lax Bypass via Method Override | PortSwigger — portswigger.net
  28. Avoiding CSRF Attacks with API Design — thedreaming.org
  29. WordPress Front End Security: CSRF and Nonces | CSS-Tricks — css-tricks.com
  30. Vulnerabilities in KTM System e-BOK software — cert.pl
  31. AVideo CSRF — CVE-2025-3100 (Critical) — dailycve.com
  32. Top CSRF HackerOne Reports — github.com
  33. Steal CSRF/Auth/Unique key Header with XSS — medium.com
  34. Self-XSS + CSRF to Stored XSS — medium.com
  35. https://medium.com/@shub66452/account-takeover-using-csrf-json-based-a0e6efd1bffc — medium.com
  36. Authlib (Python) CSRF (Cache-Backed OAuth State) — CVE-2025-68158 — dailycve.com
  37. Jenkins Security Update Patches Sandbox Bypass Command Injection and CSRF Bugs — cyberpress.org
  38. CVE-2025-23797: WP Options Editor CSRF Vulnerability — sentinelone.com
  39. Internet Bug Bounty: Argo CD CSRF leads to Kubernetes cluster compromise — hackerone.com
  40. CVE-2025-9611: Microsoft Playwright MCP Server CSRF Flaw — sentinelone.com
  41. Cross-Site Request Forgery Prevention Cheat Sheet | OWASP — cheatsheetseries.owasp.org
  42. In Praise of CSRF Tokens – Tim MalcomVetter – Medium — medium.com
  43. https://medium.com/@jrozner/wiping-out-csrf-ded97ae7e83f — medium.com
  44. Web Application Security: Anti-CSRF & Cookie SameSite Options — bitsight.com
  45. Preventing CSRF with the SameSite Cookie Attribute — invicti.com
  46. Advanced CSRF: How to Bypass SameSite Cookie Protections — sajjapremsai.github.io
  47. Cookies: HTTP State Management Mechanism (RFC 6265bis) — httpwg.org
  48. Cross-Site Request Forgery is dead! — scotthelme.co.uk
  49. Cross-site request forgery (CSRF) - Security - MDN Web Docs — developer.mozilla.org
  50. https://scotthelme.co.uk/csrf-is-dead/ — scotthelme.co.uk
  51. ruby - Sinatra CSRF Authenticity tokens - Stack Overflow — stackoverflow.com
  52. A Deep Dive into CSRF Protection in Rails – Ruby Inside – Medium — medium.com
  53. 0xInfection/XSRFProbe — github.com
  54. 0ang3el/EasyCSRF — github.com
  55. Samesite by Default and What It Means for Bug Bounty Hunters — blog.reconless.com
  56. Facebook GraphQL CSRF – These aren't the access_tokens you're looking for — philippeharewood.com
  57. Facebook GraphQL CSRF – These aren't the access_tokens you're looking for — philippeharewood.com
  58. Web Security Academy: CSRF SameSite Lax Bypass via Method Override — medium.com
  59. Modern CSRF Mitigation in Single Page Applications — medium.com
  60. Top 25 CSRF Bug Bounty Reports — corneacristian.medium.com
  61. CSRF Protection - Clerk Docs — clerk.com
  62. CWE-352: Cross-Site Request Forgery — cwe.mitre.org
  63. CSRF Exploitation Techniques — Flaws, Bypasses & SameSite Cookie Mechanics — medium.com
  64. Advanced Techniques to Bypass CSRF Defenses — medium.com
  65. Side-by-Side Comparison of SSRF vs. CSRF | Attaxion — attaxion.com
  66. devanshbatham/Vulnerabilities-Unmasked — github.com
  67. https://www.purehacking.com/blog/andre-onofre-lima/bypassing-csrf-tokens-with-pythons-cgihttpserver — purehacking.com
  68. web application - Should login and logout action have CSRF protection? - In — security.stackexchange.com
  69. https://mixmax.com/blog/modern-csrf — mixmax.com
  70. oauth 2.0 - How does CSRF work without state parameter in OAuth2.0? - Stack — stackoverflow.com
  71. WordPress Front End Security: CSRF and Nonces | CSS-Tricks — css-tricks.com
  72. Favorite tweet by @manicode — twitter.com
  73. Cross-Site Request Forgery (CSRF) | Complete Guide — youtube.com
  74. Brute Forcing User IDS via CSRF To Delete all Users with CSRF attack. — link.medium.com
📚 This guide is synthesized from the full text of resources curated in the CSRF library, and refreshed as new material is added.