# 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: ```http 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`. ## Related - [[GraphQL Security]] - [[Cross-Site Request Forgery]] - [[JSON CSRF]] - [[SameSite Cookies]] - [[CSRF Token Bypasses]] ## Sources - [[raw/portswigger.net/graphql-api-vulnerabilities-web-security-academy-2745|GraphQL API Vulnerabilities]] - [[raw/blog.assetnote.io/exploiting-graphql-435|Exploiting GraphQL]] - [[raw/fdzdev.medium.com/exploiting-csrf-in-graphql-applications-4180|Exploiting CSRF in GraphQL Applications]] - [[raw/dedsecops.com/confirming-graphql-dast-findings-introspection-batching-depth-cost-csr-14495|Confirming GraphQL DAST findings: introspection, batching, depth/cost, CSRF over GET]] - [[raw/ox.security/critical-and-high-severity-graphql-cves-in-gitlab-code-injection-and-c-11524|Critical and High-Severity GraphQL CVEs in GitLab: Code Injection and CSRF via One Directive]] - [[raw/securityaffairs.com/gitlab-patches-critical-unauthenticated-graphql-vulnerability-11475|GitLab Patches Critical Unauthenticated GraphQL Vulnerability]] - [[raw/helpnetsecurity.com/critical-gitlab-flaw-allows-attackers-to-modify-or-delete-public-proje-11470|Critical GitLab flaw allows attackers to modify or delete public projects]] - [[raw/ameeba.com/cve-2025-59845-csrf-vulnerability-in-apollo-studio-embeddable-explorer-4760|CVE-2025-59845: CSRF Vulnerability in Apollo Studio Embeddable Explorer and Sandbox]] - [[raw/github.com/cypress-launchpad-graphql-server-exposed-to-cross-site-requests-allows-15487|Cypress Launchpad GraphQL server exposed to cross-site requests allows command execution]] - [[raw/philippeharewood.com/facebook-graphql-csrf-these-aren-t-the-access-tokens-you-re-looking-fo-438|Facebook GraphQL CSRF – These aren't the access_tokens you're looking for]] - [[raw/medmahmoudi.com/csrf-in-hackerone-tray-io-integration-12611|CSRF in HackerOne Tray.io integration]] - [[raw/github.com/batchql-graphql-security-auditing-for-batch-attacks-4178|BatchQL: GraphQL Security Auditing for Batch Attacks]] - [[raw/book.hacktricks.xyz/graphql-hacktricks-2814|GraphQL]]