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

Problem Framing: The Trust Exploitation Vector

Cross-Site Request Forgery (CSRF), often shortened to XSRF or sometimes pronounced "sea-surf," is a potent class of web vulnerability that exploits the inherent trust relationship between a web application and a user's authenticated browser [1][2]. Unlike attacks that directly target the application's code or infrastructure, CSRF leverages the browser's automatic behavior of including authentication credentials (typically session cookies) with every outgoing request to a given domain [1][3]. An attacker crafts a malicious request, often embedded within a seemingly innocuous webpage or email, and tricks the user's browser into submitting it to the target application. Because the request originates from an authenticated user's browser, the application treats it as legitimate and executes the requested action, even if the user never intended to perform it [4][5][2].

The core of a CSRF attack lies in this deception: the attacker doesn't steal credentials or credentials themselves. Instead, they forge a request on behalf of the victim by hijacking the trust that the application has in the victim's browser [4][1]. This trust is usually embodied by session cookies, which are automatically sent with subsequent requests to the issuing website [6][4]. The consequences can range from minor annoyances to severe compromise, including unauthorized transactions, data theft, account takeovers, and even full application compromise if the victim holds administrative privileges [6][4][5].

Web applications become vulnerable when they perform state-changing operations based on user input without sufficient verification that the user intended that specific action. This often occurs when applications rely solely on session cookies for authentication and authorization without implementing additional checks to validate the request's origin or the user's explicit consent for the operation [1][3].

Core Mechanics: How CSRF Works Under the Hood

At its heart, a CSRF attack operates on a few fundamental principles:

The typical attack flow involves these steps:

  1. Reconnaissance: The attacker identifies a state-changing functionality within the target application that appears vulnerable. This involves discovering endpoints and understanding their expected parameters.
  2. Crafting the Malicious Request: The attacker constructs a request that mimics a legitimate action, potentially embedding it within an HTML form, an ` tag's src attribute, or a JavaScript fetch` call.
  3. Delivery: The attacker lures the victim into executing this crafted request. Common methods include social engineering via email, embedding the payload on a compromised website, or injecting it into user-generated content on the target site itself (stored CSRF) [4][1][10].
  4. Execution: When the victim, who is authenticated to the target application, visits the attacker-controlled page or encounters the malicious content, their browser automatically sends the forged request. Crucially, this request includes the victim's session cookies.
  5. Server Processing: The target application receives the request, validates the session cookie (finding it to be legitimate), and, lacking further verification of user intent, executes the attacker-specified action [5][10].

The effectiveness of CSRF attacks has been significantly shaped by browser security evolution. Modern browsers implement SameSite cookie policies to restrict when cookies are sent in cross-origin requests [11][7][12]. However, bypasses still exist, particularly when older browsers are used, or when applications are misconfigured [13][14][15][12].

Notable Techniques and Attack Vectors

CSRF exploits manifest in various forms, often differing based on the HTTP method used and the application's specific defenses (or lack thereof).

GET-Based CSRF

This is often the simplest to execute, as an attacker can embed a malicious URL directly within an ` tag, ,