Skip to content
Code & CI · Secret guide

Leaked GitLab CI/CD Job Token: what to do in the first hour

High severityDetected onlyLast verified · 5 min read

A GitLab CI/CD job token is created automatically for each pipeline job and is available inside it as CI_JOB_TOKEN. It acts with the permissions of the user who triggered the job, limited to what GitLab allows job tokens to reach: for example cloning the project, pulling packages or container images, and calling a few API endpoints on projects that allow access from the source project. Its main protection is lifetime, because the token stops working when the job ends. That changes the response: first find out whether the job is still running, then investigate what the token could reach during its life, and rotate whatever else the job could read.

Check your GitHub account for leaked secrets — free

Provider
GitLab
Severity
High
Impact
Source code and build access
Checked live by LeakWatch
No

What a GitLab CI/CD Job Token looks like

The newer token format starts with a fixed prefix, followed by a short block and a longer one separated by an underscore:

glcbt-XXXX_XXXXXXXX…   GitLab CI/CD job token (masked)

Here the short block before the underscore is one to five letters or digits, and the longer block after it is 20 characters of letters, digits, dashes and underscores. Before this format, job tokens were short random strings with no recognizable prefix, so older logs may hold tokens that no scanner can recognize by shape. The value normally appears in job logs after a debug command such as env or echo $CI_JOB_TOKEN, or in clone URLs of the form https://gitlab-ci-token:<token>@gitlab.example.com/group/project.git. Do not confuse it with a runner authentication token (glrt-) or a personal access token (glpat-), which are long-lived.

How GitLab CI/CD Job Tokens get leaked

  • Debug output. A set -x, env or printenv line in a script writes the token into the job log, and the log or its artifact is public.
  • Clone URLs in logs. A submodule or dependency fetch prints the full URL, with the token in the user-info part.
  • Artifacts and caches. A .git/config or a generated file that stores the authenticated URL is uploaded as an artifact.
  • Copied pipeline output. A log pasted into an issue, a forum post or a support ticket without removing the token.
  • Committed build files. A script or Dockerfile with a token from a past run written in as if it were constant.

What to do in the first hour

  1. Check whether the job has finished. Open the pipeline that issued the token. A job token is valid only while its job runs, so for a finished job the token is already dead. If the job is still running, cancel it.
  2. Remove the exposure. Delete the log, artifact or paste that contains the token, and clean the repository history if it was committed. Public job logs can be erased from the job page.
  3. Review the job token allowlist. In the project’s CI/CD settings, find the section for job token permissions and look at which projects may be accessed by the token. Remove entries you do not need, which limits what any future leaked token can reach.
  4. Look for use during the job’s lifetime. In the audit events and the activity of projects that the token could access, check for clones, package downloads or API calls from unexpected IP addresses while the job ran.
  5. Rotate other secrets from the same job. The job log that leaked a token probably also showed other variables. Rotate those, and mark sensitive CI/CD variables as masked and protected.
  6. Fix the cause by removing debug printing and avoiding tokens in URLs. See I accidentally pushed an API key to GitHub.

Not sure what else leaked from the same repository? Run a free scan.

Not sure what else leaked? Run a free scan.

Revoke it at GitLab

There is no button that revokes a single job token, because GitLab does it for you: the token is invalidated as soon as the job completes or is cancelled. What you control is the job and the scope. Open the pipeline in your GitLab project after signing in, cancel the running job if there is one, and then tighten the job token permissions in the project’s CI/CD settings. A person has not confirmed the exact menu wording for this guide, and the interface changes between releases, so look for the section where job token access is configured, and follow the GitLab documentation on CI/CD job tokens.

How LeakWatch detects it

The rule is called GitLab CI/CD Job Token. It looks for the literal prefix glcbt-, then one to five letters or digits, an underscore, and exactly 20 characters from letters, digits, dashes and underscores. A token with a prefix that differs, with no underscore, or with fewer than 20 characters in the second block is refused. Older job tokens without a prefix are not reported. The severity is high, even though the token is short-lived, because a leaked value can still be used while the job runs. This type is not checked live: LeakWatch does not send any request to GitLab with the token it found.

LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.

FAQ

Is a leaked job token still dangerous after the job ends?

Not by itself: the token stops working when the job finishes. The real risk is what the job exposed alongside it, such as other variables, so rotate those, and check whether anything used the token in the meantime.

How can I limit what a job token can do?

Use the project’s job token permissions to allow only the projects that need access, and keep the allowlist short. Also give the triggering users only the roles they need, since the token inherits their permissions.

Should I rotate my personal access token too?

Only if it also appeared in the log or file. A job token and a personal access token are separate credentials, and the first does not expose the second.

Get alerted next time a secret leaks — create a free account

LeakWatch is not affiliated with GitLab.