Bypassing approvals of CODEOWNERS
A developer could bypass code owner approval requirements by manipulating Git history and resolving merge conflicts to inject unapproved changes into protected files. This allowed pushing code to protected branches and potentially disclosing protected CI/CD variables.
GitLab
Originally disclosed on GitLab
- Fixed in 41 days
- Disclosed after 41 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 #2296778 by ali_shehab on 2023-12-25, assigned to @ameyadarshan:
Report | Attachments | How To Reproduce
Report
Summary
Hello team, an owner can configure the project to reset all code owners' approvals in an MR if the "protected" files change. However, developers can bypass code owners' approvals and inject unapproved code into the project, by some weird GIT fuzzing.
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:
- Navigate to the
.gitlab-ci.ymlfile, click edit, don't make any changes, and create an MR, it's an empty MR so no approvals are needed, merge that MR
As the owner:
- Add any change to the
.gitlab-ci.ymlfile, for example ( direct commit )
my_job:
script:
- echo "Hello"
- echo "This is just another change"
As the developer:
- Create a change on the README file, and create an MR with that change
As the owner:
- Approve that MR, the owner at this point is okay merging this change as it doesn't affect
.ymlfiles
As the developer:
- Clone that project locally
git clone ... - checkout the MR branch
git checkout BRANCH - Reset last 2 commits,
git reset head~2 - Add any "evil" code to
.gitlab-ci.yml, for example
my_job:
script:
- echo "Hello"
- echo "This is just another change"
my_evil_job:
script:
- echo "Evil"
- Commit amend and push
git add . && git commit --amend --no-edit && git push origin BRANCH -f - Navigate to the MR's UI, resolve conflicts and "Use Ours"
- Refresh that page, and verify that you can merge the unapproved
.gitlab-ci.ymlchanges
Impact
Developers can bypass code owners' approvals allowing them to:
- Push code to protected branches.
- Disclose group/project protected CI/CD variables
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 logic did not properly re-evaluate code owner approval requirements after a force-push and conflict resolution that altered the diff.
Impact
Developers could bypass code owner approvals to push code to protected branches and potentially disclose protected CI/CD variables.
What the attacker needed
Ultimate trial license; Owner configures CODEOWNERS and approvals; Developer role in group; Owner approves a README MR
How it was found
- As owner, create a group with ultimate trial, a private project, and add a CODEOWNERS file for *.yml files.
- As owner, add a .gitlab-ci.yml file, enable code owner approval and the setting to remove approvals if code owner files change, and invite a developer.
- As developer, create an empty merge request by editing .gitlab-ci.yml without changes and merge it.
- As owner, directly commit a change to .gitlab-ci.yml.
- As developer, create a merge request changing README, and as owner, approve it.
- As developer, clone the project, checkout the MR branch, reset the last two commits, add evil code to .gitlab-ci.yml, amend and force-push, then resolve conflicts using 'Use Ours' and merge.
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. The report shows a way for a developer to sneak changes into those files without getting that approval, by rewriting Git history and using a merge conflict resolution trick.
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.