Leaked an API key: what to do right now
Bots scan public repositories continuously and can use a leaked key within minutes. Deleting the line or the commit is not enough; the key must be revoked.
Scan code for leaked secrets →Find leaked API keys, tokens, private keys and passwords in code, .env and logs before you commit or share.🔒 Runs on your device. Nothing is uploaded.Step by step
- Revoke or rotate the key in the provider’s dashboard immediately (OpenAI, AWS, Stripe, GitHub…).
- Check the provider’s usage and billing for activity you did not make.
- Put the new key in an environment variable or secret manager, never in code; add .env to .gitignore.
- Scan the rest of the project for other secrets with the secret scanner above: paste code or drop .env, config and log files.
- If you need the key gone from history, rewrite it with git filter-repo and force-push, but only after revoking.
Why revoking comes first
Forks, clones, CI logs and caches may already hold the key, and history rewrites do not reach them. Some providers are alerted by GitHub secret scanning and may disable a key on their own, but do not rely on it.
Prevent the next leak
Use a pre-commit secret scanner, keep example configs with placeholders such as YOUR_API_KEY, and never paste keys into chats, tickets or AI assistants.
Questions
Which keys does the scanner recognise?
OpenAI, Anthropic, AWS, GitHub, GitLab, Stripe, Google, Slack, Telegram bots, SendGrid, npm, Hugging Face, JWTs, private keys, and passwords in config lines and connection strings.
Are my files uploaded?
No. Files are read and scanned in your browser.
It found a test key. Is that a problem?
Test keys are lower risk, but rotate them too if the repository is public; they can still be abused or reveal account details.
Related guides
Updated: