Skip to main content
CriticalSecretsOWASP A07:2021CWE-798

How to fix: NPM auth token in source

npm_ tokens allow publishing packages as you. Should never be in client code or public repos.

Why it matters

An exposed npm token allows an attacker to publish malicious versions of any package you maintain, a supply-chain attack that can inject backdoors into every application that installs your package, potentially affecting millions of downstream users.

npm_ tokens allow publishing packages as you. Should never be in client code or public repos.

How to fix it

  1. 1Revoke the token immediately: npm token revoke TOKEN_ID (find ID with: npm token list)
  2. 2Audit recent package publishes for unauthorized versions
  3. 3Create a new granular automation token scoped only to the packages that need it

Code examples

Revoke and rotate npm token

bash
# List all tokens to find the compromised one
npm token list

# Revoke the compromised token (use the ID from the list)
npm token revoke <token-id>

# Create a new granular token with minimal permissions
npm token create --read-only          # for CI that only installs
npm token create --cidr=10.0.0.0/8   # restrict to internal IPs

GitHub Actions: use NPM_TOKEN secret

YAML
jobs:
  publish:
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          registry-url: 'https://registry.npmjs.org'
      - run: npm publish
        env:
          # Never hard-code the token: store it as a GitHub Actions secret
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

References

Detected automatically by VulnRadar. The check id is secret-npm-token, stable across every scan so you can filter or diff on it.

See every secrets check

Questions

How severe is NPM auth token in source?
VulnRadar rates this critical severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id secret-npm-token, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does NPM auth token in source map to?
It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for npm auth token in source

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: NPM auth token in source | VulnRadar