Skip to content
Access control Disclosed report Intermediate

Granting access to deploy keys to protected tags/branches also gives access to their owners - allowing them to disclose protected variables

A user who created a deploy key retains the ability to push to protected branches or create protected tags even after being demoted, because granting access to the deploy key also grants access to its owner. This allows a demoted developer to exfiltrate protected CI variables or modify code without oversight.

GitLab

Originally disclosed on GitLab

  • Fixed in 57 days
  • Disclosed after 57 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 #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).

<details><summary>Click to expand original H1 report</summary>

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:

  1. Create a new project, having the following content in .gitlab-ci.yml
build:  
  script:  
    - echo "$VAR"  
  1. Create a protected variable in that project, let's call it VAR, Project Settings => CI/CD => variables
image.png
image.png From the original on GitLab
  1. Invite a maintainer to the project

As the maintainer:

  1. Generate a new SSH key, using ssh-keygen -t rsa -b 2048 and accepting all prompts
  2. Navigate to .ssh/id_rsa.pub and grab the public key
  3. 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:

  1. Demote the maintainer to a developer
  2. Add tags protection for the tags v* and only allow maintainers to create them, Project Settings => Repository => Protected tags
image.png
image.png From the original on GitLab

As the developer(which was a maintainer):

  1. Verify that you can't create v1.0 tag on https://gitlab.com/OWNER/PROJECT/-/tags

As the owner:

  1. Add the deploy token added in step 6 to the "Allowed to create" in tags protection

As the developer:

  1. verify that you can create a v1.0 tag
  2. 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
bandicam_2023-08-05_22-05-46-061.mp4 From the original on GitLab
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!

</details>

How To Reproduce

See https://gitlab.com/gitlab-org/gitlab/-/issues/421984#note_1513203526

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

Impact

A developer who was once a maintainer and created a deploy key can push to protected branches or create protected tags, potentially exfiltrating protected CI variables or modifying code without oversight; the impact is considered low because the attacker had those abilities in the past.

What the attacker needed

Attacker was a maintainer and created a deploy key; deploy key granted access to protected branch/tag; attacker demoted to developer

How it was found

  1. As an owner, create a project with a CI job that echoes a protected variable.
  2. Create a protected variable named VAR in the project settings.
  3. Invite a maintainer to the project.
  4. As the maintainer, generate an SSH key pair and add the public key as a deploy key with write permissions.
  5. As the owner, demote the maintainer to developer and protect tags v* to only allow maintainers to create them.
  6. As the developer, verify you cannot create a v1.0 tag, then as owner add the deploy key to allowed to create, and as developer create the tag and see the protected variable in pipeline logs.

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 is a special SSH key that lets a system or user push code to a repository. Protected branches and tags are rules that restrict who can change important parts of the code. The bug is that if you give a deploy key permission to push to a protected branch, the person who created that key also gets that permission, even if they have been demoted to a lower role. So a developer who used to be a maintainer can still push to protected branches and see secret variables.

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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.