Every user can delete public deploy keys
A normal user could delete a public deploy key shared across projects by sending a DELETE request to the project's deploy keys API endpoint. This would stop other users from deploying code using that key.
- Triaged in under an hour
- Fixed in 22 days
- Disclosed after 22 days
Vulnerability details
A GitLab instance can have public deploy keys that project admins can use for their project. An attacker can delete these public keys used by other users to deploy code.
Impact
Deleting these shared deploy keys may stop users to deploy their code.
Proof of concept
Make sure the GitLab instance has a public deploy key. Lets assume it has ID 1. Now sign in as a normal user and follow the steps below.
- Create a new project called
test - Go to http://gitlab-instance/user/test/deploy_keys
- Go to the
Public deploy keys available to any projectsection and click theEnablebutton for the public deploy key - Create an access token for the API for your own account
- Request
/api/v3/projects, get the ID number for the projecttest - Request
/api/v3/projects/:project_id/deploy_keys, you'll see the public deploy key - Send a
DELETErequest to `/api/v3/projects/:project_id/deploy_keys/:id - this will delete the public (shared) deploy key, not the relationship between the project and the key. Below is a copy of the request and response.
Request
curl -X DELETE -H "Private-Token: AAAA" http://gitlab-instance/api/v3/projects/1/deploy_keys/1
Response
{"id":1,"user_id":null,"created_at":"<removed>","updated_at":"<removed>","key":"<key>","title":"<title>","fingerprint":"72:bb:e9:cc:04:dc:64:b9:a3:e7:c2:26:8f:f2:ed:df","public":true}
The root cause of this problem lies in the following lines of code:
lib/api/deploy_keys.rb
delete ":id/#{path}/:key_id" do
key = user_project.deploy_keys.find(params[:key_id])
key.destroy
end
The destroy method will be called on the shared deploy key instead of on the relationship.
Remediation advice
Instead of removing the entire object, remove the relationship instead when it's a public deploy key.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The API endpoint called destroy on the shared deploy key object itself instead of removing only the link between the project and the key.
Impact
Deleting shared deploy keys could stop users from deploying their code.
What the attacker needed
A normal user account; a public deploy key exists; API access token
The fix
The endpoint should remove only the relationship between the project and a public deploy key, not the key itself.
How it was found
- Create a new project called test.
- Go to the project's deploy keys page.
- Enable the public deploy key for the project.
- Create an API access token for your own account.
- Find the project ID via the API.
- Send a DELETE request to the project's deploy keys endpoint for that key.
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 report has not been written yet. The Original tab links to the source.
A deploy key lets a project deploy code. Public deploy keys are shared across projects. The bug let any logged-in user delete such a shared key, which could stop others deploying.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.