← All posts
secret leak scannerAPI key leakCursorvibe codingsecurity scan

How to Check for Leaked API Keys in Cursor with OverMCP

O

OverMCP Team

Quick answer

Use a dedicated secret leak scanner like OverMCP's secret leak scanner to automatically detect exposed API keys in your Cursor project. It scans your codebase, git history, and environment files for patterns matching Stripe, OpenAI, AWS, and dozens of other services — no signup required.

What to check first

Before diving into a full audit, run through this quick checklist:

  • [ ] Check your `.env` file – Is it in .gitignore? If not, add it now.
  • [ ] Search for `sk-` in your code – OpenAI keys start with sk- and are often hardcoded during prototyping.
  • [ ] Look for `AKIA` – AWS access key IDs begin with AKIA and are commonly left in config files.
  • [ ] Scan commit history – Even if you removed a key, it may still exist in an older commit.
  • [ ] Review client-side JavaScript – Keys in frontend bundles are visible to anyone.
  • Step-by-step fix

    1. Scan your project with OverMCP

    Run the free secret leak scanner on your project repository. It will output a list of detected secrets and their locations.

    2. Remove hardcoded keys

    For each detected key, replace the hardcoded value with an environment variable. For example, in a Next.js app:

    // ❌ Bad: hardcoded in source
    const openai = new OpenAI({ apiKey: 'sk-...' });
    
    // ✅ Good: use environment variable
    const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

    3. Rotate compromised keys

    If a key has been exposed (especially if it was ever pushed to a public repo), revoke it immediately and generate a new one. For OpenAI, go to the API keys dashboard. For AWS, use the IAM console.

    4. Add `.env` to `.gitignore`

    Ensure your .env file is never committed:

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

    5. Set up continuous monitoring

    Use continuous security monitoring to automatically scan every new commit for leaked secrets.

    Common mistakes

  • Committing `.env` files – This is the #1 cause of leaks. Always double-check your .gitignore before your first commit.
  • Hardcoding test keys – During rapid prototyping with Cursor, it's easy to paste a key directly into a component. Later it gets forgotten.
  • Not rotating keys – Even if you remove a key from the code, it may have been scraped by bots if it ever hit a public repo.
  • Ignoring client-side bundles – Keys in frontend code (like Firebase API keys) are visible in the browser. Use environment variables that are only available server-side.
  • Assuming private repos are safe – Private repos can still be compromised via npm supply chain attacks or insider threats.
  • FAQ

    What is a leaked API key?

    A leaked API key is a secret credential (like a Stripe secret key or OpenAI API key) that is exposed in your codebase, typically in source files, configuration files, or version control history. If discovered by attackers, it can be used to access your paid services without authorization.

    How do I find leaked keys in my Cursor project?

    Use a dedicated scanner like OverMCP's secret leak scanner. Alternatively, you can manually search for patterns like sk- (OpenAI) or AKIA (AWS) using grep or your IDE's search function, but this is error-prone and time-consuming.

    What should I do if I find a leaked key?

    Immediately revoke the key (generate a new one) and delete the exposed copy from your codebase. Then, check usage logs for any unauthorized access. Finally, add the key to your environment variables and ensure .env is in .gitignore.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free