Skip to content
Access control Disclosed report Intermediate

An attacker is able to commit to tags with the same name as protected branches, and in many areas GitLab treats the tag as a branch (ambiguous git ref)

GitLab blocked tags with the same name as the default branch but still allowed tags matching other protected branches. A developer could push such a tag and then delete the branch, causing GitLab to treat the tag as the branch and show attacker-controlled content.

GitLab

Originally disclosed on GitLab

  • Fixed in 11 months
  • Disclosed after 11 months

⚠️ 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 #1947917 by js_noob on 2023-04-14, assigned to @greg:

Report | Attachments | How To Reproduce

Report

Summary

Hello team, this is a report to bypass the fix that was introduced in this issue. The fix was introduced to block any attacker from creating tags having the name of the default branch, however, an attacker can still create tags having the name of any protected branch.

Steps to reproduce

As an owner:

  1. Create a new project
  2. Create a new branch called protected
  3. Protect that branch and don't allow anyone to push changes to it (Settings => Repository => Protected branches)
image.png
image.png From the original on GitLab
  1. Add a developer to that project

As the developer:

  1. Clone the project locally
git clone https:...    
  1. Checkout the protected branch
git fetch origin protected  
git checkout protected  
  1. Create a new branch with the name new-feature
git checkout -b 'new-feature'    
  1. Edit any changes to any file
  2. Commit and push the new-feature branch
git add .    
git commit -m 'new-feature'    
git push origin HEAD    
  1. Grab the hash of the final commit using the following command
git rev-parse HEAD  
  1. Switch back to the protected branch
git checkout protected  
  1. Create a tag with the name of protected pointing to the latest commit of the new-feature branch
git tag protected HASH_FROM_STEP_10  
  1. Push the tags to the remote
git push origin --tags    
  1. Remove the new-feature branch from the remote
git push -d origin 'new-feature'    

As the owner:

  1. From the UI navigate to https://gitlab.com/GROUP/PROJECT/-/tree/protected, and verify the changes
Video/POC
bandicam_2023-04-14_22-48-35-879.mp4 From the original on GitLab

Impact

An attacker is able to change the content of any non-default protected branch file by pushing a tag with the protected branch name.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

How To Reproduce

Please add reproducibility information to this section:

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

Root cause

Likely the fix only checked the default branch name and did not account for other protected branches, so GitLab's ambiguous ref handling let a tag shadow a branch.

Impact

An attacker could change the content shown for any non-default protected branch by pushing a tag with that branch name.

What the attacker needed

A GitLab account with developer role; a protected non-default branch exists

How it was found

  1. As owner, create a project and a branch called protected, then protect it.
  2. Add a developer to the project.
  3. As developer, clone the project and check out the protected branch.
  4. Create a new branch, make a change, commit, and push it.
  5. Create a tag with the protected branch name pointing to the new commit, push tags, and delete the new branch.
  6. As owner, visit the tree URL for the protected branch and see the changed content.

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 Git, a branch and a tag are different things, but both are just names pointing to a commit. GitLab tried to stop people from making a tag with the same name as the main branch, but forgot other protected branches. So a user could make a tag named like a protected branch, delete the real branch, and GitLab would show the tag's content as if it were the branch.

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.