Skip to content
Access control Disclosed report Intermediate

CI ID Token Manipulated claims vulnerability for forked projects MR pipelines

GitLab issued CI ID tokens for merge request pipelines from forks that contained the same subject claim as the protected branch of the target project, allowing an attacker with low privileges to obtain tokens for branches they cannot push to. This could let them authenticate to third-party services like AWS as if they were the protected branch.

GitLab

Originally disclosed on GitLab

  • Fixed in 2 months
  • Disclosed after 2 months

Related issue

⚠️ 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 #3137660 by skybound on 2025-05-09, assigned to @greg:

Report | Attachments | How To Reproduce

Report

Summary

An attacker can trick GitLab into issuing, and subsequently using, an ID token for a protected branch of a repository which they do not have push or merge permissions for through the use of forks and merge request pipelines. This could be used to authenticate with other services such as AWS, gaining access to resources where access is restricted through the protected branches of the repository.

Steps to reproduce
  1. Create a victim project with a main protected branch
  2. Configure the repository to only allow maintainers to push/merge into the main protected branch
  3. Commit the first-gitlab-ci.yml () as .gitlab-ci.yml into the victim project directly to the main branch
  4. In the resultant pipeline, note the sub claim
  5. Add a second user as a developer to the project

The following steps are to be taken as the second user:

  1. Fork the victim repository, the fork will be referenced as the attacker repository
  2. Run the pipeline manually within the attacker repository
  3. In the resultant pipeline, note the sub claim - it should be different to the previous sub claim
  4. Commit the second-gitlab-ci.yml () to the attacker repository as .gitlab-ci.yml (replacing the previous version) directly to the main branch
  5. Submit a merge request to the victim repository, attempting to merge main from attacker into main
  6. Note a new pipeline is triggered for the merge request
  7. View the sub claim in this pipeline. Note it has the same value as the pipeline from step 4.
Impact

This allows an attacker that has low privileges within a repository to get JWT / ID tokens from branches they may not have push/merge access to. ID tokens are commonly used to authenticate with other services, for example authenticating to AWS via OIDC. The following assumes the third party service is AWS, however similar applies to other services such as Azure. However, this post is limited to AWS for brevity.

Access to AWS is constrained through AWS trust relationships which check the sub claim which by default validates the repository name and branch (as described in https://docs.gitlab.com/ci/cloud_services/aws/#configure-a-role-and-trust). For example, the sub field would be project_path:mygroup/myproject:ref_type:branch:ref:main if the pipeline was run from the main branch in the project at mygroup/myproject.

An attacker through their fork could modify .gitlab-ci.yml to extract the ID token for the main branch of the victim repository. This would allow them to authenticate to third party services as if they were the main branch of the victim repository. If the repository hosted Terraform code that was deployed automatically into an AWS account through CI/CD with trust relationships configured to only allow the main branch of the victim repository to access an administrative deployment role, an attacker would directly gain administrative access to the AWS account.

Examples

victim repository = https://gitlab.com/Skybound/oidc
pipeline from step 4 = https://gitlab.com/Skybound/oidc/-/jobs/9990314446
attacker repository = https://gitlab.com/rs_mohit/oidc
pipeline from step 7 = https://gitlab.com/rs_mohit/oidc/-/jobs/9990324982
pipeline from step 12 = https://gitlab.com/Skybound/oidc/-/jobs/9990328384

What is the current bug behavior?

The sub field from the merge request pipeline is the same as if the pipeline was directly run from the main branch.

What is the expected correct behavior?

The sub field from the merge request pipeline should not be the same as the value when running the pipeline directly against main.

Relevant logs and/or screenshots

The JWT token claims when running against the main branch of the victim repository:

{
  "namespace_id": "[REDACTED]",  
  "namespace_path": "[REDACTED]",  
  "project_id": "[REDACTED]",  
  "project_path": "[REDACTED]/oidc",  
  "user_id": "[REDACTED]",  
  "user_login": "Skybound",  
  "user_email": [REDACTED],  
  "user_access_level": "owner",  
  "pipeline_id": "1809987654",  
  "pipeline_source": "push",  
  "job_id": "9990314446",  
  "ref": "main",  
  "ref_type": "branch",  
  "ref_path": "refs/heads/main",  
  "ref_protected": "true",  
  "runner_id": 32976687,  
  "runner_environment": "gitlab-hosted",  
  "sha": "[REDACTED]",  
  "project_visibility": "private",  
  "ci_config_ref_uri": "gitlab.com/[REDACTED]/oidc//.gitlab-ci.yml@refs/heads/main",  
  "ci_config_sha": "[REDACTED]",  
  "jti": "[REDACTED]",  
  "iat": 1746820333,  
  "nbf": 1746820328,  
  "exp": 1746823933,  
  "iss": "https://gitlab.com",  
  "sub": "project_path:[REDACTED]/oidc:ref_type:branch:ref:main",  
  "aud": "sts.amazonaws.com"  
}

The JWT token claims when running against the main branch of the attacker repository:

{
  "namespace_id": "[REDACTED]",  
  "namespace_path": "[REDACTED]",  
  "project_id": "[REDACTED]",  
  "project_path": "[REDACTED]/oidc",  
  "user_id": "[REDACTED]",  
  "user_login": "[REDACTED]",  
  "user_email": [REDACTED],  
  "user_access_level": "owner",  
  "pipeline_id": "1809988925",  
  "pipeline_source": "web",  
  "job_id": "9990324982",  
  "ref": "main",  
  "ref_type": "branch",  
  "ref_path": "refs/heads/main",  
  "ref_protected": "true",  
  "runner_id": 12270831,  
  "runner_environment": "gitlab-hosted",  
  "sha": "[REDACTED]",  
  "project_visibility": "private",  
  "ci_config_ref_uri": "gitlab.com/[REDACTED]/oidc//.gitlab-ci.yml@refs/heads/main",  
  "ci_config_sha": "[REDACTED]",  
  "jti": "[REDACTED]",  
  "iat": 1746820450,  
  "nbf": 1746820445,  
  "exp": 1746824050,  
  "iss": "https://gitlab.com",  
  "sub": "project_path:[REDACTED]/oidc:ref_type:branch:ref:main",  
  "aud": "sts.amazonaws.com"  
}

The JWT token claims when running the main branch of the attacker repository as a merge request pipeline within the victim repository:

{
  "namespace_id": "[REDACTED]",  
  "namespace_path": "[REDACTED]",  
  "project_id": "[REDACTED]",  
  "project_path": "[REDACTED]/oidc",  
  "user_id": "[REDACTED]",  
  "user_login": "[REDACTED]",  
  "user_email": [REDACTED],  
  "user_access_level": "developer",  
  "pipeline_id": "1809989379",  
  "pipeline_source": "merge_request_event",  
  "job_id": "9990328384",  
  "ref": "main",  
  "ref_type": "branch",  
  "ref_path": "refs/heads/main",  
  "ref_protected": "false",  
  "runner_id": 12270831,  
  "runner_environment": "gitlab-hosted",  
  "sha": "[REDACTED]",  
  "project_visibility": "private",  
  "ci_config_ref_uri": "gitlab.com/[REDACTED]/oidc//.gitlab-ci.yml@refs/heads/main",  
  "ci_config_sha": "[REDACTED]",  
  "jti": "[REDACTED]",  
  "iat": 1746820490,  
  "nbf": 1746820485,  
  "exp": 1746824090,  
  "iss": "https://gitlab.com",  
  "sub": "project_path:[REDACTED]/oidc:ref_type:branch:ref:main",  
  "aud": "sts.amazonaws.com"  
}

Branch Protection Rules showing maintainer only:\

image.png
image.png From the original on GitLab
Output of checks

This bug happens on GitLab.com and self-managed instances

Impact

An attacker can leverage this issue to obtain ID tokens for protected branches of repositories. This could allow them to authenticate and access third party services that trust GitLab as an OIDC provider. For example, administrative access to cloud accounts.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

How To Reproduce

Please add reproducibility information to this section:

Implementation plan

  • Create a new derisk feature flag called use_forked_project_claims_in_ci_id_tokens
  • For cross project MR pipelines use source project of MR as the project
  • Code logic changes here and here
  • Update docs
  • Get MR reviewed and merged and deployed
  • Rollout the feature flag
  • Cleanup the feature flag

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 CI ID token claims for cross-project merge request pipelines used the target project's path and the source branch name instead of the fork's project path, so the subject claim matched the protected branch.

Impact

An attacker with low privileges could obtain ID tokens for protected branches and use them to authenticate to third-party services such as AWS, potentially gaining administrative access if trust relationships rely on the sub claim.

What the attacker needed

Victim project with protected branch; attacker has developer role; attacker can fork and create MR; third-party service trusts GitLab OIDC

The fix

The proposed fix is to use the source project of the merge request for cross-project MR pipelines when generating CI ID token claims, behind a feature flag.

How it was found

  1. Create a victim project with a protected main branch and restrict pushes/merges to maintainers.
  2. Commit a CI configuration to the main branch and note the sub claim in the resulting pipeline.
  3. Add a second user as a developer to the project.
  4. As the second user, fork the victim repository and run the pipeline manually in the fork, noting a different sub claim.
  5. Replace the CI configuration in the fork's main branch and submit a merge request to the victim repository.
  6. View the sub claim in the merge request pipeline and observe it matches the victim's main branch pipeline.

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.

When a project runs automated jobs (CI), it can get a signed token that other services use to decide if the job is allowed in. The token includes a claim saying which project and branch it came from. Here, a job triggered by a merge request from a fork got a token that looked like it came from the protected main branch of the original project, so the attacker could pretend to be that branch.

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.