Skip to content
Business logic Disclosed report Beginner

Bypassing push rules via repository mirrors

GitLab's push rules were not enforced when commits were pulled from a mirrored repository, allowing an attacker to bypass all configured push rules. This could lead to secrets being pushed, commits from unknown users, and prohibited files being added.

GitLab

Originally disclosed on GitLab

  • Fixed in 3.1 years
  • Disclosed after 3.1 years

HackerOne report #684724 by xanbanx on 2019-08-29, assigned to gitlab_cmaxim:

Hi GitLab Security Team,

Summary

GitLab EE has the feature of so-called push rules. An administrator, or more fine-grained per project, the owner can create certain push rules. The goal of these push rules is avoiding to push certain commits to the repository, which violate one of the push rules. If a commit violating one of the push rules is pushed to the repository, a pre-check gets executed, which decides a commit attempt should be rejected. Therefore, the user gets an error message indicating the commit does not follow the rules.

On the other hand, GitLab has the ability to mirror a repository from a different repository. GitLab periodically pulls the repo from a remote location to the local GitLab repository.

Here, the problem arises. When mirroring a remote repository, GitLab does not check for the push rules. An arbitrary commit can be pulled from the remote repo bypassing any push rule set up globally be the GitLab administrator or locally be the project owner.

Steps to reproduce

  1. Create a repository and enable the following push rules under https://example.gitlab.com/<namespace>/<project>/settings/repository:
  • Check Committer restriction
  • Check Reject unsigned commits
  • Check Check whether author is a GitLab user
  • Check Prevent committing secrets to Git
  • Change Commit message to Fixes \d+\..*
  • Change Commit message negative match to ssh\:\/\/
  • Change Commit author's email to @example.com$
  • Change Prohibited file names to (jar|exe)$
  1. Set up a mirror repository under https://example.gitlab.com/<namespace>/<project>/settings/repository with direction pull. If the repo is public you don't need to set up any authentication method.
  2. On the remote mirror create a commit with a user, who is not on GitLab, and an email not matching the push rule above
  • Add a file named id_rsa
  • Add a file named test.exe
  • Name the commit message Bypassing push rules ssh://foo.bar
  1. Wait until the repo is mirrored

You now see that the commit from the remote repo is pushed to the GitLab project and thereby is bypassing al the setup push rules from above.

The only push rule, which seems to be enforced is the branch name push rule.

Impact

This allows anyone to bypass push rules set up by an administrator or project owner. This can lead to secrets being pushed to the repo, commits created by unknown users, etc

Examples

I have added the push rules as described above to an example repo and added a mirror repo. You can view the result at https://gitlab.com/wter23/test-push-rules-mirror

What is the current bug behavior?

GitLab accepts and pushes commits from a mirrored repo, which violate a set up push rule.

What is the expected correct behavior?

GitLab should reject commits from mirrored repos, which violate a push rule.

Relevant logs and/or screenshots

Output of checks

This happens on gitlab.com

Best,
Xanbanx

Impact

See above.

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 mirror import process does not run the same push rule validation that normal pushes go through.

Impact

Anyone could bypass push rules set by an administrator or project owner, potentially leading to secrets being pushed to the repository or commits from unknown users.

What the attacker needed

A GitLab project with push rules enabled; ability to set up a pull mirror; a remote repository to mirror

The fix

GitLab should reject commits from mirrored repositories that violate a push rule.

How it was found

  1. Create a repository and enable several push rules in the repository settings.
  2. Set up a pull mirror for the repository, using no authentication if the remote is public.
  3. On the remote mirror, create a commit that violates the push rules (wrong author, prohibited files, bad commit message).
  4. Wait for GitLab to mirror the repository.
  5. Observe that the violating commit is accepted and pushed to the GitLab project.

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.

Push rules are checks that stop certain commits from being added to a repository, like blocking files with secret keys or commits from unknown authors. The report shows that when GitLab copies commits from another repository (a mirror), it skips these checks, so bad commits get in anyway.

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.