Cross-Site Request Forgery

CSRF (CWE-352) makes a victim’s browser send an authenticated, state-changing request the victim did not intend, because the server accepts ambient credentials (cookies, Basic/Digest, client certs, network position) without proof that the request came from its own UI.

What it is

The broken trust boundary is between who is authenticated and who authored the request. The server authenticates the browser, not the intent: cookies attach regardless of which page triggered the request, and HTML forms, links and simple fetch requests can target any origin. Three preconditions:

  1. A valuable action — email/password/MFA change, role grant, API key creation, payment, config change.
  2. Ambient credentials — session cookie whose SameSite policy lets it travel (None, unset in Firefox/Safari, or Lax on top-level GET), HTTP auth, or a loopback/intranet position.
  3. No unpredictable input — no enforced token, or one that can be removed, reused, guessed or planted.

CSRF exploits the site’s trust in the browser; XSS exploits the user’s trust in the site. Same-origin policy doesn’t help: it restricts reading responses, not sending simple requests. Variants that bypass “cross-site” framing entirely: same-site sibling attacks, client-side CSRF (attacker-steered same-origin JS, incl. CSPT2CSRF), and browser-to-localhost CSRF.

Why it matters

Impact rungTypical sinkExample
Integrity nuisancelikes, settings, logoutlogout CSRF (useful in chains)
Account takeoveremail change → password reset; OAuth connectCanva profile/email; $1,300 email-change ATO
Admin action as victimuser creation, role grant, ticket approvalWarpgate, Omnispace Agora, WatchGuard Dimension
Credential / secret theftconfig overwrite, hash exportAVideo SMTP creds; Wp Social OAuth secret; Injection Guard hash export
RCE / infra compromiseplugin install, file manager, SQL console, CI/CDNewsBlogger, Pluck, phpMyAdmin, emlog, Argo CD → K8s, NASA AIT-GUI

Severity drivers: privilege of the targeted user (admin bots and support staff open links), whether cookies actually travel (SameSite), whether the action is body-independent (one link/<img> is enough), and chaining with self-XSS. Of 42 CSRF disclosures catalogued 2024–2026, 27 had platform severity and five were High/Critical.

How it works

Delivery shapes

<!-- GET: only if cookie travels on subresource/nav -->
<img src="https://target/api/unlink">
<!-- POST: auto-submitting form; cookie needs SameSite=None (or same-site origin / Lax+POST window) -->
<form action="https://target/account/email" method="POST"><input name="email" value="x@evil.tld"></form>
<script>history.pushState('','','/');document.forms[0].submit()</script>

Variants (each with its own page):

  • Cookie-policy gaps and bypasses → SameSite Cookies
  • Token implementation flaws → CSRF Token Bypasses
  • JSON/API endpoints via simple content types, CORS, alternate body channels → JSON CSRF
  • GET/override/HEAD method tricks → Method Override CSRF
  • Origin/Referer/Fetch-Metadata defense failures → Referer and Origin Validation Bypasses
  • Session swapping into the attacker’s account, OAuth/SAML callbacks → Login CSRF
  • Stored CSRF: the forging <img>/form is hosted on the target itself (HTML-allowed fields, wiki pages) — same-site by construction (YesWiki despam, Samy-style worms).
  • Cross-site WebSocket hijacking: CSRF against the WS handshake (Warpgate /@warpgate/ streams, Zeppelin WS endpoints).
  • Client-side CSRF: JS builds request method/path from URL fragment, params, postMessage or uploaded JSON; app attaches its own CSRF header — tokens and SameSite don’t help.

Where to find it

  • Account/recovery: email, phone, password, MFA, linked identities, API keys, SSH keys — “crown jewel” mutations.
  • Admin panels of self-hosted products and CMS plugins (WordPress nonces missing on one handler is the recurring pattern).
  • OAuth/SAML/SSO callbacks, account-linking, consent/confirm endpoints.
  • Integrations: GraphQL endpoints accepting GET or form bodies; third-party integration connectors (HackerOne Tray.io).
  • Legacy paths and sibling apps sharing the session cookie with looser SameSite or CSRF exclusions.
  • Bodiless POST endpoints keyed by path (/approve/:id, /sessions/:id/close) — reachable by forms, no-cors fetch and even <a ping>.
  • Local/embedded services: dev servers, MCP servers, desktop agents, device UIs (modems, Tasmota), anything on 127.0.0.1/RFC1918.
  • Frameworks: per-method or per-content-type middleware (Hono csrf(), Flask-WTF + GET routes), exemption lists (Coder), session-store-specific cookie attributes (Rails Action Pack), filter ordering (Alchemy CMS).

How to test

  1. Inventory state-changing requests; tag cookie-authenticated ones (bearer-only APIs aren’t classic CSRF).
  2. Cookie check: every auth cookie’s SameSite/Secure/prefix, including remember-me and legacy-path cookies; note which browsers will send it.
  3. Token check (two accounts): remove, empty, random same length, other user’s token, stale token, placeholder; token in URL?
  4. Method: replay as GET, HEAD; _method=POST/override headers; PUT/PATCH/DELETE → POST.
  5. Content type: urlencoded, multipart, text/plain (JSON-shaped), text/plain; application/json; drop custom CSRF headers.
  6. Origin/Referer: omit, null, lookalike, query-embedded; check Sec-Fetch-Site: same-site acceptance.
  7. CORS: reflected Origin + ACAC: true on mutating routes.
  8. Same-site surface: enumerate siblings with XSS/upload/takeover; client-side redirect gadgets for Strict.
  9. Auth flows: login/logout/register tokens; OAuth state/PKCE binding; SAML RelayState.
  10. Build a browser PoC (Burp “Generate CSRF PoC”, CSRF PoC Creator) and confirm in a real browser with default settings — Burp acceptance ≠ exploitable.

Checklist

  • No GET/HEAD side effects; method override disabled or effective-method-aware
  • Token required, session-bound, all routes/methods/encodings, not in URLs
  • Auth cookies: explicit SameSite, __Host-, Secure
  • Origin/Sec-Fetch-Site exact, fail-closed, content-type-independent
  • JSON routes reject simple content types; CORS exact allow-list
  • Login/logout/OAuth/SAML bound to initiating browser
  • Siblings and redirect gadgets reviewed; WS handshakes check Origin
  • Local services validate Host/Origin

Exploitation and escalation

  • Self-XSS → stored XSS: CSRF the vulnerable profile field so the payload lands in the victim’s account (Renwa), or bypass a CAPTCHA gate with an unused value. With Login CSRF, log the victim into the attacker’s account that holds the self-XSS.
  • XSS → token theft: any same-origin/same-site XSS reads tokens or replays the app’s CSRF header; sibling XSS defeats SameSite and Sec-Fetch-Site trust (Argo CD).
  • Email change → reset → ATO; OAuth credential overwrite (Wp Social) → control of social login.
  • CSRF → RCE: plugin/module install (NewsBlogger, Pluck), file manager (WPIDE), SQL execution (phpMyAdmin, emlog), CI/CD deploys (Argo CD), spacecraft command routes (NASA AIT-GUI).
  • Browser as network pivot: unauthenticated device UIs (USB modem sends SMS with attacker-chosen content), localhost tools via DNS rebinding (Playwright MCP).
  • IDOR + CSRF: enumerate IDs in forged requests to delete all users, or hijack anonymous wizards (PetMemoria).
  • See Vulnerability Chaining and Account Takeover.

Bypassing defenses

DefenseCommon failurePage
SameSite LaxGET mutations, _method, Lax+POST 2-min window, siblings, client-side redirectsSameSite Cookies, Method Override CSRF
Tokensnot enforced, not session-bound, method/format-conditioned, leakable, hash collisionsCSRF Token Bypasses
Referer/Originfail-open on absence, substring match, exempt entry points, sub-resource RefererReferer and Origin Validation Bypasses
”JSON only”text/plain parsing, form encodings, text/ping, credentialed CORS, query-param bodyJSON CSRF
CAPTCHA / confirm stepreusable or hardcoded valuesCSRF Token Bypasses

Real-world cases

Prevention

Summary (detail in CSRF Prevention):

  • Use the framework’s CSRF protection and keep it global; tokens session-bound (synchronizer or signed double-submit), enforced on every non-safe effective method and every accepted encoding.
  • Or/and enforce Sec-Fetch-Site (reject cross-site, and same-site unless siblings are trusted) with exact Origin fallback; fail closed on absence.
  • Never mutate on GET/HEAD; disable method override.
  • JSON APIs: require application/json + custom header; exact CORS allow-list with credentials.
  • Session cookies: explicit SameSite=Lax/Strict, __Host-, Secure, HttpOnly — as depth, never alone.
  • Protect login/logout/registration and bind OAuth (state + PKCE) and SAML flows to the initiating browser.
  • Re-authenticate for crown-jewel actions; localhost services validate Host/Origin.

Tools

  • Burp Suite — “Generate CSRF PoC”; extensions CSRF Scanner, CSurfer, Auto CSRF, CSRF PoC Creator. See Burp Suite.
  • EasyCSRF (Burp) — strips CSRF headers/params (urlencoded, multipart, JSON), converts PUT/DELETE/PATCH → POST, urlencoded → JSON; good for APIs and GraphQL.
  • XSRFProbe — crawler + token-strength analysis + PoC generation.
  • Bolt — crawling CSRF scanner.

Sub-pages

See also: CORS Misconfiguration

Sources