CSRF Token Bypasses

Ways anti-CSRF tokens fail in practice: the token is issued but not enforced, enforced only on some methods, content types or routes, not bound to the session, predictable, leakable, or attacker-plantable.

How it works

A token defends only if, for every state-changing request in every accepted format, the server (1) requires it, (2) compares it to a value bound to this session, and (3) the value cannot be read, guessed or set by the attacker. Real bugs break one leg; the frontend still sends the token, so scanners mark the endpoint “protected”.

Techniques / payloads

Validation gaps (send each variant; compare to the baseline):

VariantCatches
Drop the parameter/header entirely”validate only if present”
Keep the name, empty value (csrf=)existence-only checks
Random value, same lengthformat-only checks
Token from attacker’s own sessionglobal token pool / not session-bound
Placeholder string (csrf-token)backend never receives the rendered value
Integer 0 via JSON ("_token": 0)Laravel loose-comparison bypass noted by Cobalt
Stale/expired tokenmissing expiry

Method-conditioned enforcement. Checks gated on REQUEST_METHOD === 'POST' skip GET/HEAD; combined with $_REQUEST merging, a token-protected POST becomes a one-click GET. Also try _method / X-HTTP-Method-Override where the check runs on the wire method but the handler routes on the override — see Method Override CSRF.

if ($_SERVER['REQUEST_METHOD'] !== 'POST') return true; // GET, HEAD bypass CSRF

Format-conditioned enforcement. The JSON path requires X-CSRF-Token/Rfcsrf, but the same route also parses application/x-www-form-urlencoded and skips the check — a plain form then works. See JSON CSRF.

Route exemptions. Exemption lists for agents/webhooks written as globs but matched as unanchored regex (derp/* exempts any path containing derp); framework config that disables CSRF for a whole legacy prefix (Spring ignoringRequestMatchers).

Ordering bugs. User loaded/memoized in a before_action before the CSRF check: Rails’ null_session strategy nulls the session but the memoized @current_user survives, so the forged request still runs as the user.

Token tied to a non-session cookie / naive double submit. If the server only checks cookie == param, an attacker who can write a cookie on the target (CRLF/header injection, sibling subdomain, plaintext-HTTP injection on a non-__Host- cookie) plants both halves:

<img src="https://target/?x=%0d%0aSet-Cookie:%20csrf=AAAA" onerror="document.forms[0].submit()">
<form action="https://target/email/change" method="POST"><input name="csrf" value="AAAA">…</form>

Fails if the token is derived from the session cookie (you’d overwrite the victim’s session).

Weak token construction. pac4j compared tokens via Java String.hashCode(): collisions are computable without knowing the victim’s token, collapsing the space to 32 bits (CVE-2026-40458).

Leakage. Tokens in URLs (?_token=) leak through history, logs and Referer; tokens readable by JS or sent over plaintext; any XSS reads the token from DOM/meta tag or replays the header the app attaches. A reflected, unescaped token is itself an injection sink (Litestar, CHCon 2026).

Token scope reuse. A token minted for /login accepted by /register/step2 (SourceHut CVE-2026-121728).

Non-token gates. CAPTCHA or “type confirm” steps: test whether the value is single-use and server-verified. emlog’s write gate was the literal string confirm; one Self-XSS chain succeeded by reusing an unused CAPTCHA value.

Notable cases

Defenses

  • Enforce centrally (deny-by-default middleware), on the effective method, for every content type the route parses; reject missing, empty or malformed tokens.
  • Bind to session: synchronizer token, or signed double-submit (HMAC over session-bound value + random, constant-time compare). Naive double-submit is discouraged.
  • Never put tokens in URLs; rotate on login; scope per form/action where feasible (Rails per-form tokens, one-time-pad masking against BREACH).
  • Anchor exemption patterns; test with two accounts (cross-session token reuse only shows up that way).
  • See CSRF Prevention.

Sources