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
victimcreatesvictim-groupand activates ultimate trial.victimgoes tovictim-group, Manage -> Members and
- Adds
victim-memberas Maintainer - Adds
attackeras Developer
victimgoes tovictim-group, Settings -> Repository, Expand Protected branchesvictimclicks on Add protected branch and adds protected branchproductionwith the following configuration,

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).
victimcreates a projectvictim-projectinsidevictim-group.
(Choose initialize repository with a README)
victimadds filetest.shwith the following content,
echo “safe code”
attackercreates a new branchbranchfrommain.attackerchangestest.shinbranchand creates a malicious commit as following,
echo “malicious code”
attacker notes the SHA of the commit.
attackeragain changestest.shinbranchto 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.
attackercreates a merge request frombranchtomain.
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.
-
victimgoes tovictim-project, Code -> Merge requests and selects the merge request. (Created in step 10) -
victimswitches to Changes tab and sees that only safe changes are being merged. -
victimmerges the merge request. -
attackergoes tovictim-project, creates a new branchproductionfrommainbut intercept the request. -
In the body of the request,
attackerchanges&ref=mainto&ref=<noted_SHA>(Noted in step 8) -
attackerforwards 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
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 mergepermission should only be able to merge through the merging workflow. - Developer not given the
Allowed to pushpermission 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 mergepermission 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:
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
- Victim creates a group and project, adds attacker as Developer, and sets a protected branch 'production' allowing only Maintainers to push.
- Attacker creates a branch from main, makes a malicious commit, notes its SHA, then adds a safe commit to hide it.
- Attacker opens a merge request from their branch to main; victim reviews only safe changes and merges.
- Attacker initiates creation of a new branch 'production' from main but intercepts the request.
- Attacker changes the ref parameter from 'main' to the malicious commit SHA and forwards the request.
- 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.