Research · Published 2 December 2026

What a poisoned repository can do with your GitLab CI_JOB_TOKEN

A build script is code that runs with your pipeline's credentials. In November we saw a public repository whose npm run build quietly started an obfuscated loader that connected to an unknown server, and nothing in its dependencies would have shown it. If the same step runs in a GitLab job, it runs next to the job's CI_JOB_TOKEN, your CI/CD variables and your registry credentials.

The case: a loader hidden in the repository itself

The repository was an ordinary web project built with Vite. It had no malicious dependency. The attack sat in the repository's own files:

  • The build script was changed from vite build to node init && vite build. The new init file was about 32 KB of obfuscated JavaScript.
  • A second copy hid in a fake asset: a file under public/fonts/ that looked like a web font but was obfuscated JavaScript of about 30 KB.
  • An editor task ran it on open: a .vscode/tasks.json entry set to run automatically when the folder is opened, so developers who open the project in VS Code with automatic tasks allowed run it too.
  • Code hidden behind whitespace: in vite.config.js, the payload sat far to the right of the export line, invisible in a normal editor window and in most diff views.

The commits used harmless messages ("Update .gitignore", "Delete .vscode directory"), some carried a backdated author date, and about twenty repositories of the same account received the changes within a quarter of an hour. Weeks later most of them were force-pushed back to an older state, which removes the evidence from the visible history.

How did the code get in? Not through a pull request or a dependency: the commits were made with the owner's own name from a git client and pushed with the owner's own credentials. One commit titled "Delete .vscode directory" in fact added the loader to four sub-projects at once. That pattern fits malware on a developer's machine, or stolen git credentials; from the outside the two look the same. Either way, the repository's history looked like the owner's normal work.

When the project was built, the loader ran right after the build step, set two global values (an identifier and a server address) and opened a connection to that server on a port no package registry uses. The build itself still succeeded.

We reported the findings to the repository owner, who has cleaned most of the affected repositories.

Why this matters in GitLab CI

A dependency scanner reads the lockfile. A secret scanner reads code and logs. Neither runs the build, so neither sees what init does. In a GitLab job, that build step runs in the same environment as:

  • CI_JOB_TOKEN, a short-lived token (prefix glcbt-) that is valid while the job runs. It acts with the permissions of the user who started the pipeline on what the job token can reach: the project's package registry and container registry, cloning the projects that allow it, and a set of API endpoints.
  • CI/CD variables that the job receives, including protected ones when the pipeline runs on a protected branch or tag.
  • Registry and cloud credentials that the job uses to publish packages or images, or to deploy.

A loader that talks to its own server can send any of these out, or use them directly while the job is still running: publish a package version, push an image, or read other projects the token is allowed to clone. In this case we saw the connection, not what was sent over it. The point is that nothing stops the step from doing it.

How does such code get into a GitLab build? The same ways real code does: a project mirrored or forked from a public repository, a dependency installed from a git URL, a template copied into an internal project, or a contributor's merge request that changes the build script.

Limit what a poisoned build step can reach

These GitLab settings do not stop the code from running, but they shrink what it can take:

  1. Restrict the job token. In each project, use the CI/CD job token allowlist (Settings > CI/CD > Job token permissions) so that only the projects you list can be accessed with a job token from another project. Review it for projects that hold packages, images or deployment config.
  2. Protect variables and keep them off feature branches. Mark deployment and publishing secrets as protected so they only reach pipelines on protected branches and tags, and mask them. A merge request pipeline then has nothing worth stealing.
  3. Be careful with merge requests from forks. By default their pipelines run in the fork, without your project's variables. Running them in the parent project gives fork code your environment: review the changes to build scripts, package.json, config files and .vscode/ before you do.
  4. Treat build scripts and config files as code in review. package.json scripts, vite.config.js, next.config.js, .vscode/tasks.json and files in asset folders can all execute. Long lines and files that do not match their extension are worth a second look.
  5. Pin what you mirror. When an internal project mirrors or vendors an external repository, update it deliberately and review the diff, rather than syncing automatically.
  6. Use short-lived, narrow credentials for publishing and deployment, so that a stolen value expires quickly and can do little.

What you can see while the job runs

Every one of these steps leaves a trace in what the job executes: a node process started from the build script, an unexpected outbound connection on a non-registry port, a command reading environment variables before a network call. That is the layer CI/CD runtime security watches: it records the commands each job runs and the connections it opens, and flags a job that behaves like an attack. Protet does this for self-managed GitLab runners and sends one finding per job to your SIEM. See how it works.

Checklist

  • ☐ Job token allowlist reviewed on projects with packages, images or deploy config
  • ☐ Publishing and deployment variables protected and masked
  • ☐ Fork merge request pipelines run in the fork, or only after review
  • ☐ Build scripts, config files and .vscode/ reviewed like code
  • ☐ Mirrored and vendored repositories updated deliberately
  • ☐ Publishing credentials short-lived and narrow
  • ☐ Runtime visibility on what CI jobs execute

Indicators available to defenders on request: hello@protet.io.