Insufficient Type Check on GraphQL leading to Maintainer delete repository
The GraphQL destroySnippet mutation did not verify that the object ID referred to a snippet, so a maintainer could pass a DiffNote ID. The mutation then used the DiffNote's repository, which is the project repository, and deleted it.
Originally disclosed on HackerOne
- Triaged in 6 hours
- Fixed in 4 months
- Paid in 6 hours
- Disclosed after 6 months
Summary
As you have know, Maintainer cannot delete/archive repository. But via GraphQL, they can do as there exists an sufficient check on GraphQL API
app/graphql/mutations/snippets/destroy.rb
def resolve(id:)
snippet = authorized_find!(id: id)
response = ::Snippets::DestroyService.new(current_user, snippet).execute
The function authorized_find lead to object_from_id!
app/graphql/mutations/snippets/base.rb
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
Here there is no check for whether the Object returned from find_object is a Snippet. I could specify any object which the user have permission of
"#{ability_name}_#{snippet.to_ability_name}".to_sym to.
For example: A DiffNote that is created by a Maintainer in the Project as the function.
If I have such a ID:
mutation test{
destroySnippet(input: {id: "gid://gitlab/DiffNote/116"}){
errors
}
}
It refer to an DiffNote with id 116
Perfectly, a Maintainer have an admin_note and admin_snippet on a DiffNote (!!!)
In the mutation Destroy the call to ::Snippets::DestroyService.new(current_user, snippet) but the Object of snippet is actually a DiffNote
app/services/snippets/destroy_service.rb
def attempt_destroy!
result = Repositories::DestroyService.new(snippet.repository).execute
raise DestroyError if result[:status] == :error
snippet.destroy!
end
and in
app/models/diff_note.rb
def repository
noteable.respond_to?(:repository) ? noteable.repository : project.repository
end
It return the project.repository which in turn the Project that the DestroyService gonna delete
Steps to reproduce
- Create 2 User: User A, User B
- User A create a project set User B as Maintainer.
F802288 3. User B create 2 branch with the same file but different content
F802287 F802289 4. Create a merge request for those 2 Branch
F802290 5. Create a diff note for the file by clicking at the comment on a line of the file then Submit it
F802291 6. To know the ID of diff note, delete this one, the ID will show up in burp then you will know the ID of the next one
F802292
7. Use the /-/graphiql-explorer to execute the following the query
mutation test{
destroySnippet(input: {id: "gid://gitlab/DiffNote/118"}){
errors
}
}
F802293 8. Enjoy no repository
F802294
9. If you click on Create empty repository It will actually make the Project 404 but It still show up on the User's project feed
F802295 F802296
Impact
Unauthorized deleting of repository/project by maintainers
Output of checks
This bug happens on GitLab.com
Impact
Unauthorized deleting of repository/project by maintainers
Attachments










Context
GitLab exposes a GraphQL API alongside its REST API, and the web UI ships a GraphQL explorer at /-/graphiql-explorer that lets an authenticated user run arbitrary queries and mutations against gitlab.com. Among the mutations is destroySnippet, which is meant to delete a snippet. In the normal permission model, a Maintainer of a project cannot delete or archive the project's repository; that action is reserved for higher roles. The report shows that the GraphQL mutation path did not check the type of the object it was handed.
The weakness is classified as improper access control (generic), severity high, and the report was disclosed on 2 November 2020 with a bounty of 4,000 USD.
Setup
Two accounts are enough:
- User A, who creates a project and sets User B as Maintainer.
- User B, the Maintainer, who performs the attack.
The only tooling mentioned is Burp, used to observe the ID of a diff note, and the built-in /-/graphiql-explorer page to send the mutation. The bug happens on GitLab.com.
Finding it
The researcher started from a known rule: a Maintainer cannot delete or archive a repository. Reading the GraphQL mutation for destroying snippets, the suspicion was that the check on the GraphQL side was insufficient.
The destroy mutation resolves the object like this:
def resolve(id:)
snippet = authorized_find!(id: id)
response = ::Snippets::DestroyService.new(current_user, snippet).execute
authorized_find leads to object_from_id:
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
The gap: nothing checks that the object returned by find_object is actually a Snippet. The ability name is built dynamically from the object's own to_ability_name, so any object the user has the corresponding permission on will pass authorized_resource?. The researcher's example is a DiffNote: a Maintainer holds admin_note and admin_snippet on a DiffNote, so the authorisation check succeeds even though the object is not a snippet.
Exploitation
Step 1: create the two users and the project
Create User A and User B. User A creates a project and sets User B as Maintainer.

Step 2: create two branches with the same file
User B creates two branches containing the same file with different content.


Step 3: open a merge request
Create a merge request for those two branches.

Step 4: add a diff note
Create a diff note on the file by clicking the comment control on a line of the file and submitting it.

Step 5: learn the diff note ID
To find the ID of a diff note, delete one; the ID shows up in Burp, and from there the ID of the next one is known.

Step 6: send the mutation
Use /-/graphiql-explorer to execute the following mutation, with the ID of a DiffNote:
mutation test{
destroySnippet(input: {id: "gid://gitlab/DiffNote/118"}){
errors
}
}
The global ID is a DiffNote, not a snippet. The mutation resolves it, the dynamic ability check passes because the Maintainer has the note permissions, and the destroy service is invoked with a DiffNote where a snippet is expected.

Step 7: the repository is gone
After the mutation, the project has no repository.

Step 8: the project becomes a 404
Clicking Create empty repository makes the project return 404, although it still appears in the user's project feed.


Root cause
The destroy service assumes it is operating on a snippet:
def attempt_destroy!
result = Repositories::DestroyService.new(snippet.repository).execute
raise DestroyError if result[:status] == :error
snippet.destroy!
end
and DiffNote supplies a repository of its own:
def repository
noteable.respond_to?(:repository) ? noteable.repository : project.repository
end
For a diff note, that returns the project repository, which is exactly what Repositories::DestroyService then deletes. The type confusion is the whole bug: the mutation authorises against a dynamically derived ability name on whatever object the ID points to, without confirming the object class, and the downstream service trusts the object's repository method. The existing role check on repository deletion is bypassed because the deletion happens through the snippet destroy path rather than the project path.
Impact
A Maintainer, who is not permitted to delete or archive a repository, can delete the repository of a project through this mutation. The report describes this as unauthorised deleting of repository/project by maintainers. The project then returns 404 while still being listed in the user's project feed.
Fix
The report does not describe the fix that was applied.
Variants to test
- Other GraphQL mutations that call
authorized_find!orobject_from_idand then pass the result to a service expecting a specific class: try a global ID of a different type the current user has some admin ability on, and see whether the mutation proceeds. - Mutations whose ability name is built dynamically from
to_ability_name: check whether a type with a permissive ability (for example note administration) can stand in for the intended type. - Services that call a method such as
repositoryon their argument: check whether other object types expose the same method and return a more sensitive resource. - A positive result is a mutation that succeeds with a global ID of the wrong type and produces an effect on a resource the caller should not be able to modify.
Hunting notes
This kind of bug hides where a generic resolver feeds a type-specific service: GraphQL mutations, polymorphic IDs, and any code that builds permission names from object metadata. During recon, look for mutations that accept a global ID and for authorisation helpers that derive the ability from the object rather than from a fixed constant. The researcher demonstrated impact by walking the full chain from a Maintainer account to a deleted repository and showing the resulting 404.
What happened, in plain words
GitLab is a website where teams keep and share code. Each project on GitLab has a repository, which is the storage area holding all the files and their history. GitLab has rules about who can do what inside a project. One of those rules says that a person with the Maintainer role is not allowed to delete or archive the project's repository. Only people with higher roles can do that.
The researcher found that this rule could be broken through a different door. GitLab offers an API, which is a way for programs (or a special web page) to talk to GitLab and ask it to do things, without clicking through the normal screens. One of the things the API can do is delete a snippet, which is a small piece of saved text or code, unrelated to the project repository. The code behind that delete action checked the permission, but it never checked that the thing being deleted was actually a snippet. It checked the permission, but it never checked that the thing being deleted was actually a snippet. A Maintainer could therefore point the delete-snippet action at a different kind of object, a diff note (a comment left on a line of a file in a merge request), and the permission check would still pass. The delete action then went on to delete the project's repository, which the Maintainer was never allowed to do.
The weakness is filed as improper access control (generic), with high severity. The report was disclosed on 2 November 2020 and the bounty was 4,000 USD.
The pieces you need to know
Before following the steps, here are the ideas the report relies on, explained from scratch.
- GraphQL: a way for a client to ask a server for exactly the data or action it wants, using a small query language. Think of a restaurant menu where you write down precisely which dishes you want and how they should be prepared, instead of ordering a fixed set meal. GitLab offers GraphQL next to its older REST API (where each action has its own fixed address).
- Mutation: in GraphQL, a request that changes something on the server (create, update, delete), as opposed to a query that only reads. The mutation in this report is called
destroySnippetand is meant to delete a snippet. - GraphQL explorer: a page built into GitLab at
/-/graphiql-explorerwhere a logged-in user can type GraphQL requests and run them againstgitlab.com. It is like a test kitchen where you can write your own order and send it straight to the chef. - Global ID: a string that uniquely identifies one object on the whole site, in the form
gid://gitlab/Type/number. TheTypepart says what kind of object it is (for exampleDiffNote), and the number is that object's ID. Think of a parcel label that says both what is inside the box and its tracking number. - Diff note: a comment attached to a specific line of a file inside a merge request. A merge request is a proposal to combine changes from one branch into another, and a branch is a separate line of work holding its own copy of the files.
- Maintainer: a role in a GitLab project with a lot of power (managing members, settings, code) but, per the report, not the power to delete or archive the repository.
- Burp: a tool that sits between your browser and the website and lets you see and edit the requests going back and forth. The researcher used it only to observe an ID.
- 404: the standard web response meaning "not found". A page that returns 404 is effectively invisible to normal browsing.
- Type confusion: the general name for this class of bug. A program is handed an object of one kind while it believes, and acts as if, the object is of another kind. It is like a form that asks for a passport but accepts a library card because nobody checks the document type, only that the person holding it is a member.
Setting up the scene
The report needs only two accounts:
- User A, who creates a project and makes User B a Maintainer of it.
- User B, the Maintainer, who carries out the attack.
The only tools mentioned are Burp, to see the ID of a diff note, and the built-in /-/graphiql-explorer page, to send the mutation. The bug happens on GitLab.com.
How the researcher found it
The starting point was a rule the researcher already knew: a Maintainer cannot delete or archive a repository. Reading the code behind the GraphQL mutation that destroys snippets, the suspicion was that the check on the GraphQL side was not strict enough.
The mutation finds the object to delete like this:
def resolve(id:)
snippet = authorized_find!(id: id)
response = ::Snippets::DestroyService.new(current_user, snippet).execute
Line by line:
def resolve(id:)declares the function that runs when the mutation is called. It receives one input,id, the global ID of the object to delete.snippet = authorized_find!(id: id)looks up the object with that ID and checks that the current user is allowed to act on it. The result is stored in a variable namedsnippet, which already shows the assumption: whatever comes back is treated as a snippet.response = ::Snippets::DestroyService.new(current_user, snippet).executehands the current user and that object to the snippet destroy service and runs it. The service is the part of the code that actually performs the deletion.
authorized_find leads to object_from_id:
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
Line by line:
def find_object(id:)declares the lookup function.GitlabSchema.object_from_id(id)turns the global ID string into the actual object it points to. Whatever type the ID names, that is the type you get back.def authorized_resource?(snippet)declares the permission check. Again the parameter is calledsnippet, but nothing enforces that.Ability.allowed?(context[:current_user], ability_for(snippet), snippet)asks the permission system whether the logged-in user has the ability returned byability_foron the object.def ability_for(snippet)declares the function that builds the ability name."#{ability_name}_#{snippet.to_ability_name}".to_symbuilds the ability name by gluing together a fixed prefix and the object's ownto_ability_name. The object itself decides half of the permission name that will be checked against it.
The gap: nothing checks that the object returned by find_object is actually a snippet. Because the ability name is built from the object's own to_ability_name, any object the user has the matching permission on will pass authorized_resource?. The researcher's example is a DiffNote. A Maintainer holds admin_note and admin_snippet on a diff note, so the authorisation check succeeds even though the object is not a snippet at all.
Carrying out the attack
Step 1: create the two users and the project
Create User A and User B. User A creates a project and sets User B as Maintainer. This sets up the exact situation the rule is meant to cover: a Maintainer who should not be able to delete the repository.

Step 2: create two branches with the same file
User B creates two branches containing the same file with different content. Two versions of one file are needed so that there is something to compare, which is what a merge request shows.


Step 3: open a merge request
Create a merge request for those two branches. The merge request is the page where GitLab displays the differences between the branches, line by line.

Step 4: add a diff note
Create a diff note on the file by clicking the comment control on a line of the file and submitting it. This produces the object the attack will borrow: a comment that the Maintainer is genuinely allowed to administer.

Step 5: learn the diff note ID
To find the ID of a diff note, delete one. The ID shows up in Burp, and from there the ID of the next one is known. The reason for this detour is simple: the attack needs the numeric ID of a diff note, and the report's way of learning it is to watch the request that deletes a note and read the ID from it.

Step 6: send the mutation
Use /-/graphiql-explorer to run the following mutation, with the ID of a DiffNote:
mutation test{
destroySnippet(input: {id: "gid://gitlab/DiffNote/118"}){
errors
}
}
Line by line:
mutation test{starts a mutation namedtest. The name is just a label for the request.destroySnippet(input: {id: "gid://gitlab/DiffNote/118"}){calls the delete-snippet mutation and passes it one input, the global ID. The ID says the object is aDiffNotewith number 118, not a snippet. This is the heart of the trick: the action meant for snippets is pointed at a comment.errorsasks GitLab to return any errors the mutation produced, so the researcher can see whether it worked.- The closing braces end the selection and the mutation.
The global ID is a DiffNote, not a snippet. The mutation resolves it, the dynamic ability check passes because the Maintainer has the note permissions, and the destroy service is invoked with a DiffNote where a snippet is expected.

Step 7: the repository is gone
After the mutation, the project has no repository.

Step 8: the project becomes a 404
Clicking Create empty repository makes the project return 404, although it still appears in the user's project feed. In other words, the project page can no longer be reached normally, but the project is still listed among the user's projects.


Why it worked
The destroy service assumes it is working on a snippet:
def attempt_destroy!
result = Repositories::DestroyService.new(snippet.repository).execute
raise DestroyError if result[:status] == :error
snippet.destroy!
end
Line by line:
def attempt_destroy!declares the function that performs the deletion.result = Repositories::DestroyService.new(snippet.repository).executeasks the object for itsrepositoryand passes that repository to the service that deletes repositories, then runs it. The code never asks what kind of object it is holding; it just callsrepositoryon it.raise DestroyError if result[:status] == :errorstops with an error if the deletion reported a failure.snippet.destroy!then deletes the object itself.
And DiffNote supplies a repository of its own:
def repository
noteable.respond_to?(:repository) ? noteable.repository : project.repository
end
Line by line:
def repositorydeclares a method that answers the question "which repository do you belong to?".noteable.respond_to?(:repository) ? noteable.repository : project.repositorychecks whether the thing the note is attached to has a repository. If it does, return that one; if not, return the project's repository.
For a diff note, that returns the project repository, which is exactly what Repositories::DestroyService then deletes. The type confusion is the whole bug: the mutation authorises against a dynamically derived ability name on whatever object the ID points to, without confirming the object class, and the downstream service trusts the object's repository method. The existing role check on repository deletion is bypassed because the deletion happens through the snippet destroy path rather than the project path.
What it means
A Maintainer, who is not permitted to delete or archive a repository, can delete the repository of a project through this mutation. The report describes this as unauthorised deleting of repository/project by maintainers. The project then returns 404 while still being listed in the user's project feed.
The fix
The report does not describe the fix that was applied.
Other places to look
- Other GraphQL mutations that call
authorized_find!orobject_from_idand then pass the result to a service expecting a specific class: try a global ID of a different type the current user has some admin ability on, and see whether the mutation proceeds. - Mutations whose ability name is built dynamically from
to_ability_name: check whether a type with a permissive ability (for example note administration) can stand in for the intended type. - Services that call a method such as
repositoryon their argument: check whether other object types expose the same method and return a more sensitive resource. - A positive result is a mutation that succeeds with a global ID of the wrong type and produces an effect on a resource the caller should not be able to modify.
Notes for hunters
This kind of bug hides where a generic resolver feeds a type-specific service: GraphQL mutations, polymorphic IDs, and any code that builds permission names from object metadata. During recon, look for mutations that accept a global ID and for authorisation helpers that derive the ability from the object rather than from a fixed constant. The researcher demonstrated impact by walking the full chain from a Maintainer account to a deleted repository and showing the resulting 404.
Glossary
- API: a way for programs to talk to a service and ask it to read or change things, without using the normal web pages.
- REST API: an older style of API where each action has its own fixed address.
- GraphQL: a query language and API style where the client writes exactly what it wants, including actions that change data.
- Mutation: a GraphQL request that changes something on the server, such as creating or deleting.
- Query: a GraphQL request that only reads data.
- GraphQL explorer: a page built into GitLab at
/-/graphiql-explorerfor typing and running GraphQL requests while logged in. - Repository: the storage area of a project holding its files and their history.
- Snippet: a small saved piece of text or code, separate from a project repository.
- Branch: a separate line of work holding its own copy of the files.
- Merge request: a proposal to combine changes from one branch into another, shown as a line-by-line comparison.
- Maintainer: a project role with broad management power but, per the report, not the power to delete or archive the repository.
- Global ID: a string of the form
gid://gitlab/Type/numberthat uniquely identifies one object and states its type. - Burp: a tool that sits between browser and website so you can inspect and edit the requests.
- Authorisation: the process of deciding whether a user is allowed to perform an action.
- Access control: the rules that decide who may do what; improper access control means those rules can be bypassed.
- Type confusion: a bug where a program receives an object of one kind but treats it as another kind.
- 404: the web response meaning "not found".
- Bounty: a payment made by a company to a researcher who reports a valid security bug.