Developers can bypass code owners approval by changing a MR's base branch
HackerOne report #2236642 by salh4ckr on 2023-11-02, assigned to @kmorrison1:
Report | Attachments | How To Reproduce
Report
Summary
Hello team,
I found this issue after while trying to find a bypass of #422142 (closed), and i found another way to bypass code owner approval by changing a MR's branch.
- I can use approval from X branch to push in Y protected branch.
Steps to reproduce
As Owner:
- Create a new group and apply the ultimate trial to it.
- Create a new project in that group.
- Add a developer member.
- Create new branch:dev_branch.
- Create CODEOWNERS file in main branch
[Code Owners]
* [@]YOUR_USERNAME
- Create Create CODEOWNERS file in dev_branch
[Code Owners]
* [@]YOUR_USERNAME
7 .Navigate to Project settings => Repository => Protected branches, and allow Developers + Maintainers to merge to main, and also toggle on Code owner approval.
8.Navigate to Project settings => Repository => Protected branches, and allow Developers + Maintainers to merge to dev_branch, and also toggle on Code owner approval.
9.Navigate to Project settings => Merge requests => Approval settings, check Prevent approval by author, Prevent approvals by users who add commits, and Prevent editing approval rules in merge requests and under When a commit is added: select Remove all approvals.

As Developer:
-
Go to project > repository and switch from main to dev_branch
-
Edit or add a file and add in content you want to be in main.
-
Create marge_request.
AS Owner:
- Approve merge merge request created by a developer.
As Developer:
-
On merge request click edit then Change the base branch of the MR to main, and verify that the approval persists
-
Now click merge.
-
Go to project repository you will see you changes in main branch.
What is the current bug behavior?
Changing the base branch of a MR persists code owners' approvals.
What is the expected correct behavior?
Changing the base branch of a MR should remove code owners' approvals.
Impact
Ability to push in protected branch using approval from different branch
Video:
POC_Approvals.mp4
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:

