Post

CSRF Bypass Techniques (Deep Dive)

CSRF Bypass Techniques (Deep Dive)

What We’re Targeting

These are cases where:

  • A CSRF token is present but flawed
  • Cookies are misconfigured (SameSite, Secure, etc.)
  • Referer / Origin headers are relied on—but can be bypassed
  • Application behavior allows leakage or reuse

Bypass Techniques Overview

TechniqueProtection BypassedScenario
1. Token Reuse or LeakStatic or predictable CSRF tokensToken is same across users or pages
2. Misconfigured SameSiteSameSite set to None or missingCookies sent in cross-origin requests
3. JSON CSRFTokens not enforced on application/jsonNo CORS preflight + cookies auto-sent
4. Referer Header BypassServer uses referer as CSRF checkHeader can be spoofed in some edge cases
5. CORS MisconfigurationTrusts Origin without validating CredentialsRequests with cookies from cross-origin go through
6. Multi-step CSRFEach request step is CSRF-safe but chain allows state-changeCombine endpoints
7. Login CSRFCSRF used on login to set known credsNo anti-CSRF on login form

1. Token Reuse or Leakage

Scenario:

The CSRF token is:

  • Static for the user session
  • Embedded in HTML and exposed via GET
  • Not bound to the user (or action)

Example :

1
<input type="hidden" name="csrf_token" value="123456"/>
  • Use Burp to capture the token
  • Reuse it in CSRF PoC

Endpoint :

1
2
POST /account/update-email 
csrf_token=123456&email=attacker@evil.com

Impact :

If an attacker can obtain or guess the token, they can send a CSRF request with a valid token and bypass protection.

Scenario :

Cookie is not marked as SameSite or is set to SameSite=None without Secure.

1
Set-Cookie: session=xyz; SameSite=None

Endpoint:

1
POST /user/change-password
  • Test using your CSRF PoC : if cookies are sent, this may work.

Impact :

Login session is used in a forged request from another origin.

3. JSON CSRF (a.k.a. JSON Hijacking)

Scenario :

Application uses JSON API:

1
2
POST /api/change-email
Content-Type: application/json

Protection fails if :

  • Token is not required
  • CORS not enforced correctly

Browser auto-sends cookies even for JSON unless:

  • SameSite blocks it
  • CORS blocks it

Trick :

Use JavaScript to submit JSON:

1
2
3
4
5
6
7
8
fetch('<https://target.com/api/change-email>', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({email: "attacker@evil.com"})
});

Impact :

Full API control via CSRF — often works if backend has weak CORS + no token.

4. Referer Header Check Bypass

Scenario :

App validates the Referer or Origin headers to allow the request.

1
Referer: <https://target.com/account/change-password> 

But :

  • Old browsers/extensions can leak referer
  • Some misconfigured proxies allow header manipulation
  • Intra-site redirection tricks can be used

Trick :

Host a redirector on a subdomain like:

1
2
evil.target.com → redirects to /account/update?csrf_payload

Then the Referer becomes: https://evil.target.com

If the backend only checks:

1
Referer.startsWith("<https://target.com>")
  • It fails.

5. CORS Misconfiguration

Scenario :

  • App allows cross-origin POST
  • Access-Control-Allow-Origin: *
  • Cookies sent with request (missing Access-Control-Allow-Credentials: true block)

Trick :

Craft a fetch() request to sensitive endpoint with credentials:

1
2
3
4
fetch("<https://target.com/api/delete-account>", {
  method: "POST",
  credentials: "include",
});

Impact :

CORS + CSRF = full account hijack.

6. Multi-Step CSRF

Scenario :

  1. Step 1: GET /start-change — CSRF-safe
  2. Step 2: POST /confirm-change — lacks protection

Trick :

Auto-submit both steps from your page :

1
2
3
4
5
6
7
8
9
10
11
12
<iframe src="<https://target.com/start-change>" onload="step2()"></iframe>

<script>
  function step2() {
    var f = document.createElement("form");
    f.method = "POST";
    f.action = "<https://target.com/confirm-change>";
    f.innerHTML = '<input name="confirm" value="yes">';
    document.body.appendChild(f);
    f.submit();
  }
</script>

Impact :

By chaining steps, attacker executes a CSRF that bypasses step-based protections.

7. Login CSRF

Scenario :

If a site allows login via POST, and doesn’t have CSRF protection on login form, an attacker can:

  • Force login with attacker creds
  • Victim’s session is now authenticated as attacker
1
2
3
4
<form method="POST" action="<https://target.com/login>">
  <input name="username" value="attacker">
  <input name="password" value="123456">
</form>

Impact :

  • Session fixation
  • Victim uses attacker account
  • Attacker gains indirect access to victim’s actions

Testing Tips :

1
2
3
4
5
Burp Suite                >         Intercept and repeat POSTs, modify CSRF tokens
DevTools                  >         Observe network requests, token presence
Cookie Editor             >         View and edit SameSite attributes
Custom HTML PoC           >         Test auto-submission
Firefox Multi-Container   >         Simulate cross-origin sessions

Summary

Bypass TechniqueBypassesFix
1. Reusable TokenToken mismanagementPer-request, per-user token
2. Missing/Weak SameSiteCross-origin cookie leakageSet SameSite=Strict
3. JSON CSRFAPI not protectedCSRF token for all state-changing requests
4. Referer/Origin Weak CheckSHeader spoofing/redirectionUse CSRF tokens instead
5. Misconfigured CORSOpen CORS + cookiesDisallow credentials or restrict origins
6. Multi-stepNo token on one stepToken on every state-changing step
7. Login CSRFNo CSRF on loginCSRF tokens for login too
This post is licensed under CC BY 4.0 by the author.