← All posts
Stripe secret keysecret scanningvibe codingNext.jssecurity

Stripe Secret Key Scanner: Find Leaked Keys in Your Next.js App

O

OverMCP Team

Quick answer

A Stripe secret key scanner is a tool that searches your codebase, environment variables, and git history for exposed Stripe secret keys (sk_live_ or sk_test_). For vibe-coded Next.js apps built with AI tools like Cursor, Bolt.new, or v0, leaked keys often hide in .env files, client-side bundles, or hardcoded in components. Run a scanner immediately after your AI generates code, and set up automated scanning in your CI/CD pipeline.

What to check first

Before deploying your vibe-coded Next.js app, audit these common leak points:

  • `.env.local` and `.env.production`: Open these files and verify they are in .gitignore. AI tools sometimes create .env files without adding them to .gitignore.
  • Client-side code: Check any file in /pages, /app, or /components for sk_live or sk_test strings. AI-generated components may include server-only secrets.
  • API routes: Look in /pages/api or /app/api for hardcoded secret keys. AI models sometimes inline secrets when generating API handlers.
  • Git history: Run git log -p | grep "sk_live" to check if a secret was ever committed.
  • Public repositories: If your repo is public, search for sk_live in the code directly.
  • Vercel/Netlify dashboard: Check environment variables on hosting platforms—sometimes AI tools suggest pasting keys directly.
  • npm dependencies: Some AI-generated apps include packages that accidentally bundle secrets.
  • Step-by-step fix

    Follow these steps to scan and fix leaked Stripe secret keys in your vibe-coded Next.js app.

    Step 1: Scan your codebase with a Stripe secret key scanner

    Use a dedicated Stripe secret key scanner like the secret leak scanner from OverMCP. This tool checks your entire project, including git history and common config files.

    # Example using OverMCP CLI (if available)
    npx overmcp scan --pattern "sk_live_*"
    # Or use the web tool: paste your repo URL or upload a file

    Alternatively, use grep manually:

    grep -r "sk_live_" . --include="*.{js,ts,jsx,tsx,json,env}" --exclude-dir=node_modules

    Step 2: Rotate the compromised key

    If you find a leaked key, go to the Stripe Dashboard and roll the key immediately. Create a new secret key and update your environment variables.

    Step 3: Remove the key from your codebase

    Delete any hardcoded keys from source files. Move secrets to environment variables:

    // pages/api/charge.ts (before - insecure)
    const stripe = new Stripe('sk_live_abc123');
    
    // After - secure
    const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

    Step 4: Update `.gitignore`

    Ensure .env* files are ignored:

    # .gitignore
    .env
    .env.local
    .env.production
    .env.*.local

    Step 5: Purge git history (if committed)

    If the key was committed, use git filter-branch or BFG Repo-Cleaner to remove it from history. Then force push to overwrite remote.

    Step 6: Set up continuous monitoring

    Prevent future leaks by adding automated scanning. OverMCP offers continuous security monitoring that scans every commit and deployment for exposed secrets.

    Common mistakes

    Vibe-coded apps often make these errors:

  • Hardcoding secrets in client-side code: AI coding tools sometimes generate code that uses sk_live_* directly in a React component, thinking it’s safe. But all frontend code is visible to users.
  • Committing `.env` files: AI assistants often create .env files as part of setup instructions but forget to add them to .gitignore.
  • Using `process.env` in client components: Next.js exposes environment variables prefixed with NEXT_PUBLIC_ to the browser. If you use process.env.STRIPE_SECRET_KEY in a client component, it will be bundled and leaked.
  • Leaving keys in git history: Even if you remove a key from the latest commit, it may still exist in previous commits. Attackers often scan git history for secrets.
  • Not rotating keys after a leak: Simply removing the key from code isn’t enough—the leaked key should be revoked in the Stripe dashboard.
  • How OverMCP helps

    OverMCP’s free AI app security scanner automatically detects leaked Stripe secret keys and other secrets in your vibe-coded Next.js app. It integrates with your git workflow and provides real-time alerts when secrets are exposed. Run it before every deploy to catch leaks early.

    FAQ

    How do I know if my Stripe secret key is leaked?

    Use a Stripe secret key scanner like OverMCP’s secret leak scanner or grep your codebase for sk_live_. Also check public GitHub repos and pastebin-like sites. If you suspect a leak, rotate the key immediately.

    Can I use `grep` to find Stripe keys in my Next.js app?

    Yes. Run grep -r "sk_live_" . --include="*.{js,ts,jsx,tsx,env}" --exclude-dir=node_modules. This will find any hardcoded secret keys. For a more thorough scan including git history and compressed files, use a dedicated scanner.

    What should I do if my Stripe secret key is exposed?

  • Rotate the key in the Stripe Dashboard. 2. Remove the key from your codebase and move it to environment variables. 3. Update your .gitignore and purge git history if committed. 4. Add automated scanning to prevent future leaks.
  • Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free