Resend a GraphQL mutation as a form-encoded POST to test for CSRF on cookie-authenticated endpoints
Many GraphQL servers only expect application/json, and developers assume that makes cross-site requests impossible because JSON needs a CORS preflight. But some servers (Apollo with CSRF prevention turned off, graphql-http style handlers, custom middleware) also accept other content types or the GET method, and those need no preflight.
Take a state-changing mutation from your own test account, authenticated by a session cookie, and replay it three ways:
POST /graphql Content-Type: application/x-www-form-urlencoded
query=mutation{updateEmail(email:"a@example.com"){id}}
POST /graphql Content-Type: text/plain
{"query":"mutation{...}"}
GET /graphql?query=mutation{updateEmail(email:"a@example.com"){id}}If any variant returns the normal data object and the change really happens, a plain HTML form or <img> on another origin can trigger it with the victim's cookie. Confirm by sending it from a page on a different origin, with no custom header and no CSRF token. Cookies set SameSite=Lax still send on top-level GET, but not on cross-site POST, so check the flag first.
Not reportable: a 400 or 415 for the odd content type, a mutation rejected over GET with a message about non-query operations, or an endpoint that needs a bearer header you cannot set cross-site. Use only your own test accounts and in-scope targets.
Follow #content-type, #csrf, #graphql or #samesite for new tips like this one, on your notifications page and, if you choose, in a daily or weekly email.
Comments
No comments yet.