← All posts
npm tokenleaked secretsvibe codingsecurityAI app security

Leaked NPM Token Fix: Step-by-Step Guide for Vibe-Coded Apps

O

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:

  • [ ] Revoke the compromised token immediately via npm tokens page or npm token revoke <token-id>.
  • [ ] Check npm audit logs for any unauthorized package publishes or changes (Settings > Audit Log).
  • [ ] Scan your git history for the token—it may be in old commits, not just the latest code.
  • [ ] Search all environment variables in your hosting platform (Vercel, Netlify, Render, etc.) for the leaked token.
  • [ ] Look in AI-generated files: Bolt.new, Lovable, and Cursor often generate .env examples or config files that accidentally include real tokens.
  • [ ] Review CI/CD pipelines—tokens often end up in GitHub Actions, GitLab CI, or Vercel environment variables.
  • [ ] Run a full secret scan on your repo with OverMCP's free scanner or a tool like 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 packages

    Then update all services that used the old token:

  • GitHub Actions secrets
  • Vercel/Netlify environment variables
  • .npmrc files (remove the old token, add the new one)
  • Any .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-verified

    Check these common spots:

  • *.env* files
  • next.config.js or vite.config.ts (hardcoded env vars)
  • docker-compose.yml
  • serverless.yml
  • CI/CD config files (.github/workflows/*.yml, .gitlab-ci.yml)
  • AI-generated boilerplate (Cursor's rules/, Lovable's public/, etc.)
  • Old commit messages (developers sometimes paste tokens in PR descriptions)
  • 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:

  • Committing `.env` files: Vibe-coded apps often generate a .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.
  • Tokens in client-side code: Some AI tools mistakenly place npm tokens in frontend code (e.g., in a config.js file). Npm tokens should never be in client-side JavaScript—they grant access to your packages.
  • Not rotating tokens after a breach: Developers revoke the token but forget to update CI/CD pipelines, causing silent failures or—worse—leaving old tokens in cached environments.
  • Ignoring git history: Even if you delete the token from the latest commit, it's still in your git history. Use git filter-branch or BFG Repo-Cleaner to purge it completely.
  • Using overly permissive tokens: Many AI-generated configs create tokens with publish permissions when only read-only is needed. Always use the least privilege.
  • Common mistakes

    AI-built apps make these errors repeatedly:

  • Committing `.env` files: Vibe-coded apps often generate a .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.
  • Tokens in client-side code: Some AI tools mistakenly place npm tokens in frontend code (e.g., in a config.js file). Npm tokens should never be in client-side JavaScript—they grant access to your packages.
  • Not rotating tokens after a breach: Developers revoke the token but forget to update CI/CD pipelines, causing silent failures or—worse—leaving old tokens in cached environments.
  • Ignoring git history: Even if you delete the token from the latest commit, it's still in your git history. Use git filter-branch or BFG Repo-Cleaner to purge it completely.
  • Using overly permissive tokens: Many AI-generated configs create tokens with 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/).

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free