You published a secret to npm. Do this, in this order.

A .env, an .npmrc with a token, a private key, or a key baked into dist/ went out with npm publish. Here's the order that matters.

1. Rotate the credential now

Assume it's already copied. Registry mirrors and CDNs (unpkg, jsDelivr, npmmirror) fetch new tarballs within minutes, and people do scrape new releases for keys. Unpublishing doesn't un-leak anything, so revoke and reissue before you touch npm:

Once the old value is dead, the rest is cleanup.

2. Find every version that has it

The file is rarely in just the latest release. Check every published version. This pulls each tarball from the registry and looks for the filename, or for the leaked value itself:

pkg=your-package
needle='\.env'          # filename regex, e.g. '\.env|\.npmrc|id_rsa'
value='sk_live_abc123'  # or the leaked value itself (optional)

for v in $(npm view "$pkg" versions --json | jq -r 'if type=="array" then .[] else . end'); do
  tgz=$(npm pack "$pkg@$v" --silent 2>/dev/null) || continue
  if tar -tzf "$tgz" | grep -qE "(^|/)($needle)"; then echo "$v: file"; fi
  if [ -n "$value" ] && tar -xzOf "$tgz" | grep -qF "$value"; then echo "$v: value"; fi
  rm -f "$tgz"
done

Filename matching misses keys that a build step inlined into a bundle (for example process.env.X replaced at build time). Grepping for the value catches that, but only if you know the value. To find secrets you don't know about, scan the published package. It reads every file in the tarball, not just the names.

3. Unpublish, if npm will let you

npm's unpublish policy is strict. You can remove a version yourself only if:

npm unpublish your-package@1.4.2

You can never reuse that version number. If you unpublish every version, the name is blocked for 24 hours. When the policy says no, npm support can still remove a version that contains a secret. Open a ticket at npmjs.com/support with the package, versions and what leaked. Rotate first anyway: removal can take days.

4. Ship a clean patch and deprecate the bad range

# fix packaging (step 5), then
npm version patch && npm publish

# warn anyone still installing a leaky version
npm deprecate "your-package@<1.4.3" "contained a leaked credential (rotated); upgrade to 1.4.3+"

A deprecated version stays installable, but npm prints a warning on every install. Most people pin with ^, so they pick up the patch on their next install anyway.

5. Fix why it shipped

Almost always one of these:

Switch to a "files" allowlist, then check the result before every publish with npm pack --dry-run.

6. Make the next one fail in CI

A dry-run list only helps if someone reads it. Gate the publish job instead. ReleaseShield runs npm pack, unpacks the tarball and fails the step on secrets or sensitive files before npm publish runs:

curl -fsSLo releaseshield.mjs https://release-shield-app.vercel.app/releaseshield.mjs
node releaseshield.mjs scan

The GitHub Action setup is in the docs. To check what's already out there, scan any published package. It's free and needs no login.