Skip to content
Info disclosure Disclosed report Intermediate

Disclosure of private merge request commits

GitLab stores merge request commits in a predictable ref that can be fetched without authentication, allowing anyone to access unmerged code from private forks even when merge request visibility is restricted. An attacker can brute-force merge request IDs to retrieve all such commits.

GitLab

Originally disclosed on GitLab

  • Fixed in 33 days
  • Disclosed after 33 days

HackerOne report #1847433 by shells3c on 2023-01-26, assigned to @kmorrison1:

Report | How To Reproduce

Report

Summary

When a merge request is created, commits of the merge request are fetched into the target repository (the fork's parent), which means you can access all commits of the merge request through the main repository itself, not just the fork, even when the MR hasn't been merged yet. Therefore, those commits can be exposed to the public no matter what the fork's visibility is: public, private, or internal. This is an intended behavior, however, it might expose some risks given the following scenario:

  • The project merge requests' visibility is set to Only Project Members, and the repository is accessible for everyone
  • Developers, with their forks set to private to hide their unfinished work, create merge requests to the project
  • Users now can access those un-merged private works if they know the commit SHA(s) (by visiting https://gitlab.com/<user>/<project>/-/commit/<sha> or using git: git fetch <sha>)

Gitlab decided to leave it as is in https://gitlab.com/gitlab-org/gitlab/-/issues/12643, agreed that the randomness of the SHA is the only protection for this.

Unfortunately, I found that I can get all those merge requests' commits without even knowing the SHA. Because those commits are saved into a ref named refs/merge-requests/<merge request id>/head, which I can then fetch without any authentication (the id can be brute-forced from 1 and until the ref is found not to exist)

Steps to reproduce
  1. Let's say user A is the project owner and user B is a project developer
  2. As user A, create a public project, set the Merge Requests visibility to Only Project Members in general settings and invite user B to the project
  3. As user B, fork the project (you can set the fork visibility to Private if you want), make a commit to the fork and finally create a merge request to the parent project, which is the official project owned by user A
  4. Now as the attacker (unauthenticated), execute the following commands:
Bash
###  Clone the project  
git clone https://gitlab.com/<user A>/<project>.git  
cd <project>  
###  Fetch the merge request's ref  
git fetch origin refs/merge-requests/1/head  
###  View commits  
git checkout -b let-see-what-in-the-mr FETCH_HEAD  
git log  

From there you can see the merge request's commit, even though you can see it via https://gitlab.com/<user A>/<project>/-/merge_requests

Examples

You can try with my example project created for testing only: https://gitlab.com/jobert2/alertmanager

  • The merge requests in that project are private
  • It has a merge request created from a private fork

Reproduce:

Bash
git clone https://gitlab.com/jobert2/alertmanager.git  
cd alertmanager  
git fetch origin refs/merge-requests/19/head  
git checkout -b example FETCH_HEAD  
git log  
Proposal fix

Given the fact that implementing an authentication check in this situation is very difficult, GitLab should apply the same method that refs of mirror use to secure themself: Add a random hash to prevent guessing, something like refs/merge-requests/<id>_<sha>/head

Output of checks

This bug happens on GitLab.com

Impact

Disclosure of merge requests' source code, leaking un-merged development work

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 merge request refs are named using only the sequential merge request ID, making them guessable, and no authentication is required to fetch them.

Impact

Unauthenticated users can access unmerged commits from private forks, leading to disclosure of source code and development work.

What the attacker needed

Public project with restricted MR visibility; a merge request from a fork; no authentication needed

The fix

GitLab should add a random hash to the ref name to prevent guessing, similar to how mirror refs are secured.

How it was found

  1. Create a public project and set merge request visibility to 'Only Project Members'.
  2. Invite a developer who forks the project (optionally privately) and creates a merge request.
  3. As an unauthenticated attacker, clone the project repository.
  4. Fetch the merge request ref using a guessed ID.
  5. Check out the fetched commits and view the log.

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 create a merge request in GitLab, the commits from your fork are copied into the main project so they can be reviewed. These commits are stored under a predictable name that includes the merge request number. Anyone can guess these numbers and download the commits, even if the merge request is supposed to be 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.