Granting access to deploy keys to protected tags/branches also gives access to their owners - allowing them to disclose protected variables
HackerOne report #2097737 by js_noob on 2023-08-05, assigned to @nmalcolm:
Report | Attachments | How To Reproduce
Report
Summary
A user maintains the ability to write to protected branches if a Deploy Key they created has access.
For example, a user is a Maintainer and adds a Deploy Key, and adds that Deploy Key to the allowed to push to main list. That user is demoted to a Developer. The user still has the ability to write to main directly, even though they're only a Developer.
Impact
A developer with the ability to push to a protected branch can:
- Exfiltrate protected CI variables
- Modify code without oversight
However, because the precondition of this attack is that the Developer was once a Maintainer who created a Deploy Key, we treat the impact as constrained to Low. They had the ability to read protected CI vars in the past, and they had the ability to write to main in the past.
In the above screenshot you can see that the project is configured with a Deploy Key which is Allowed to push and merge (left) and which is owned by a user who now has Max Role Developer (bottom right). The developer has turned malicious and updated .gitlab-ci.yml by committing directly to main without review (top right).
Click to expand original H1 report
Hello team, according to the deploy keys documentation, a deploy key can't push to protected branches unless its owner has access to that protected branch, this also applies to protected tags. However, there's some broken logic in the protected tags "allowed to create logic", if an owner gives access to create a protected tag to a deploy key, the owner of that key automatically gets access to that protected tag as well, knowing that that owner can be a developer (i.e. less than a maintainer) allowing him to disclose protected variables.
This bug happens on both protected tags and protected branches, but for simplicity, I'll be doing a protected tag scenario.
Steps to reproduce
As an owner:
- Create a new project, having the following content in
.gitlab-ci.yml
build:
script:
- echo "$VAR" - Create a protected variable in that project, let's call it
VAR, Project Settings => CI/CD => variables
- Invite a maintainer to the project
As the maintainer:
- Generate a new SSH key, using
ssh-keygen -t rsa -b 2048and accepting all prompts - Navigate to
.ssh/id_rsa.puband grab the public key - Navigate to Project Settings => Repository => Deploy keys and add a deploy key, make sure you check
Grant write permissions to this key
As the owner:
- Demote the maintainer to a developer
- Add tags protection for the tags
v*and only allow maintainers to create them, Project Settings => Repository => Protected tags
As the developer(which was a maintainer):
- Verify that you can't create
v1.0tag on https://gitlab.com/OWNER/PROJECT/-/tags
As the owner:
- Add the deploy token added in step 6 to the "Allowed to create" in tags protection
As the developer:
- verify that you can create a
v1.0tag - Navigate to the pipeline logs and verify that the protected var, created in step 2 is disclosed
Just noting something, this doesn't require user interaction, as step 8 can be easily done by the maintainer before being demoted, the above is just a sample scenario.
POC Video
What is the current bug behavior?
Granting access to the deploy key gives access to the owner.
What is the expected correct behavior?
Granting access to the deploy key shouldn't give access to the owner.
Output of checks
This bug happens on GitLab.com
Impact
Developers can disclose protected variables of a project/group.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!


