What can a hijacked CI workflow still publish under trusted publishing?
In December 2024 the first malicious ultralytics releases reached PyPI through the project’s own trusted publishing workflow, with no token involved. A guide to what the npm and PyPI OIDC exchange checks, why Nx’s stolen token and Ultralytics’ poisoned build are different failures, and the controls that close the gap: environment-bound publishers, tag rules, cache-free release builds, npm staged publishing with 2FA approval, and provenance checks.
By The Xalgorix Team
In early December 2024, four malicious releases of ultralytics, a popular computer vision library, reached PyPI carrying a cryptominer. PyPI's incident analysis contains a detail that matters to every team that has since switched to tokenless releases: the first round of malicious packages was “published through the existing GitHub Actions workflow, not by an API token”. The project was already using Trusted Publishing. The attacker did not need a credential, because they had a foothold in the workflow that the registry trusted.
Trusted publishing is a large improvement, and npm, PyPI, RubyGems and crates.io now all offer it. It removes the long-lived token that worms and CI breaches harvest. What it does not change is who can make the trusted workflow run, and with what code. This guide covers what the registry checks during the OIDC exchange, what two real incidents show about the gap, and the controls that close it on npm and PyPI.
What the registry checks when a workflow asks to publish
You register a “trusted publisher” on the package: for GitHub Actions, the owner, the repository, the workflow file name and, optionally, a GitHub environment name. When a job with the id-token: write permission runs, it asks GitHub for a signed OIDC token whose claims describe the run. The package tool sends that token to the registry, which compares the claims with the registered publisher and, on a match, returns a short-lived publish credential. PyPI's security model says those API tokens “expire no more than 15 minutes after the OIDC flow that authorizes them”.
Two properties of this design decide where the remaining risk sits. First, the identity is a workflow file in a repository. Neither registry's GitHub publisher form has a branch field, and PyPI's documentation notes that a renamed workflow is indistinguishable from the original apart from repository-state claims such as the git ref. The only built-in narrowing beyond the file name is the optional environment. Second, PyPI points out that any workflow in the repository can request an OIDC token “with any audience, so long as it has the id-token: write permission”, and every step in such a job can make that request. If an attacker can change what that job runs, the registry will accept what it uploads.
Two incidents, two different failures
The cases worth studying side by side are Nx in August 2025 and Ultralytics in December 2024, because trusted publishing would have changed one and did not stop the other.
Nx: a stolen token. According to the Nx postmortem, a PR-title check that ran on pull_request_target echoed unsanitised titles into a shell. An attacker used it to steal a read/write GITHUB_TOKEN, pushed a branch with a modified CI script, triggered publish.yml through workflow_dispatch, and exfiltrated the NPM_TOKEN secret it exposed. Malicious versions of nx and several @nx/* packages were live on 26 August 2025 for about four hours. (We walked through the workflow side of this in our piece on pull_request_target.) Afterwards Nx stopped using npm tokens, moved to trusted publishing, and added a manual 2FA approval for every release.
Ultralytics: a hijacked workflow. PyPI says the attack “targeted the GitHub Actions cache” used during the build phase. The compromised build ran inside the normal release workflow, which authenticated through trusted publishing and uploaded the result. A second round of releases then used “an unrevoked PyPI API token that was still available to the GitHub Actions workflow”, possibly left over from before the project switched. PyPI notes that “no security flaw in PyPI was used”.
The middle case is our reading of the Nx timeline, not something the postmortem states. Had Nx been on trusted publishing with no environment gate that day, there would have been no NPM_TOKEN to steal, but the attacker already held the access needed to dispatch publish.yml from a branch they had modified. The file name would have matched the registered publisher. That is why the controls below focus on who can start the release job and what it consumes, not only on removing tokens.
What the registries changed after 2025
The token side has tightened considerably. After the Shai-Hulud worm in September 2025, GitHub published its plan for npm: deprecate classic tokens, shorten granular token lifetimes, disallow tokens for publishing by default and expand trusted publishing. On 9 December 2025 npm permanently revoked all classic tokens and capped write tokens at 90 days. PyPI, in its November 2025 note on Shai-Hulud, reported finding still-valid PyPI tokens stored as secrets in compromised repositories and revoking them.
The most useful addition for the workflow side is npm's staged publishing, generally available since 22 May 2026. npm stage publish puts the tarball in a queue instead of the registry, and “a human maintainer with a 2FA challenge is required to approve a staged package before it is released”. A trusted publishing configuration can be limited to stage-only, in which case a plain npm publish from CI is rejected. For token-based automation, npm added stage-only granular tokens in September 2026 and says it plans to remove direct publishing with 2FA-bypass tokens in January 2027.
Staged publishing matters because it puts the human check outside CI. A GitHub environment approval is enforced by GitHub, which is the same platform an attacker is already inside in the scenarios above. A 2FA challenge on npm, answered from a maintainer's own device, is not reachable from a poisoned cache or a stolen GITHUB_TOKEN. It is only as good as the reviewer, though: approving a tarball nobody looked at protects nothing.
A release workflow built for the workflow-compromise case
Here is the shape we recommend for an npm package on GitHub Actions. Build and test run in a job with no OIDC permission and no cache; a separate, minimal job holds id-token: write, is bound to a protected environment, and only stages the tarball the build job produced.
name: release
on:
push:
tags: ["v*"]
permissions:
contents: read # default for every job; nothing writes to the repo
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@<full-commit-sha> # pin actions to SHAs
with:
persist-credentials: false
- uses: actions/setup-node@<full-commit-sha>
with:
node-version: 24 # no "cache:" here: release builds start clean
- run: npm ci --ignore-scripts
- run: npm test
- run: npm pack
- uses: actions/upload-artifact@<full-commit-sha>
with:
name: tarball
path: "*.tgz"
publish:
needs: build
runs-on: ubuntu-latest # npm trusted publishing needs cloud-hosted runners
environment: npm-release # required reviewers + tag-only deployment rule
permissions:
id-token: write # only this job can mint an OIDC token
steps:
- uses: actions/setup-node@<full-commit-sha>
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: npm install -g npm@latest # stage needs npm CLI 11.15.0+
- uses: actions/download-artifact@<full-commit-sha>
with:
name: tarball
- run: tar -xzf ./*.tgz # npm pack output unpacks to ./package
- run: npm stage publish # a maintainer approves with 2FA on npm
working-directory: package
env:
NPM_CONFIG_IGNORE_SCRIPTS: "true" # no lifecycle scripts in this jobOn PyPI the equivalent publish job uses pypa/gh-action-pypi-publish, which generates attestations by default, inside an environment such as pypi, again downloading a built artifact rather than building in place. Then configure the pieces around the file:
- Bind the publisher to the environment. Enter the environment name in the npm or PyPI trusted publisher form. Without it, any job in that workflow file can publish, whatever environment it does or does not use. PyPI said after Ultralytics that it would start warning when a workflow uses an environment the publisher does not require.
- Protect the environment. GitHub's environment rules let you limit deployments to selected branches and tags (here,
v*tags), add up to six required reviewers, stop the person who triggered the run from approving it, and disallow administrator bypass, which is allowed by default. The job does not start until the rules pass. - Protect the tags. If tags trigger releases, restrict who can create and move them; PyPI's security model recommends tag protection for exactly this reason. A tag-only deployment rule means little if any contributor can push
v9.9.9. - Keep caches out of the release path. The Ultralytics attack went through the build cache. A clean, cache-free build for releases costs a few minutes and removes that channel.
- Delete the old tokens. Ultralytics' second round used a token nobody had revoked. Remove
NPM_TOKENandPYPI_API_TOKENsecrets from the repository and organisation, revoke them on the registry, and on npm set publishing access to “Require two-factor authentication and disallow tokens”. The npm documentation notes this setting does not affect trusted publishers.
What provenance gives the people installing your package
Trusted publishing also produces signed provenance. npm generates it by default for trusted publishes from GitHub Actions and GitLab, for public packages in public repositories; on PyPI, the publish action attaches PEP 740 attestations. Consumers can check npm provenance and registry signatures with npm audit signatures.
Be precise about what that buys. PyPI's attestation security model says an attestation “will tell you where a PyPI package came from, but not whether you should trust it”. A malicious Ultralytics-style release built by the real workflow carries a provenance statement pointing at the real repository. What provenance does give you is a baseline. If a package that has always been published from org/repo/.github/workflows/release.yml suddenly ships a version with no provenance, or from a different repository or workflow, that change is a strong signal. PyPI recommends watching for exactly these identity changes between releases, and Nx added provenance checks to its own tooling after its incident.
A fifteen-minute audit of your own release path
Run through these for each package you publish:
- Does any repository or organisation secret still hold an npm or PyPI token? Is the token still valid on the registry side?
- Is the trusted publisher bound to an environment, and does that environment have required reviewers, self-review prevention, a tag or branch rule and admin bypass disabled?
- Which jobs have
id-token: write? It should be one small job, not a workflow-level permission. - Can the publish workflow be started with
workflow_dispatchorworkflow_callfrom an arbitrary ref? If so, the environment's deployment rule is doing all the work. - Does the release build restore a cache, or run lifecycle scripts from dependencies it just installed?
- On npm: is the package on staged publishing with a stage-only trusted publisher, and do approvers actually inspect the staged tarball?
- Have you run a workflow linter such as zizmor, which PyPI recommends, over every workflow that shares the repository with the publish job?
None of this makes a compromised CI harmless. An attacker who can change your source on the default branch and wait for a maintainer to approve the next release will still ship code. What these controls do is move the decision from “any foothold in CI” to “a person on a trusted device approved this specific artifact”, and give everyone downstream a record to check when that goes wrong.
Ready to see it prove a bug?
Start scanning on Cloud →