Skip to content
Access control Disclosed report Advanced

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:

  1. Create a new group, and apply the ultimate trial to it
  2. Create a new private project in that group
  3. Create a CODEOWNERS file, with the following content
[Code Owners]  
*.yml [@]OWNER_USERNAME  
  1. Create a .gitlab-ci.yml file, with the following content
my_job:  
    script:  
        - echo "Hello"  
  1. Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/repository, allow developers and maintainers to merge and toggle on code owners approval
  2. Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/merge_requests, and enable Remove approvals by Code Owners if their files changed
  3. Invite a developer to that group

As the developer:

  1. Navigate to the .gitlab-ci.yml file, 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:

  1. Add any change to the .gitlab-ci.yml file, for example ( direct commit )
my_job:  
    script:  
        - echo "Hello"  
        - echo "This is just another change"  

As the developer:

  1. Create a change on the README file, and create an MR with that change

As the owner:

  1. Approve that MR, the owner at this point is okay merging this change as it doesn't affect .yml files

As the developer:

  1. Clone that project locally git clone ...
  2. checkout the MR branch git checkout BRANCH
  3. Reset last 2 commits, git reset head~2
  4. 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"  
  1. Commit amend and push git add . && git commit --amend --no-edit && git push origin BRANCH -f
  2. Navigate to the MR's UI, resolve conflicts and "Use Ours"
  3. Refresh that page, and verify that you can merge the unapproved .gitlab-ci.yml changes
WhatsApp_Video_2023-12-25_at_5.59.25_PM.mp4 From the original on GitLab

Impact

Developers can bypass code owners' approvals allowing them to:

  1. Push code to protected branches.
  2. 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:

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

  1. As owner, create a group with ultimate trial, a private project, and add a CODEOWNERS file for *.yml files.
  2. 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.
  3. As developer, create an empty merge request by editing .gitlab-ci.yml without changes and merge it.
  4. As owner, directly commit a change to .gitlab-ci.yml.
  5. As developer, create a merge request changing README, and as owner, approve it.
  6. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.