Skip to content
Access control Disclosed report Intermediate

CI_JOB_TOKEN incorrectly invalidated after the job finishes

The CI_JOB_TOKEN is invalidated when a job finishes, but a separate registry authentication token obtained using that job token remains valid for 15 minutes. An attacker with the job token could use this to push to the container registry after the job ends.

GitLab

Originally disclosed on GitLab

  • Fixed in 60 days
  • Disclosed after 60 days

⚠️ 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 #2769465 by xiridium on 2024-10-09, assigned to @truegreg:

Report | How To Reproduce

Report

Summary

CI_JOB_TOKEN is the CI/CD token of the job that lives up until the moment the job quits. In fact, a malicious actor that possess the CI_JOB_TOKEN can perform actions on behalf of the job for 15 minutes after the job quits

Steps to reproduce
  1. Extract CI_JOB_TOKEN. For example create the following job:
YAML
print-job-token:  
  stage: deploy  
  script:   
    - echo CI_JOB_TOKEN $CI_JOB_TOKEN  
    - echo CI_JOB_TOKEN $CI_JOB_TOKEN | base64  
    - |  
     curl --header "Authorization: $CI_JOB_TOKEN" https://gitlab.com/api/v4/job  
    - sleep 160

  1. Now we use docker cli that is proxied into Burp Suite
  2. Use that key to login into gitlab registry like this: docker login -u gitlab-ci-token -p glcbt-66_Y6__jb84THGzc3y42XVQ registry.gitlab.com
  3. Issue a valid docker push command which is also proxied into Burp Suite.
  4. The push request will contain an Authorization: bearer token that lives 15 minutes
  5. Stop the job. CI_JOB_TOKEN is invalided immediatedly, however the token from the previous step will be alive for 15 minutes.
Impact

Companies that rely on the short term living of the token might be put at risk, since the token would live for extra 15 minutes. So an attacker, that can possess CI_JOB_TOKEN would be able to perform actions on behalf of the job for extra time.

For example, an attacker can overwrite container registry images after the build stage has finished.

Examples

(If the bug can be reproduced on GitLab.com without violating the Rules of Engagement as outlined in the program policy, please provide the full path to the project.)

What is the current bug behavior?

"auth-token" is not invalided once the job finishes

What is the expected correct behavior?

The token should be invalided as soon as the job finishes.

Output of checks

This bug happens on GitLab.com (or any other instance of gitlab)

Impact

Companies that rely on the short term living of the token might be put at risk, since the token would live for extra 15 minutes. So an attacker, that can possess CI_JOB_TOKEN would be able to perform actions on behalf of the job for extra time.

For example, an attacker can overwrite container registry images after the build stage has finished.

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 the registry authentication token issued via the job token is not revoked when the job token is invalidated.

Impact

An attacker who possesses the CI_JOB_TOKEN could perform actions on behalf of the job for an extra 15 minutes, such as overwriting container registry images after the build stage has finished.

What the attacker needed

Access to CI_JOB_TOKEN; ability to run a CI job; network access to GitLab registry

The fix

The report says the token should be invalidated as soon as the job finishes.

How it was found

  1. Create a CI job that prints the CI_JOB_TOKEN and then sleeps.
  2. Use the CI_JOB_TOKEN to log in to the GitLab container registry.
  3. Issue a docker push command and capture the Authorization bearer token from the request.
  4. Stop the job, which invalidates the CI_JOB_TOKEN.
  5. Observe that the captured bearer token remains valid for 15 minutes.

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.

A CI job uses a short-lived token to prove its identity. When the job ends, that token stops working. However, when the job logs into a container registry, it gets a different token that lasts 15 minutes. The report says this second token is not cancelled when the job ends, so someone who stole the first token could still use the registry for a short time.

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.