Force pipelines to not have access to protected variables and will likely fail
A developer could create a branch named refs/heads/main that GitLab treated as the protected main branch, causing subsequent pipelines on main to lose access to protected CI/CD variables and likely fail.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #1932805 by js_noob on 2023-04-03, assigned to @fvpotvin:
Report | Attachments | How To Reproduce
Report
Summary
Hello team, a developer can force all pipelines from the main branch to not have access to protected CI/CD variables and will likely force them to fail.
Steps to reproduce
As an owner do the following:
- Create a project
- Add a couple of variables
/-/settings/ci_cdlets call themVAR_1andVAR_2 - Add
.gitlab-ci.ymlfile containing the following:
image: node:latest
stages:
- build
build-job:
stage: build
script:
- echo $VAR_1
- cat $VAR_2
- Add any commit and navigate to the pipeline logs and verify that the variables are logged
- Add a developer member
As the developer do the following:
- Clone the repo locally
git clone <repo> - Create a new branch named
refs/heads/main;git checkout -b 'refs/heads/main' - Delete
.gitlab-ci.ymlfile and commit the changes - Push the branch to remote
git push origin HEAD
As an owner do the following:
- Add any changes and commit
- Navigate to the pipeline logs and verify that the vars are empty and not logged
Video/POC
Impact
Pipelines on main will not have access to protected variables leading them to fail.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
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
Root cause
Likely GitLab did not properly validate branch names, allowing a branch named refs/heads/main to be treated as the protected main branch.
Impact
Pipelines on main will not have access to protected variables, likely causing them to fail.
What the attacker needed
Developer role in project; protected variables configured
How it was found
- As owner, create a project and add CI/CD variables.
- Add a .gitlab-ci.yml that echoes the variables and run a pipeline to confirm they are logged.
- Add a developer member.
- As developer, clone the repo and create a branch named refs/heads/main.
- Delete .gitlab-ci.yml, commit, and push the branch.
- As owner, commit a change and check pipeline logs; variables are empty.
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.
In GitLab, protected variables are secret values only available to pipelines running on protected branches like main. A developer could create a branch with a special name that confused GitLab into thinking it was the real main branch, so later pipelines on main could not see those secrets and would break.
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.