Skip to content
Access control Disclosed report Intermediate

Spoofing of the contents of a protected branch by creating a tag with the same name as the protected branch

A developer could create a tag with the same name as a protected branch, causing the GitLab UI and git checkout to show the tag's contents instead of the protected branch's. This allowed spoofing of the protected branch's contents to other users.

GitLab

Originally disclosed on GitLab

  • Fixed in 25 hours
  • Disclosed after 25 hours

⚠️ 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 #2121310 by ricardobrito on 2023-08-23, assigned to GitLab Team:

Report | Attachments | How To Reproduce

Report

Hi team,

Summary

I have found that it is possible for a user with developer role to spoof the contents of a protected branch by creating a tag with the same name as the protected branch.

Pre-requisites
  1. An instance admin account.
  2. A normal user - User A
  3. A normal user - User B
  4. Create an access token for user A
  5. Create an access token for user B
Steps to reproduce
  1. As the instance admin, create a private group called admin-group

  2. As the instance admin, create a project (private) called admin-project inside the group created in step 1.

  3. As the instance admin (now group owner), invite User A and User B as developers.

  4. As the group owner, create a file called .gitlab-ci.yml inside the project with the following content:

YAML
build-job:  
  stage: build  
  script:  
    - echo "Hello, ADMIN"  
  1. As the group owner, edit the .gitlab-ci.yml file using the gitlab ide:
image.png
image.png From the original on GitLab

change the contents to:

YAML
build-job:  
  stage: build  
  script:  
    - echo "Hello, ADMIN FROM BRANCH"  

Commit the changes to a new branch called devel

  1. Still as the owner, go to the repository settings -> expand the Protected branches section, select the devel branch and set the following rules:

Allowed to merge: maintainrers
Allowed to push and merge: maintainrers

Press the protect button

  1. As user A, clone the project using the gitlab token, with the following command:

git clone http://USER-A:glpat-_USER-A-TOKEN@YOUR-GITLAB-INSTANCE/admin-group/admin-project

Then run the following commands:

cd admin-project
git checkout origin/devel -b devel_tag

  1. Still as User A, edit the file .gitlab-ci.yml with the following contents (locally):
YAML
build-job:  
  stage: build  
  script:  
    - echo "Hello, USER A"  

and save the changes.

  1. Still as User A, run the following commands:

git add -A
git commit -m "attack"
git push origin devel_tag:refs/tags/devel

This will push the changes to a new tag called devel.

  1. As User B, go to http://YOUR-GITLAB-INSTANCE/admin-group/admin-project, and click on the branches button (which should show 2, as highlighted below):
Screenshot_2023-08-23_at_9.45.02_PM.png
Screenshot_2023-08-23_at_9.45.02_PM.png From the original on GitLab

Click on the highlighted section in the image above and it will take you to http://127.0.0.1:3000/admin-group/admin-project/-/branches, where you will see 2 branches: main and devel (which is the protected branch that neither USER A or USER B have permission to push code to).

image.png
image.png From the original on GitLab
  1. As user B, click on the devel branch and you should see that it shows the contents that were commited and pushed by User A instead of the original protected devel branch. (** Impact: The contents of the protected branch have been spoofed by a user who does not have push rights into the branch, allowing him to deliver fake content to other users**)
image.png
image.png From the original on GitLab

If User B clicks on the .gitlab-ci.yml file, he will see the contents pushed by User A:

image.png
image.png From the original on GitLab
  1. Still as user B, clone the project locally using the gitlab token and cd into the directory and run the following command:
    git checkout devel

Then open the .gitlab-ci.yml file and you will see that it contains the contents pushed by User A, instead of the original contents of the protected branch.

Impact

The impact here is two-fold:

  1. After User A makes changes to the protected branch and pushes the changes into a tag with the same name as the protected branch (say devel), whoever visits the branches page in the UI of the project and clicks on the devel branch, will see the changes pushed by user A instead of seeing the contents of the original protected branch.

  2. If another user clones the project and checks out the devel branch, he will be checking out the contents of the tag pushed by User A instead of the original protected branch.

Impact

The impact here is two-fold:

  1. After User A makes changes to the protected branch and pushes the changes into a tag with the same name as the protected branch (say devel), whoever visits the branches page in the UI of the project and clicks on the devel branch, will see the changes pushed by user A instead of seeing the contents of the original protected branch.

  2. If another user clones the project and checks out the devel branch, he will be checking out the contents of the tag pushed by User A instead of the original protected branch.

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, GitLab's UI and git checkout resolve a name to a tag before a branch when both exist, so a tag with the same name as a protected branch overrides the branch's content.

Impact

A user without push rights to a protected branch could make other users see and check out attacker-controlled content when they view or checkout that branch, potentially delivering fake content.

What the attacker needed

GitLab instance; instance admin account; two normal users with access tokens; developer role on the project

How it was found

  1. As admin, create a private group and project, and invite two users as developers.
  2. As owner, create a .gitlab-ci.yml file, commit it to a new branch called devel, and protect that branch so only maintainers can push.
  3. As user A, clone the project, check out the devel branch, modify the file, commit, and push to a tag named devel.
  4. As user B, visit the branches page and click on the devel branch to see user A's content.
  5. As user B, clone the project and run git checkout devel to see user A's 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, branches and tags are both names for commits, and they can have the same name. GitLab's web interface and git commands sometimes pick the tag when both exist, so a user without push rights to a protected branch could make it look like the branch had different content. This is a spoofing issue because other users see the attacker's content when they expect the protected branch's content.

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.