Safeguard
Security Guides•

Myth or fact: if my npm account has 2FA, my CI publish token is safe?

Myth. A granular token with bypass 2FA can publish without a second factor, so account 2FA does not protect it. What npm documents and how to limit damage.

Safeguard Security Team
4 min read

Myth. A granular npm token created with bypass 2FA turned on can publish without a second factor. npm's own docs say it overrides account and package 2FA for actions such as publishing. Account 2FA protects your sign-in, not a token you already minted.

The claim and why people believe it

Many maintainers enable 2FA, feel covered, and then paste a token into CI. It is natural to think the account setting follows the token around. It does not, when bypass is on.

What the docs say

From the npm access tokens page:

  • Bypass 2FA applies only to write tokens and defaults to false.
  • When enabled, it overrides account level and package level 2FA for actions such as publishing.
  • The page advises against enabling it where a package or organization requires fully enforced 2FA.
  • A token cannot exceed the permissions of its owner.
  • Starting August 2026, bypass tokens can no longer do identity or governance actions such as managing 2FA, creating tokens or managing maintainers. Those need an interactive challenge.

Publishing itself requires either 2FA on the account or a granular token with bypass enabled, according to the npm publishing pages. So CI that uses a token is in the second case by design.

Myth versus fact

StatementVerdictWhy
2FA on my account stops anyone using my tokenMythBypass tokens skip the second factor
A stolen bypass token can publish a new versionFactThat is what bypass does for write tokens
A stolen bypass token can change my 2FA settingsNot after August 2026npm says those actions need an interactive challenge
Scoping a token to one package limits damageFactTokens can be limited to specific packages and scopes
A short expiry helpsFactTokens can be given an expiration date

Limit the damage

  1. Prefer trusted publishing, so no long-lived secret exists. See npm trusted publishing setup and common errors.
  2. If you must keep a token, scope it to one package, mark it write only if needed, set an expiry and limit IP ranges. Details in how to configure an npm granular token.
  3. Consider stage-only tokens. The docs say they can stage versions but cannot publish directly, so a maintainer approves with 2FA first. See staged publishing.
  4. Put the publish job behind an approval gate.
  5. Know your first hour plan: your package was compromised, a runbook for maintainers.

Check for drift

Tokens pile up. Review the list on the npm site every few months and revoke anything unclear. The page says direct publishing with granular tokens is being removed in January 2027, so you will need to change the setup anyway. Check the live page for the current state.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how fast a new issue in a package can surface, which is the pace a stolen token works at too.

Quick check

Is bypass 2FA on by default?

No. The npm docs say it defaults to false and applies only to write tokens.

What is the safest CI setup?

Trusted publishing, where the registry accepts a short-lived identity from your workflow and you store no publish token at all.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.