Skip to content
Business logic Disclosed report Intermediate

Manipulate the repository content in the UI (bypass #2031845)

GitLab's fix for a previous issue only blocked branch names matching a hex string followed by '-/', but the underscore character also works, allowing a malicious branch to be created. An attacker could make the repository content shown in the UI differ from what is cloned, potentially hiding malicious code.

GitLab

Originally disclosed on GitLab

  • Fixed in 2 months
  • Disclosed after 2 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 #2173053 by shells3c on 2023-09-20, assigned to GitLab Team:

Report | How To Reproduce

Report

Summary

In order to fix #2031845, Gitlab added another check in prohibited_branch_checks method to prevent any branch name that matches <hex>-/. However, the _ character also works and hasn't been protected yet.

Steps to reproduce
  1. Create a new empty project on Gitlab
  2. Clone the project and create a safe repository for UI display:
Bash
mkdir -p ./_/main  
echo "safe" > ./_/main/script.sh  
git add -A  
git commit -m .  
git push origin  
  1. Create a malicious branch with the malicious code:
Bash
git checkout --orphan "$(git rev-parse HEAD)_/main"  
git rm -rf .  
echo "evil" > script.sh  
git add -A  
git commit -m .  
git push origin  
  1. Go to your repository settings and set your default branch to the new branch

Now visit the project from Gitlab and view the content of script.sh, you will see safe, but if you clone it, the file will contain evil.

Output of checks

This bug happens on GitLab.com

Impact

Similar to #1864278 (you can read it here if you can't access the HackerOne report), the repository you see from the UI is different than the repository you clone. You can see the video in the original report to understand it better.

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 branch name validation only blocks a hex string followed by '-/', but not the same pattern with '_/', so a branch name like <hex>_/main bypasses the check.

Impact

An attacker could make the repository content displayed in the GitLab UI differ from what is actually cloned, potentially hiding malicious code from users who only inspect the UI.

What the attacker needed

A GitLab account; ability to create a project and push branches

How it was found

  1. Create a new empty project on GitLab.
  2. Clone the project and create a safe repository for UI display by adding a file under a directory named '_/main'.
  3. Create a malicious branch with a name formed by the current commit hash followed by '_/main', containing a malicious script.
  4. Set the default branch to the new malicious branch in repository settings.
  5. Visit the project in GitLab and view the script file; it shows safe content, but cloning the repository yields the malicious 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.

GitLab tries to stop branches with names that could confuse the system, but their filter missed one character. This means someone can create a branch that makes the website show safe files while the actual downloaded code is malicious.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.