Backend: Bypass predefined vars even if it is turned off
HackerOne report #1962746 by ali_shehab on 2023-04-26, assigned to @ngeorge1:
Report | Attachments | How To Reproduce
Report
Summary
Hi team. An admin can set that only maintainer and owner can bypass predefined variables. If you put it to true, when a developer tries to override manually they will get an error, however, this is bypassable using schedulers . https://docs.gitlab.com/ee/ci/variables/#restrict-who-can-override-variables
Steps to reproduce
Click to expand
- Create a group and a project in the group.
- Add this
.gitlab-ci.yamlfile to the project and lock this file.
stages:
- build
- owner-only
build:
stage: build
image: ubuntu
script:
- echo "This is a normal job..."
owner-only:
stage: owner-only
image: ubuntu
script:
- echo "This should only run is the pipeline was triggered by ali_shehab"
rules:
- if: '$GITLAB_USER_LOGIN == "ali_shehab"' - This means that owner-only job will only be triggered if the pipeline trigger is ali_shehab.
- Go to project settings => repository => expand protected branch and set developers and maintainers can push and merge.
- Now invite user B with a developer role.
- User B cannot edit the pipeline since it is locked.
- Now from the owner account send this request:
curl -X PUT -H "Authorization: Bearer PAC" "https://gitlab.com/api/v4/projects/{project_id}?restrict_user_defined_variables=true" - Now user B cannot override predefined variables and they will get an error.
- Now from account B schedule a pipeline and schedule a pipeline and add variables to be "ali_shehab" manaually and the var is GITLAB_USER_LOGIN
- It will run and override the variables.
This is the video:
Please also take a look at this thread to see the actual vulnerability: #410702 (comment 1430553920)
I can't run this pipeline with overriding
GITLAB_USER_LOGINbut I can schedule a pipeline with overridingGITLAB_USER_LOGIN. If I can schedule a pipeline on that branch, I can also alter that branch. So, I don't have to overwrite any variable, I can just change the pipeline config.
there is an edge case. It's possible that the project has defined its pipelines to use a CI configuration that's defined in an external repository that the "attacker" can't access.
Ref: !51682 (merged)
Impact
Able to bypass predefined variables even if only the maintainer and developers are allowed.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!