Demoted member continues having read and write access to projects using his deploy key which victim is unaware of
A demoted GitLab member's deploy key remains enabled and grants read/write access to a project, but the API endpoint that lists a user's deploy keys returns no results for demoted users, so the project owner is unaware of the key. An attacker can therefore retain access after being demoted.
GitLab
Originally disclosed on GitLab
- Fixed in 21 days
- Disclosed after 21 days
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #2038990 by theluci on 2023-06-26, assigned to @greg:
Report | Attachments | How To Reproduce
Report
Hello,
Background
Gitlab provides a feature to set up Deploy Keys.
Only the maintainers/owner of a project can create or view project’s deploy keys.
There is no option to see the owner/creator of the deploy key through the UI, however, Gitlab provides the following API endpoint to List the project deploy keys for a specific user,
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/users/id_or_username/project_deploy_keys"
Where, id_or_username is the ID or username of the user to get the project deploy keys for.
Vulnerability
According to the docs, this API endpoint is used to list project deploy keys for a specific user.
The doc states,
It lists only the enabled project keys from the common projects of requester and requestee.
It can be seen that the API endpoint was supposed to list the project deploy keys that a specific user (requestee) has in the current project by looking at the common projects between the requester and requestee.
However, the above endpoint does not return any result if the requestee is demoted.
That is, if victim has a project victim-project where attacker is one of the maintainers and had set up his deploy key.
Then, after attacker is demoted (maybe to a guest role) and victim runs the following command,
curl --header "PRIVATE-TOKEN: <victim_access_token>" "https://gitlab.com/api/v4/users/attacker_username/project_deploy_keys"
<----------------------------------------------------Important---------------------------------------------------->
No results are returned leading victim to believe that attacker does not have any enabled deploy keys.
This is contradictory to documentation as attacker is still a member of victim-project and has an enabled deploy key which should’ve been returned by looking at the common projects of requester and requestee.
attacker can now continue having read and write access to victim-project using his deploy key which victim is unaware of.
<------------------------------------------------------------------------------------------------------------------>
Steps to reproduce
victimcreates a groupvictim-groupand a projectvictim-projectinside.victimgoes tohttps://gitlab.com/<victim-group>/<victim-project>/-/settings/repository, Expand Deploy keys and adds a few deploy keys.
In a real-world scenario, there will already be a few keys added to the project.
-
victimgoes tovictim-groupmembership pagehttps://gitlab.com/groups/<victim-group>/-/group_membersand addsattackeras maintainer. -
attackervisitshttps://gitlab.com/<victim-group>/<victim-project>/-/settings/repository, Expand Deploy keys and adds a trustworthy looking deploy key such asCI_SERVER_FALLBACK_KEY. (Be sure to grant write permissions as well.) -
victimgoes tovictim-groupmembership pagehttps://gitlab.com/groups/<victim-group>/-/group_membersand demotesattackeras guest. -
victimruns the following command to make sureattackerdoesn’t have an enabled deploy key,
curl --header "PRIVATE-TOKEN: <victim_access_token>" "https://gitlab.com/api/v4/users/attacker_username/project_deploy_keys"
No results are returned leading victim to believe that attacker does not have any enabled deploy keys.

attackercan now continue having read and write access tovictim-projectusing his deploy key.
attacker goes to his terminal and runs the following commands,
git clone [email protected]:<victim-group>/<victim-project>.git
cd victim-project
git init
git checkout -b other
echo “Some text” > Sample.txt
git add .
git commit -m "my commit"
git push origin other
POC
Output of checks
This bug happens on GitLab.com (Probably on instance too).
Impact
A demoted member can continue having read and write access to projects using his deploy key which victim is unaware of.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
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
Likely the API endpoint that lists a user's deploy keys only considers common projects where the user has a certain role, and demotion removes that role, so the endpoint fails to return keys that are still enabled.
What the attacker needed
Victim creates group and project; attacker is added as maintainer; attacker adds a deploy key with write access; victim demotes attacker to guest
How it was found
- Victim creates a group and project and adds deploy keys.
- Victim adds attacker as maintainer.
- Attacker adds a deploy key with write permissions.
- Victim demotes attacker to guest.
- Victim runs the API to list attacker's deploy keys and gets no results.
- Attacker uses the deploy key to clone and push to the project.
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.
In GitLab, a deploy key lets someone read or write to a project's code. The report shows that when a user is demoted, their deploy key still works, but the tool that lists deploy keys for that user shows nothing, so the project owner thinks the key is gone. A demoted user can still change code.
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.