Vulnerability class

How to prove CSRF, and verify the token is actually enforced

Updated

CSRF is proven when a request originating from another site performs a state change with the victim's cookie. A token in the form is not protection — it has to be required server-side and rejected on mismatch.

Where this class of bug actually lives in cookie-authenticated state changes

  • Endpoints exempted from the token. Webhooks and JSON APIs are commonly excluded from CSRF middleware, which also excludes the state-changing routes that share the prefix.
  • Tokens that are not verified. The field is rendered; the server never compares it.
  • SameSite=None cookies. Required for cross-site embeds, and it removes the browser's own defence.
  • GET requests with side effects. Any state change reachable by an img or a link is trivially CSRF-able.

What to try first

  1. Build a local HTML page that posts to the target endpoint and open it while signed in. If the action happens, it is CSRF.
  2. Remove the token from a form POST and see whether the server accepts it.
  3. Send a token from a different session and see whether it is accepted.
  4. Check SameSite on the session cookie and whether cookies authenticate JSON endpoints.

A reproduction you can keep

Cross-origin needs a real page. Serve one locally, open it authenticated:

Minimal CSRF proof page
cat > /tmp/csrf.html <<'HTML'
<form action="https://staging.example.com/api/email" method="POST"
      enctype="application/x-www-form-urlencoded">
  <input name="email" value="attacker@example.com">
</form>
<script>document.forms[0].submit()</script>
HTML
python3 -m http.server 8000 --directory /tmp &
open http://127.0.0.1:8000/csrf.html     # signed in to staging in the same browser

# vulnerable: the account email changes
# fixed: 403 CSRF token missing or invalid, and the email is unchanged

What "fixed" has to look like

Require a per-session token on every state-changing method and reject a missing or mismatched one; set SameSite=Lax or stricter on the session cookie. Verify by posting without a token, with a stale token, and from a cross-origin page — all three must fail and the record must be unchanged.

Where people get this wrong

  • A token rendered but not compared is the most common false fix.
  • Exempting an API prefix from CSRF middleware exempts every state-changing route under it.
  • SameSite=Lax still permits top-level GET navigations, so any GET with a side effect remains exploitable.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Is CSRF still relevant with SameSite cookies?

Yes. SameSite=None is needed for embeds, older browsers ignore the attribute, and GET-with-side-effect remains reachable from a top-level navigation.

Why does a token in the form not stop CSRF?

Because the attack page cannot read the victim's token — but if the server accepts a missing token, it does not need to.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.