Skip to content
Business logic Disclosed report Intermediate

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:

  1. Create a new group and apply the ultimate trial to it
  2. Create a new project in that group
  3. Create a CODEOWNERS file with the following content
[Code Owners]  
* [@]OWNER_USERNAME  
  1. Navigate to https://gitlab.com/GROUP/PROJECT/-/settings/repository, and do the following for the main branch:
    • Toggle on code owner approval
    • Allow developers and maintainers to merge
  2. Invite a developer to the group

As the developer:

  1. Create a new branch, add any change to any file, and create an MR from that branch to main - let's call that branch test-1

As the owner:

  1. Approve that MR (the owner sees the changes, they're all safe and can be merged)

As the developer:

  1. Delete test-1 branch
  2. Create a new branch call it test-2, and add "evil" code to the repository, create an MR with that change
  3. Create a new branch called test-1 from test-2
  4. Navigate back to the MR approved by the owner, and open the mr and merge
  5. Refresh the page, and verify that you can merge the MR
  6. Merge that MR, and verify that the second MR (created in step 9) is also merged
  7. 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:

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

  1. As owner, create a group and project, add a CODEOWNERS file, enable code owner approval, and invite a developer.
  2. As developer, create a branch with a change and open a merge request to main.
  3. As owner, approve the merge request.
  4. As developer, delete the branch, create a new branch with evil code, and open a second merge request.
  5. Create a new branch with the same name as the first from the second branch.
  6. 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.

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.