Skip to content
Info disclosure Disclosed report Intermediate

Deleting branch and merge request from a repository does not hide or delete the changes made in the merge request

Deleting a merge request and its branch in GitLab leaves the merge request's commits reachable through a hidden git remote, so the changes are never actually purged. An attacker who notices gaps in merge request IDs can enumerate these hidden remotes and recover the supposedly deleted content, including sensitive information.

GitLab

Originally disclosed on GitLab

  • Fixed in 54 days
  • Disclosed after 54 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 #2795371 by f3rn0s on 2024-10-21, assigned to @ottilia_westerlund:

Report | Attachments | How To Reproduce

Report

Summary

GitLab provides mechanisms for users to delete merge requests and associated branches, but currently the functionality will leave behind orphaned commits that are never automatically cleaned. An attacker can enumerate through the merge requests visible from the web UI or API, and spot missing incremental IDs. With these IDs, the attacker can then check to see if there exists a git remote that matches the deleted merge request, and then recover the changes.

Steps to reproduce
  1. Create a repository on GitLab
  2. Create a branch and push sensitive information
  3. Create a merge request for the branch
  4. Delete the branch, then delete the merge request
  5. Clone a fresh copy of the repository and use git ls-remote to find the still persisting git remote for the merge request.
  6. Use git fetch origin sha_hash_of_commit to pull the commit of the merge request down into the local repo.
  7. Use git checkout sha_hash_of_commit to checkout the commit.
  8. Use git log -p -v to observe the changes made in the commit, and observe any sensitive information remaining.

I have created a test repository here:

https://gitlab.com/f3rn0s/theres-no-such-thing-as-flags/

From the web UI you can observe there is an open merge request (identified as 2) that implies that there is some missing merge request. Using a tool I developed, I can quickly identify that there is a hidden remote that points at this now deleted merge request:

image.png
image.png From the original on GitLab

To manually re-create these steps you would use git directly:

image.png
image.png From the original on GitLab
image.png
image.png

We can observe from these screenshots that an anonymous user can retrieve the flag from the repository, even though from the maintainers perspective they have deleted both the branch the flag existed on, as well as the merge request originally created.

Impact

Users who are not aware of this functionality may erroneously believe that after deleting the merge request, and the branch the changes existing on, they have purged the repository of sensitive information. The sensitive information will then persist inside the repository and can potentially be gathered by an attacker.

What is the expected correct behavior?

Gitlab provides two modals that pop up during this process. Once when deleting the branch:

image.png
image.png From the original on GitLab

And once when deleting the merge request:

image.png
image.png From the original on GitLab

Both of these modals state that 'data loss could occur' which implies to the user that they are deleting data from the repository.

GitLab should seek to better clarify that deleting a merge request does not delete the underlying remote, or to change the functionality to remove the merge request remote when deleting the merge request.

Impact

Security impact depends on the repository affected. I first observed this behaviour on my own companys repositories, and the impact if discovered by an attacker would have been:

  • (For my company) Access to a red teaming report that contained redaction fails (hence why the MR and branch were deleted to remove the report from GitLab).
  • (For my company) Access to internal pricing information

An exploration of public facing repositories to expose similar issues may find similar levels of risk.

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 deleting a merge request removes the merge request record but not the underlying git remote and commits it created, so the objects remain reachable in the repository.

Impact

Sensitive information that maintainers believed they had removed could be recovered by an attacker, with the severity depending on what the repository contained.

What the attacker needed

Access to the repository (anonymous in the example); knowledge or guessing of commit hashes

The fix

GitLab should either clearly warn that deleting a merge request does not delete the underlying remote, or remove that remote when the merge request is deleted.

How it was found

  1. Create a repository on GitLab
  2. Create a branch, push sensitive information to it, and open a merge request for it
  3. Delete the branch and then delete the merge request
  4. Clone a fresh copy of the repository and list its remotes to find the one still pointing at the merge request
  5. Fetch and check out the commit by its hash, then inspect the log to see the changes and any sensitive information

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 delete a branch and a merge request in GitLab, you expect the code inside them to be gone. In fact the commits stay stored in the repository and can still be fetched by anyone who knows or guesses the commit identifier. This means secrets that someone tried to remove by deleting a merge request may still be readable.

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.