Bypassing CODEOWNERS approval allowing to steal protected variables
A developer could bypass CODEOWNERS approval by deleting and recreating a branch after approval, then merging unapproved code. This allowed the attacker to merge malicious changes and potentially steal protected environment variables.
GitLab
Originally disclosed on GitLab
- Fixed in 2 months
- Disclosed after 2 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 #2295423 by ali_shehab on 2023-12-22, assigned to GitLab Team:
Report | Attachments | How To Reproduce
Report
Summary
Hi team hope you are well. There is something weird happening, that allows me to bypass CODEOWNERS approval of a file. This done by creating a branch through a merge requestali -> main and approve the mr by the CODEOWNER then deleting ali branch, creating branch ali2 and add evil code to it, and create mr. Now create ali from ali2 . Go back to the first mr, reopen and merge you will see that evil code was added although it was not approved.
Steps to reproduce
As an owner:
- Create a new group and apply the ultimate trial to it
- Create a new project in that group
- Create a
CODEOWNERSfile with the following content
[Code Owners]
* [@]OWNER_USERNAME
- Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/repository, and do the following for the
mainbranch:- Toggle on code owner approval
- Allow developers and maintainers to merge
- Invite a developer to the group
As the developer:
- Create a new branch, add any change to any file, and create an MR from that branch to
main- let's call that branchtest-1
As the owner:
- Approve that MR (the owner sees the changes, they're all safe and can be merged)
As the developer:
- Delete
test-1branch - Create a new branch call it
test-2, and add "evil" code to the repository, create an MR with that change - Create a new branch called
test-1fromtest-2 - Navigate back to the MR approved by the owner, and open the mr and merge
- Refresh the page, and verify that you can merge the MR
- Merge that MR, and verify that the second MR (created in step 9) is also merged
- Verify that the merged change is that introduced in the second MR which the owner didn't approve
Impact
Able to bypass codeowners approval which can lead to pass and evil code and steal protected enviroment.
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 merge request approval status was not invalidated when the source branch was deleted and recreated with different content.
Impact
A developer could merge unapproved code, potentially stealing protected environment variables.
What the attacker needed
GitLab Ultimate trial; Owner and developer roles; CODEOWNERS approval enabled
How it was found
- As owner, create a group and project, add a CODEOWNERS file, enable code owner approval, and invite a developer.
- As developer, create a branch with a change and open a merge request to main.
- As owner, approve the merge request.
- As developer, delete the branch, create a new branch with evil code, and open a second merge request.
- Create a new branch with the same name as the first from the second branch.
- Reopen and merge the first merge request, which also merges the second merge request with unapproved code.
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.
CODEOWNERS is a GitLab feature that requires approval from designated owners before merging changes to certain files. The bug let a developer reuse an already-approved merge request to sneak in new, unapproved code by manipulating branches. This meant the owner's approval was effectively bypassed, allowing malicious code to be merged.
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.