GraphQL CSRF

Cross-site request forgery against a cookie-authenticated GraphQL endpoint that will execute operations from browser “simple requests” — GET, application/x-www-form-urlencoded or text/plain POST — or from cross-origin channels it fails to origin-check.

How it works

A JSON POST with Content-Type: application/json triggers a CORS preflight, so it cannot be forged cross-site as long as the server actually enforces the content type. The bug appears when the server is lenient about transport:

  • GET execution — GET /graphql?query=mutation{...}. A top-level navigation carries SameSite=Lax cookies: in one lab a link on evil.test to a GET updateEmail mutation executed with Alice’s Lax session in Chromium.
  • Form-encoded / text POST — an auto-submitting HTML form sending query, operationName and variables as fields; no preflight, cookies attached unless SameSite blocks them.
  • Non-HTTP entry points — postMessage bridges and local dev servers without origin checks.

The GraphQL-over-HTTP draft is explicit: GET MUST NOT execute mutations (respond 4xx), and alternative media types risk “simple request” treatment and CSRF.

Detecting it

BatchQL-style probe — send a trivial query both ways and see whether it is parsed:

GET /graphql?query=query+%7B+a+%7D
POST /graphql   Content-Type: application/x-www-form-urlencoded   query=query+%7B+a+%7D

A response like Cannot query field "a" on type "Query" means the transport is accepted. That is an indicator, not a finding: prove impact with a state-changing mutation on your own test account, check cookie SameSite attributes, and confirm the endpoint authenticates by cookie rather than a bearer header.

Notable cases

  • GitLab CVE-2026-19650 (CVSS 7.1, CWE-352) — improper request validation in GraphQL multiplex query handling allowed mutations via GET; patched with CVE-2026-19478 in 18.11.11 / 19.0.8 / 19.1.6 / 19.2.4.
  • Apollo Studio Embeddable Explorer & Sandbox CVE-2025-59845 — no origin validation on window.postMessage events, so a hostile page could drive the embedded explorer to run arbitrary operations against the victim’s GraphQL server; fixed Sandbox 2.7.2, Explorer 3.7.3.
  • Cypress Launchpad (GHSA-pgrh-36vg-cqj7) — cypress open ran a GraphQL server bound to all interfaces with no origin check; a network peer or a website hitting loopback could set the “preferred editor” to an arbitrary command line → code execution as the developer (Cypress ≥10.0.0; recent Chrome/Edge/Firefox now block or prompt for such loopback requests).
  • Facebook / business.instagram.com — CSRF-style GraphQL call against the “assigned roles and emails” feature.
  • HackerOne Tray.io integration — CSRF linked victims’ third-party apps (GitHub, Jira) to the attacker’s account, then the integration’s GraphQL API reached private repositories.
  • Indeed-style changeEmail form PoC illustrates the form-encoded variant.

Defenses

  • Accept operations only as JSON-encoded POST and validate that the body matches the declared content type.
  • Reject mutations over GET with 4xx (and consider rejecting GET entirely where persisted GET queries aren’t needed).
  • CSRF tokens or a required custom header for cookie-authenticated APIs; SameSite=Lax/Strict as defense in depth — Lax does not cover GET mutations.
  • Validate postMessage origins in embedded IDEs; bind dev-tool GraphQL servers to loopback and check Origin.

Sources