How I Found a CSRF via a misconfiguration in graphql
The GraphQL API lacked CSRF tokens for sensitive actions like changing username or phone number, and the session cookie had SameSite=Lax. By abusing Automatic Persisted Queries (APQ) to send mutations via GET requests, an attacker could bypass the Lax restriction and perform state-changing actions on behalf of a victim.
Published on medium.com
I recently found a CSRF on a program on bugcrowd and i’d like to share the whole story so maybe you can learn something from it.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the GraphQL server allowed mutations to be sent via GET requests using Automatic Persisted Queries, and the session cookie was set to SameSite=Lax without additional CSRF protections for certain actions.
Impact
An attacker could change a victim's username, phone number, or basket contents without their consent, but only if the victim visits a malicious page while logged in.
What the attacker needed
Victim is logged in; victim visits attacker's page; GraphQL endpoint accepts GET mutations
The fix
The GraphQL server should reject mutations sent via GET requests and enforce CSRF tokens or SameSite=Strict cookies for state-changing operations.
How it was found
- Notice that GraphQL requests lack CSRF tokens for actions like changing username or phone number.
- Observe that the session cookie has SameSite=Lax, which blocks cross-site POST but allows top-level GET navigations.
- Discover that the GraphQL endpoint supports Automatic Persisted Queries (APQ) and can accept GET requests.
- Construct a GET request with a mutation, variables, and a valid persisted query hash to perform a state-changing action.
- Create an HTML form that auto-submits the GET request to the GraphQL endpoint, changing the victim's fullName and phoneNumber.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A CSRF attack tricks a logged-in user's browser into sending a request to a site where they are authenticated, without their knowledge. Here, the site's cookie had a setting called SameSite=Lax that normally blocks such cross-site POST requests, but the attacker found a way to send the request as a GET instead, which Lax allows for top-level navigation. This let them change the victim's account details.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.