Backend: Bypass predefined vars even if it is turned off

⚠️ 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 #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
  1. Create a group and a project in the group.
  2. Add this .gitlab-ci.yaml file 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"'  
  1. This means that owner-only job will only be triggered if the pipeline trigger is ali_shehab.
  2. Go to project settings => repository => expand protected branch and set developers and maintainers can push and merge.
  3. Now invite user B with a developer role.
  4. User B cannot edit the pipeline since it is locked.
  5. 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"  
  1. Now user B cannot override predefined variables and they will get an error.
  2. 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
  3. 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_LOGIN but I can schedule a pipeline with overriding GITLAB_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!

Edited by Furkan Ayhan