Skip to content
Access control Disclosed report Intermediate

Backend: Bypass predefined vars even if it is turned off

A developer could bypass the restriction on overriding predefined CI/CD variables by scheduling a pipeline and manually setting a variable such as GITLAB_USER_LOGIN. This allowed the developer to make a job that was meant to run only for a specific user run under their control.

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 #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

<details><summary>Click to expand</summary>
  1. Create a group and a project in the group.
  2. Add this .gitlab-ci.yaml file to the project and lock this file.
PLAINTEXT
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
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:

bandicam_2023-04-26_21-44-29-043.mp4 From the original on GitLab
</details>

Please also take a look at this thread to see the actual vulnerability: https://gitlab.com/gitlab-org/gitlab/-/issues/410702#note_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

Impact

Able to bypass predefined variables even if only the maintainer and developers are allowed.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

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 scheduled pipeline creation feature did not enforce the restrict_user_defined_variables setting, allowing users to set variables that should have been protected.

Impact

A developer could bypass the restriction on overriding predefined variables and cause jobs that were meant to run only for a specific user to execute.

What the attacker needed

A GitLab account with developer role; ability to create scheduled pipelines; a CI configuration with a job gated on a variable

How it was found

  1. Create a group and a project, and add a CI configuration that has a job which only runs when a specific user triggers the pipeline.
  2. Protect the branch so developers can push and merge, and invite a second user with the developer role.
  3. As the owner, enable the setting that restricts who can override variables.
  4. As the developer, schedule a pipeline and manually add a variable named GITLAB_USER_LOGIN with the value of the privileged user.
  5. The scheduled pipeline runs and the restricted job executes.

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, you can set rules for when a job runs, for example only if the pipeline was started by a certain user. The system has a setting to stop people from faking the variables that hold such information. This report shows that a developer could still fake the variable by creating a scheduled pipeline and typing the value by hand, so the job ran even though it should not have.

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.