Leaked NPM Token Fix: Step-by-Step Guide for Vibe-Coded Apps
OverMCP Team
Quick answer
If you've leaked an npm token in your vibe-coded app, immediately revoke it via npm's website or CLI (npm token revoke <token-id>), then rotate any secrets the token had access to (e.g., private packages, CI/CD variables). Scan your entire codebase—including .env files, commit history, and AI-generated configs—for hardcoded tokens. Use a secret leak scanner to catch any remaining exposures automatically.
What to check first
Before you panic, run through this checklist to contain the damage:
npm token revoke <token-id>..env examples or config files that accidentally include real tokens.trufflehog.Step-by-step fix
1. Revoke the leaked token
Do this first—every second counts. Use the npm CLI:
# List all tokens to find the leaked one
npm token list
# Revoke the specific token
npm token revoke <your-token-id>Or go to npm settings > tokens and delete it manually.
2. Rotate any secrets the token had access to
If your npm token had publish or read/write access to private packages, create a new token with the same permissions:
npm token create --read-only # For CI/CD read access
npm token create --publish # For publishing packagesThen update all services that used the old token:
.npmrc files (remove the old token, add the new one).env files in your repo (and add .env to .gitignore!)3. Scan your entire codebase
Vibe-coded apps often scatter secrets in unexpected places. Run a thorough scan:
# Using OverMCP secret leak scanner (free)
# Or use trufflehog locally
npx trufflehog git --since-commit HEAD~10 --only-verifiedCheck these common spots:
*.env* filesnext.config.js or vite.config.ts (hardcoded env vars)docker-compose.ymlserverless.yml.github/workflows/*.yml, .gitlab-ci.yml)rules/, Lovable's public/, etc.)4. Prevent future leaks
Add a pre-commit hook to block tokens before they hit your repo:
# Install husky and lint-staged
npm install --save-dev husky lint-staged
npx husky install
# Add a hook to run secret scanning
npx husky add .husky/pre-commit "npx --yes secretlint **/*"Or use OverMCP's continuous security monitoring to automatically scan every commit and PR.
5. Update your `.gitignore` and `.npmignore`
Ensure these files exist and include:
# .gitignore
.env
.env.local
.env.*.local
*.log
npm-debug.log*
node_modules/# .npmignore (if publishing a package)
.env
.git
__tests__Common mistakes
AI-built apps make these errors repeatedly:
.env.example but also a .env with real tokens. Bolt.new and Lovable have been known to scaffold projects with hardcoded API keys in .env that get committed.config.js file). Npm tokens should never be in client-side JavaScript—they grant access to your packages.git filter-branch or BFG Repo-Cleaner to purge it completely.publish permissions when only read-only is needed. Always use the least privilege.Common mistakes
AI-built apps make these errors repeatedly:
.env.example but also a .env with real tokens. Bolt.new and Lovable have been known to scaffold projects with hardcoded API keys in .env that get committed.config.js file). Npm tokens should never be in client-side JavaScript—they grant access to your packages.git filter-branch or BFG Repo-Cleaner to purge it completely.publish permissions when only read-only is needed. Always use the least privilege.FAQ
How do I find all places where my leaked npm token was used?
Check npm audit logs for any package publishes or access events from unknown IPs. Also search your repo's git history, CI/CD logs, and hosting platform environment variables. Use a secret leak scanner to automate this.
Can I remove a leaked npm token from git history?
Yes, use git filter-branch or the BFG Repo-Cleaner tool. But note that if the token was ever public, assume it's compromised even after removal from git—revoke it first.
Do I need to revoke all my npm tokens after a leak?
Only the leaked token needs immediate revocation. But as a best practice, rotate all tokens that share the same permissions or were created around the same time, especially if you're unsure which one leaked.
---
This guide is part of OverMCP's security resources for vibe-coded apps. For automated scanning, try our [free AI app security scanner](https://www.overmcp.com/).