Skip to content
RCE Disclosed report Intermediate

Subshell execution in 'artifacts' paths for jobs in .gitlab-ci.yml

The GitLab Runner evaluates artifact paths in a subshell with the executor's permissions, not the job image's user. An attacker who can define a pipeline could run commands as the executor, often root.

GitLab

Originally disclosed on GitLab

  • Fixed in 2 months
  • Disclosed after 2 months

HackerOne report #1650554 by mattjaccino on 2022-07-26, assigned to @ngeorge1:

Report | Attachments | How To Reproduce

Report

NOTE! Thanks for submitting a report! Please note that initial triage is handled by HackerOne staff. They are identified with a HackerOne triage badge and will escalate to the GitLab team any. Please replace all the (parenthesized) sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!

Summary

Even when using an image that is configured to a specified user, the 'artifacts' path evaluations are handled by the executor, often the root user. A subshell command or any additional code can be included in the list of paths and it is run by the executor with its permissions rather than the user for the image being used.

Steps to reproduce
  1. Include a subshell command within the list of paths in the 'paths' section of a job's 'artifacts' definition.
  2. Have job run to perform whatever action is in the subshell by the executor
Impact

This type of privilege escalation would allow anyone with the ability to define pipelines to execute commands with the executor.

Examples

An 'artifacts' entry such as

artifacts:  
  paths:  
    - "$(whoami)"  
    - "$(cat /etc/passwd)"  

Would be performed in the job and give output like:

Uploading artifacts...  
Runtime platform                                    [...]  
WARNING: root: no matching files. Ensure that the artifact path is relative to the working directory  
WARNING: root:x:0:0:root:/root:/bin/bash  
[...]  
gitlab-runner:x:992:990:GitLab Runner:/home/gitlab-runner:/bin/bash: no matching files. Ensure that the artifact path is relative to the working directory   

When the image is set to use user "user"

What is the current bug behavior?

Executor's permissions are used to evaluate artifact paths and execute any commands that may appear

What is the expected correct behavior?

Either treat the paths as raw strings or use the image's user to perform any evaluations

Relevant logs and/or screenshots
artifacts:  
  paths:  
    - "$(whoami)"  
    - "$(cat /etc/passwd)"  

Would be performed in the job and give output like:

Uploading artifacts...  
Runtime platform                                    [...]  
WARNING: root: no matching files. Ensure that the artifact path is relative to the working directory  
WARNING: root:x:0:0:root:/root:/bin/bash  
[...]  
gitlab-runner:x:992:990:GitLab Runner:/home/gitlab-runner:/bin/bash: no matching files. Ensure that the artifact path is relative to the working directory   
Output of checks

This bug occurs on the job output screen for GitLab pipelines.

Results of GitLab environment info

Unable to run the command. We are using GitLab 15.0.2, but if needed, I'll ask a co-worker for the info

Impact

Ability to execute code with the permission of the executor.

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 runner passes artifact path strings to a shell for evaluation instead of treating them as literal paths or evaluating them as the job's user.

Impact

Anyone able to define pipelines could execute commands with the executor's permissions, which is often root.

What the attacker needed

Ability to define pipelines

The fix

The paths should be treated as raw strings or evaluated using the image's user rather than the executor.

How it was found

  1. Add a subshell command inside the list of paths in the artifacts section of a job.
  2. Run the job so the executor performs the subshell action.

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.

GitLab pipelines can save files as 'artifacts'. The program that runs the pipeline (the runner) checks those file paths. Instead of treating the paths as plain text, it runs them through a shell. That means special characters like $(...) get executed. The runner usually runs as a powerful user, so this lets someone run commands with high privileges.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.