Developer with Allowed to merge permission can bypass merging workflow to push an initial commit to the protected branch affecting its integrity
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:
