Exposed .npmrc: revoke the token before it publishes for someone else
Revoking the leaked npm auth token and removing the .npmrc keeps anyone from publishing packages or reading private ones as you
The threat
The scanner requested /.npmrc and got back a line like //registry.npmjs.org/:_authToken=.... That token authenticates you to an npm registry. Depending on its type, it can install your private packages, and if it is a publish or automation token, push new versions of your packages under your account.
The publish case is the dangerous one. Someone with a publish token can ship a malicious version of a package your customers, or your own builds, install: a supply-chain compromise that spreads downstream on its own. Even a read-only token exposes private code and can run up private-registry costs. Bots scrape _authToken strings specifically, so assume it has been collected.
The exact fix
Step 1, contain: revoke the token now. In your registryβs account settings (on npmjs.com under Access Tokens, or the equivalent for a private registry):
- Revoke or delete the exposed token immediately. That is the whole fix for the secret: a revoked token is inert no matter who holds it.
- Check recent publish history for versions you did not ship. Deprecate or unpublish anything unexpected, and warn consumers if needed.
- Issue a fresh, scoped token (read-only where possible, or a short-lived automation token in CI) and update your build to use it.
Step 2, stop serving the file.
- Remove
.npmrcfrom the web root. - Keep it out of deploys: add
.npmrcto.gitignoreand.netlifyignore, and never copy it into published output. In CI, inject the token from a secret store into an.npmrcthat lives outside any served directory, or useNODE_AUTH_TOKEN. - Block the path as a backstop.
nginx:
location ~ /\.npmrc {
deny all;
return 404;
}
Apache:
<FilesMatch "^\.npmrc">
Require all denied
</FilesMatch>
A committed
.npmrccan be safe, if it holds no token. Use variable substitution (//registry.npmjs.org/:_authToken=${NPM_TOKEN}) and keep the real value in an environment secret, so there is nothing to leak even if the file is served.
Verify it
curl -s https://yourdomain.com/.npmrc
You want a 404, not a line containing _authToken=. If the token is visible in the output, the file is still served, and the token still needs revoking.
Proof
The ApeCyber scanner flags this passively with a single GET of /.npmrc, from the outside, touching nothing and never using the token. apecyber.com ships built static output to Netlify, so no .npmrc is present in the served files to read. At β40 this is the largest single line on a posture score, and it clears once the token is revoked and the file is gone.