Skip to content
Access control Disclosed report Advanced

An attacker can run pipeline jobs as arbitrary user

An attacker could run pipeline jobs as an arbitrary user by manipulating the git commit author name in a security policy project, causing the scan execution policy to trigger a pipeline under the victim's identity. This allowed the attacker to obtain the victim's CI job token and access private repositories.

GitLab

Originally disclosed on GitLab

  • Fixed in 21 days
  • Disclosed after 21 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 #2057633 by vaib25vicky on 2023-07-08, assigned to GitLab Team:

Report | How To Reproduce

Report

Summary

An attacker can run arbitrary pipeline jobs as a victim user. This means the attacker can access the user internal repositories, member only repositories, registry, etc... by using the victim CI_JOB_TOKEN token.

It is possible by using scan execution policy which triggers the pipeline on the basis of who last commited/edited policy.yml file.
We can include victim username in git config --global user.name "victim" and push changes to policy.yml as victim then a new pipeline will trigger whose triggerer/author will be victim.

All this is done, without any user interaction and only prerequisite is victim Gitlab username and name of victim internal or members-only project whose code is private.

Since, there is restriction in policy.yml file that we can't add scripts or bash commands. However, I find a way to use analyzer file to run custom bash code. This allows me to exploit the bug as shown in steps.

Steps to reproduce on Gitlab.com

VICTIM:

  • Sign in to a GitLab.com as a Victim user
  • Create an arbitrary public member only repository with some private files. (We will steal this repo as a poc.)

ATTACKER:

  1. Create a group in Gitlab.com
  2. Add victim as Owner
  3. Register a self-hosted runner at group level
    • Let it run untagged jobs
    • Install on an Ubuntu machine and choose executor as shell
    • SSH into your machine and create a bash file named analyzer at root level that is , /analyzer
Bash
root@ubuntu123$  nano /analyzer

###  !/bin/bash  
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}[@]gitlab.com/<victim>/<project>   ~/poc

root@ubuntu123$  chmod  +x  /analyzer  
   * After successful exploitation, victim repository will be downloaded in ` /home/gitlab/poc`
  1. Start an Ultimate trial for your group

  2. Prepare the test project. Follow the steps below:

    • Create a new private project with a working .gitlab-ci.yml file. For example, use the bash template.
    • Disabled shared runners for the project. Validate that the group runner created in the previous step is listed under "Available group runners: 1"
    • Add an empty named package.json to the project. This is required for the SAST scan to run.
    • On the left sidebar select Code and then Branches
    • Select New branch
    • Enter test as name
    • Select Create branch
  3. Prepare the security policy in your test project
    * On the left sidebar, select Secure* and then Policies.
    * Select New policy.
    * Select Scan execution policy
    * Switch to .yaml mode
    * Replace the content with the example policy yaml below

JSON
---  
scan_execution_policy:  
- name: test  
  description: 'helloo'  
  enabled: true  
  rules:  
  - type: schedule  
    branches:  
    - test  
    cadence: "*/16 * * * *"  
  actions:  
  - scan: sast  
    tags: []

     * Select **Configure with a merge request**  
     * Select **Merge.**
  1. After above steps, a new project is created in your group with name like test-security-policy-project
  2. Go to your test-security-policy-project Protected branch settings and choose Allow to push Maintainers and Developers
  3. Clone that test-security-policy-project to your local computer
  4. Change your git config and include username of the your victim that is,

git config --global user.name "victim"
10. Edit policy.yml file in your test-security-policy-project and just change description. No need of anything else.
11. git push origin main to merge your changes in test-security-policy-project .
12. In the policy.yml file commit history you'll see that your victim is the last edited user here.
13. Wait for 15 mins or more, a new pipeline will run in the test project and you will be able to gain access to victim internal repository or members only repository whose code is private.

Output of checks

This bug happens on GitLab.com.

Impact

An attacker can run pipeline jobs as arbitrary user without any user interaction allows access to internal and members-only projects whose code are private.

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 scan execution policy uses the commit author name to determine the pipeline triggerer, without verifying the actual user, allowing spoofing via git config.

Impact

An attacker could run pipeline jobs as an arbitrary user without user interaction, allowing access to internal and members-only projects whose code is private.

What the attacker needed

Victim's GitLab username; Name of victim's private project

How it was found

  1. Create a group and add the victim as Owner.
  2. Register a self-hosted group runner with shell executor and create an executable analyzer script that clones a repository using the CI job token.
  3. Start an Ultimate trial and create a private project with a working CI configuration and a package.json file.
  4. Create a scan execution policy in the project that runs on a schedule for the test branch.
  5. After the policy project is created, allow Maintainers and Developers to push to the protected branch.
  6. Clone the policy project, set git user.name to the victim's username, edit policy.yml, and push to main.

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.

In GitLab, pipelines run jobs with a token that has the same access as the user who triggered the pipeline. The attacker tricked GitLab into thinking the victim triggered the pipeline by setting the commit author name to the victim's username. Then the attacker's malicious code ran with the victim's token, letting them read the victim's private code.

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.