# Insufficient Type Check on GraphQL leading to Maintainer delete repository

GraphQL destroySnippet mutation lacked a type check, letting a Maintainer pass a DiffNote GID and delete the entire project repository.

- Payout: $4,000
- Severity: high
- Program: GitLab
- Found by: ledz1996
- Disclosed: 2020-11-02
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/858671
- Library page: https://bugbountylibrary.com/r/h1%3A858671
- Tags: area:web domain:api domain:web impact:data-leak impact:integrity kind:bounty platform:hackerone sev:high tech:graphql technique:chained technique:source-review vuln:access-control

**Target:** GitLab GraphQL destroySnippet mutation
**Root cause:** authorized_find!/object_from_id! resolves any GlobalID without verifying the object is a Snippet; ability check uses the resolved object's own ability name, so a DiffNote passes admin_note and is then fed to Snippets::DestroyService.
**Steps:**
1. Create project, add User B as Maintainer.
2. Create two branches with differing file content and open a merge request.
3. Add a diff note on a line; capture its DiffNote GID (e.g. gid://gitlab/DiffNote/118).
4. Run `mutation test{ destroySnippet(input: {id: "gid://gitlab/DiffNote/118"}){ errors } }` via /-/graphiql-explorer.
5. Snippets::DestroyService calls snippet.repository on the DiffNote, which returns project.repository, deleting the repo.
**How found:** Code reading of the GraphQL mutation: noticed authorized_find! delegates to object_from_id! with no type check, and ability_for derives the permission from the resolved object's own ability name, so any object the user can administer satisfies the check.
**Exploitation:** Maintainer submits a GraphQL destroySnippet mutation with a DiffNote GlobalID instead of a Snippet ID; the service resolves DiffNote#repository to project.repository and Repositories::DestroyService wipes the project repository.
**Insight:** In GraphQL APIs using GlobalID, test mutations by swapping the expected object type for another type the user has any admin ability on; the ability check often keys off the resolved object rather than the mutation's intended type.

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

**Vulnerable authorized_find without type check**

```
def find_object(id:)
        GitlabSchema.object_from_id(id)
      end

      def authorized_resource?(snippet)
        Ability.allowed?(context[:current_user], ability_for(snippet), snippet)
      end

      def ability_for(snippet)
        "#{ability_name}_#{snippet.to_ability_name}".to_sym
      end
```

**DestroyService deletes DiffNote's project repository**

```
def attempt_destroy!
      result = Repositories::DestroyService.new(snippet.repository).execute

      raise DestroyError if result[:status] == :error

      snippet.destroy!
    end
```

