Skip to content
Access control Disclosed report Intermediate

Developer with `Allowed to merge` permission can bypass merging workflow to push an initial commit to the protected branch affecting its integrity

A Developer with only 'Allowed to merge' permission on a protected branch could bypass the merge workflow and push an initial commit to that branch by intercepting a branch creation request and changing the ref to a malicious commit SHA. This could allow deployment of malicious code to production if auto-deployments are configured.

GitLab

Originally disclosed on GitLab

  • Fixed in 53 days
  • Disclosed after 53 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 #3149326 by theluci on 2025-05-15, assigned to @katwu:

Report | Attachments | How To Reproduce

Report

Hello, I hope you are doing well.
This report is similar to my other report #2708946.
However, this time using a very practical exploitation scenario which might be already being exploited.

Functionality

Gitlab provides a feature to set a few branches as protected in the top-level group.

Vulnerability

When creating a protected branch Gitlab doesn’t check if the Developer has Allowed to push permission or not, it only checks if the Developer has Allowed to merge permission.

<------------------------------------Important------------------------------------>

**This allows a Developer to bypass merging workflow to push an initial commit to the protected branch. (affecting it’s integrity) **

This can wreak havoc if the project has auto-deployments, which means malicious protected branch would be automatically pushed to a secure environment. For example, production.

<------------------------------------------------------------------------------------>

Steps to reproduce

  1. victim creates victim-group and activates ultimate trial.
  2. victim goes to victim-group, Manage -> Members and
  • Adds victim-member as Maintainer
  • Adds attacker as Developer
  1. victim goes to victim-group, Settings -> Repository, Expand Protected branches
  2. victim clicks on Add protected branch and adds protected branch production with the following configuration,
10may-1.png
10may-1.png From the original on GitLab

It can be seen that only Maintainers have allowed to push permission. Thus, it is expected that only Maintainers could create production branch (which involves directly pushing an initial commit).

  1. victim creates a project victim-project inside victim-group.

(Choose initialize repository with a README)

  1. victim adds file test.sh with the following content,
echo “safe code”  
  1. attacker creates a new branch branch from main.
  2. attacker changes test.sh in branch and creates a malicious commit as following,
echo “malicious code”  

attacker notes the SHA of the commit.

  1. attacker again changes test.sh in branch to a safe version and creates a safe commit as following,
echo “safe code”  
echo “some other safe code”  

This is done to smuggle one malicious commit in branch which would later be merged into main.

  1. attacker creates a merge request from branch to main.

In a real-world scenario, it might not be main but some development branch like dev which is fine as it is not the production branch.

  1. victim goes to victim-project, Code -> Merge requests and selects the merge request. (Created in step 10)

  2. victim switches to Changes tab and sees that only safe changes are being merged.

  3. victim merges the merge request.

  4. attacker goes to victim-project, creates a new branch production from main but intercept the request.

  5. In the body of the request, attacker changes &ref=main to &ref=<noted_SHA> (Noted in step 8)

  6. attacker forwards the request.

attacker has created a malicious production branch without having the Allowed to push permission.

In a real-world scenario, project might even have auto-deployments deploying malicious production branch to production server which can wreak havoc.

POC

16may-poc.mp4 From the original on GitLab

Examples

This is my POC project (It is private so let me know if you need ownership),

What is the Current Bug behavior?

Developer can push and create a protected branch even though he is specifically not given Allowed to push permission and only given Allowed to merge permission. Thus, merging workflow should have been followed.

What is the Expected Correct behavior?

  • Developer with Allowed to merge permission should only be able to merge through the merging workflow.
  • Developer not given the Allowed to push permission should not be able to create the protected branch as it requires initial pushing.

Output of checks

This bug happens on GitLab.com (Probably on instance too).

Impact

  • Developer with Allowed to merge permission can bypass merging workflow to push an initial commit and create a protected branch. (Integrity: High)
  • This can wreak havoc if the project has auto-deployments, which means malicious protected branch would be automatically pushed to a secure environment. For example, production. (Scope: Changed, Integrity: High)

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 protected branch creation endpoint checks only merge permission, not push permission, when a branch is created from a specific commit SHA.

Impact

A Developer with only merge permission could push arbitrary code to a protected branch, potentially leading to deployment of malicious code to production if auto-deployments are enabled.

What the attacker needed

Attacker has Developer role; protected branch allows merge but not push for Developers; victim merges attacker's merge request; attacker can intercept HTTP requests

The fix

Protected branch creation should require push permission, not just merge permission.

How it was found

  1. Victim creates a group and project, adds attacker as Developer, and sets a protected branch 'production' allowing only Maintainers to push.
  2. Attacker creates a branch from main, makes a malicious commit, notes its SHA, then adds a safe commit to hide it.
  3. Attacker opens a merge request from their branch to main; victim reviews only safe changes and merges.
  4. Attacker initiates creation of a new branch 'production' from main but intercepts the request.
  5. Attacker changes the ref parameter from 'main' to the malicious commit SHA and forwards the request.
  6. The protected branch 'production' is created with the malicious commit, bypassing push restrictions.

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.

In GitLab, protected branches restrict who can push code directly. A user with only 'merge' permission should not be able to create the branch with new code. The attacker tricked the system by modifying a request to use a hidden commit, effectively pushing code without permission.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.