How to Check for Leaked API Keys in Cursor with OverMCP
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:
.gitignore? If not, add it now.sk- and are often hardcoded during prototyping.AKIA and are commonly left in config files.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.*.local5. Set up continuous monitoring
Use continuous security monitoring to automatically scan every new commit for leaked secrets.
Common mistakes
.gitignore before your first commit.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.