Security teams should replace long-lived npm tokens with short-lived OIDC-based publishing credentials, then restrict pipeline permissions so only trusted release workflows can mint them. The practical goal is to remove persistent secrets from repos and runners, because token theft becomes much harder when credentials expire quickly and cannot be reused outside the intended build step.
How Trusted Publishing Changes the npm Release Model
Trusted Publishing shifts npm release authentication away from reusable secrets and toward short-lived workload identity assertions issued by your CI provider. That changes the trust model in a useful way: the build job proves it is the approved publisher at release time, rather than carrying a long-lived token that can be copied, replayed, or leaked from the repository or runner.
For security teams, the practical benefit is not just convenience. It is the removal of standing credentials from the places attackers most often target, which reduces the value of secret scanning misses, stale environment variables, and compromised build logs.
That is why the control belongs in the release path, not as an optional add-on. If a package can still be published with a long-lived token elsewhere in the pipeline, the security gain is only partial, because the weaker path remains the easiest path to abuse.
What a Secure CI Implementation Needs to Enforce
A safe implementation starts with a narrow release workflow, explicit repository and branch trust, and permissions that only allow the job that performs the publish step to request the federated credential. The pipeline should separate build, test, and publish stages so that only the final, trusted release job can mint the publishing assertion.
That separation matters because CI systems are highly dynamic. Pull request jobs, reusable workflows, matrix jobs, and third-party actions should not inherit the ability to publish packages unless they are part of the explicitly trusted release path. If every job can request the same publish capability, the OIDC model loses most of its security value.
Good implementation also means treating the package registry trust policy as code. The publisher identity, repository, environment, and branch conditions should be reviewed as carefully as the package itself, because the security boundary is really between approved release automation and everything else that can run in CI.
For teams operating multiple registries or package families, the rule should be consistent: use the registry’s trusted publishing support where available, and keep the trust conditions as specific as possible to the release repository and environment. The goal is to make publishing possible only when the expected pipeline context is present.
What to Validate Before You Remove npm Tokens
Before you delete existing npm tokens, confirm that the release workflow can publish end to end under the new model and that there is no fallback path left in secrets storage, runner variables, or shared automation accounts. A migration is only complete when the old token can no longer be used to publish the package.
Teams should also verify who can change the release workflow itself. If anyone who can edit the pipeline can silently broaden the trust policy, then the publish path becomes a policy control problem as much as an authentication problem. Change control around the workflow definition is therefore part of the security boundary.
It is also worth checking whether package ownership, CI permissions, and branch protection all agree. A trusted publishing setup is strongest when the people who can modify release code are not the same people who can unilaterally widen the release trust conditions.
Risk and Threat Considerations
Legacy npm tokens are attractive because they are reusable, often long lived, and frequently stored in places attackers can search once they gain any foothold in a repository or runner. If an attacker steals a publish token, they may be able to push a malicious package version without needing to compromise the maintainer’s interactive account.
Failure mechanism: A CI pipeline that still exposes a reusable token, or a release workflow that grants publish rights too broadly, lets secret theft turn into package tampering. The attacker only needs one successful read of the token or one weakly controlled publishing path to abuse the registry trust model.
Impact: Malicious package releases can spread quickly through dependency ecosystems, contaminate downstream builds, and create a lasting trust problem for the publisher. Even where the package is later reverted, consumers may already have installed the poisoned version.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Trusted Publishing removes reusable npm secrets from CI release paths. |
| NHI-07 — Long-Lived Secrets | The question is about replacing persistent npm tokens with expiring publish credentials. | |
| Recommendation — Remove long-lived npm publish secrets and publish only with short-lived federated credentials. Retire long-lived publish tokens and enforce short-lived credential issuance for release jobs. | ||
| NIST SP 800-53 Rev 5 | IA-9 — Identification and Authentication (Non-Organizational Users) | CI publishing with OIDC is federated machine authentication, not shared secret use. |
| AC-6 — Least Privilege | Only the trusted release workflow should be allowed to mint publishing credentials. | |
| Recommendation — Use federated authentication for the release workflow and eliminate shared publish tokens. Limit publish permission to the smallest trusted release path and deny it elsewhere. | ||
| CIS Controls v8 | CIS-5 — Account Management | Managing and retiring publishing tokens is an account and credential lifecycle issue. |
| Recommendation — Inventory, rotate, and remove deprecated npm publishing credentials from CI. | ||
Practitioner Guidance
What to verify: Confirm that the publish job is the only job able to mint the OIDC credential, and that the credential expires after the release step. If a non-release workflow can still request publish authority, the implementation is not yet safe enough to rely on.
Implementation sequence: First remove stored npm publish tokens from CI secrets, then wire the release job to OIDC-based publishing, then test a failed publish from every non-release path you use in practice, including pull request and ad hoc automation flows.
Common mistake: Treating Trusted Publishing as a registry setting alone. The real control is the combination of registry trust policy, workflow permissions, and branch or environment restrictions, all of which must line up before the old secret can be retired.
Practitioner takeaway: The security win comes from making package publication a narrow, auditable, short-lived action, not from simply swapping one credential format for another.
Related resources from NHI Mgmt Group
- Guide: RubyGems, NuGet and Crates.io Publishing Tokens Guide
- How should security teams respond when a trusted-publisher npm supply chain compromise is detected in CI or build pipelines?
- How should security teams implement dependency validation for npm installs in CI/CD pipelines?
- How should security teams screen new npm packages before allowing them into builds and CI pipelines?
- How should security teams implement SBOM signing in CI/CD pipelines?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 5, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org