← All posts
JWT secretvibe codingNext.js securitysecret scanningleaked secrets

Leaked JWT Secret Checker for Vibe Coding: Secure Your Next.js App

O

OverMCP Team

Quick answer

To check for leaked JWT secrets in a vibe-coded Next.js app, scan your entire codebase—including client-side bundles, .env files, and Git history—for hardcoded secrets using a dedicated leaked jwt secret checker vibe coding tool. Then, verify that your JWT secret is not exposed in browser source maps, public environment variables on Vercel, or any GitHub repository. Finally, rotate the secret immediately if found anywhere outside your server-side environment variables.

What to check first

Before diving into deep scans, run through this quick checklist. These are the most common places JWT secrets leak in AI-built apps:

  • [ ] Client-side code: Search for process.env.JWT_SECRET or hardcoded strings like 'your-secret-key' in *.tsx, *.jsx, or *.js files in your src/ or pages/ directories.
  • [ ] Public `.env` files: Check if .env (or .env.local) was accidentally committed to Git and is publicly visible on GitHub.
  • [ ] Vercel environment variables: Review your Vercel project’s environment variables for any that contain JWT or SECRET and are marked “exposed” (visible in client-side bundles).
  • [ ] Git history: Look for secrets that were committed in the past and are still accessible in commit history.
  • [ ] Source maps: If your production app has source maps enabled, anyone can see your original code, including hardcoded secrets.
  • Step-by-step fix

    1. Run a leaked jwt secret checker on your repo

    Use a free secret scanner like the secret leak scanner from OverMCP, which specializes in catching hardcoded API keys and secrets in AI-generated code. Point it to your GitHub repository or local folder.

    Example output from a scan:

    Found potential JWT secret in src/lib/auth.ts:12
      Pattern: 'my-super-secret-jwt-key'
      Risk: High

    2. Remove hardcoded secrets and use environment variables

    If you find a hardcoded JWT secret, move it to a .env.local file (never committed) and access it via process.env.JWT_SECRET. For Next.js App Router, ensure you prefix the variable with NEXT_PUBLIC_ only if you intend it to be client-side (which you never should for secrets).

    Before (vibe-coded mistake):

    // src/lib/auth.ts
    const JWT_SECRET = 'my-super-secret-jwt-key';

    After (secure):

    // src/lib/auth.ts
    const JWT_SECRET = process.env.JWT_SECRET;
    if (!JWT_SECRET) {
      throw new Error('JWT_SECRET environment variable is not set');
    }

    3. Check Vercel environment variables

    Go to your Vercel project dashboard > Settings > Environment Variables. Ensure that JWT_SECRET is not marked as “Expose to client-side” (the NEXT_PUBLIC_ prefix). If it is, remove the prefix and re-deploy.

    4. Scrub Git history

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

    # Example using BFG
    bfg --delete-text 'my-super-secret-jwt-key' my-repo.git
    git reflog expire --expire=now --all && git gc --prune=now --aggressive
    git push --force

    5. Rotate the secret

    Generate a new JWT secret using a cryptographically secure random string (e.g., openssl rand -hex 32). Update your environment variable on Vercel and locally. Invalidate all existing tokens if possible.

    6. Prevent future leaks with continuous monitoring

    Set up continuous security monitoring on your GitHub repo to automatically scan every pull request for secrets before merge.

    Common mistakes

    AI coding tools often make these errors that lead to leaked JWT secrets:

  • Hardcoding secrets in source files: A common pattern in tutorials is to use a placeholder like 'your-secret-key'. AI models trained on such code may replicate this pattern.
  • Using `NEXT_PUBLIC_` prefix for secrets: Vibe-coded apps sometimes mistakenly prefix environment variables with NEXT_PUBLIC_, making them accessible in client-side JavaScript.
  • Committing `.env` files: AI-generated projects often include a .env.example file, but developers may rename it to .env and commit it without thinking.
  • Storing secrets in JSON config files: Files like config.json or next.config.js often end up with hardcoded secrets, especially when AI generates them as inline values.
  • Relying only on `.gitignore`: Even if .env is ignored, a secret could be copied into another file that is tracked. Git history can still expose secrets that were committed before adding to .gitignore.
  • How to scan your entire app for leaked JWT secrets

    A comprehensive scan should cover:

  • All source code – Use a regex pattern search for common JWT secret patterns like 'jwt', 'secret', 'token' combined with assignment.
  • Client-side bundles – Check the _next/static/chunks folder in your production build for any hardcoded secrets that were inlined.
  • Public repositories – If your repo is public, use a service like the free AI app security scanner to scan for exposed secrets.
  • Dependency files – Sometimes secrets end up in package.json scripts or Dockerfiles.
  • Example of a quick local scan using grep:

    grep -r -E '(JWT_SECRET|jwt.*secret|process.env.JWT)' --include='*.{js,ts,jsx,tsx,json,yml,yaml}' .

    Why vibe-coded apps are especially vulnerable

    AI coding assistants generate code based on patterns from the internet, which often include insecure examples. They rarely enforce security best practices unless explicitly prompted. Moreover, AI-built apps tend to be shipped faster with less manual review, making secret leaks more likely. Using a dedicated leaked jwt secret checker vibe coding workflow is essential to catch these issues before deployment.

    FAQ

    How do I check if my JWT secret is exposed on Vercel?

    Go to your Vercel project dashboard, click Settings > Environment Variables. Look for any variable containing JWT or SECRET that has the “Expose to client-side” toggle enabled. If so, it’s accessible in browser JavaScript.

    Can attackers use a leaked JWT secret to forge tokens?

    Yes. If an attacker obtains your JWT secret, they can sign arbitrary tokens, impersonate any user, and gain unauthorized access to your app. Rotate the secret immediately and invalidate all existing tokens.

    What is the best way to scan my Next.js app for leaked JWT secrets?

    Use a combination of a local grep for hardcoded strings and a specialized tool like the secret leak scanner that understands AI-generated code patterns. For ongoing protection, enable continuous security monitoring on your repository.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free