Check Code for Leaked API Keys Before You Share It
How API keys and passwords end up in tickets, forums and AI chats, how a secret scanner spots them, and what to do the moment a real key has leaked.

Most leaked credentials are not stolen by clever attacks. They are pasted. A developer shares a config file in a support ticket, posts a stack trace on a forum, sends a zipped project to a contractor, or drops a code snippet into an AI chat to ask why it fails. Somewhere in that text is a database URL with a password, a cloud access key or a payment API key. Automated bots scan public code sites and paste sites around the clock, and a key published on a public repository can be abused within minutes.
What counts as a secret
Anything that grants access on its own:
- cloud keys such as AWS access keys and Azure storage keys
- payment keys, for example Stripe secret keys
- tokens for GitHub, GitLab, npm, PyPI and Hugging Face
- AI service keys from OpenAI or Anthropic
- chat and email tokens and webhook URLs for Slack, Discord, Telegram, SendGrid or Twilio
- private key files (anything starting with BEGIN PRIVATE KEY)
- database connection strings with the password inside
- JSON Web Tokens that may still be valid
- variables called password, secret or api_key holding a literal value
Many providers give their keys a recognisable prefix, such as AKIA for AWS or ghp_ for GitHub personal tokens, precisely so that scanners can find them.
How a scanner finds them
There are two complementary methods. Pattern rules match known formats exactly, which gives few false alarms. Entropy checks look for strings that are unusually random, which catches unknown formats but also flags hashes, IDs and test data. A good scanner uses both, ranks findings by severity and skips obvious placeholders such as changeme, your_api_key or ${API_TOKEN}.
Scanning before you share
The Code Secret Scanner runs entirely in your browser, which matters: sending your code to an online scanner would be its own leak.
- Paste the text you are about to share, or pick files or a whole project folder. Build folders, node_modules, .git and binary files are skipped.
- Read the summary: high, medium and low counts, then each finding with file, line, column and a masked value.
- Dismiss false alarms with one click, or add fragments to an ignore list. Lines marked secret-scan:ignore or gitleaks:allow are skipped too.
- Share the redacted version. Copy the text with every secret replaced by a label such as [REDACTED:aws-access-key], or download redacted files as a ZIP.
- Keep a report as CSV, or as SARIF to open the findings in VS Code or GitHub code scanning.
When the scanner finds a real key
Act in this order:
- Revoke or rotate the key in the provider's dashboard. This is the only step that actually stops misuse.
- Check for use: cloud providers have access logs (CloudTrail on AWS, audit logs elsewhere), and payment providers list API requests.
- Remove it from the code and load it from an environment variable or a secret manager instead.
- Clean history if it was committed. Deleting the line in a new commit leaves the key in git history. Tools such as git filter-repo rewrite history, but assume the key is already public once it has been pushed.
Skipping step one is the most common mistake. A key that has been posted anywhere public should be treated as compromised, even if you deleted the post seconds later.
Preventing the next leak
- Keep secrets in .env files listed in .gitignore, and commit a .env.example with empty values instead.
- Use your platform's secret storage: GitHub Actions secrets, Vercel or Netlify environment variables, AWS Secrets Manager, Azure Key Vault or Doppler.
- Give keys the smallest permissions they need, and set spending limits where providers allow it.
- Add a pre-commit secret scan in your repository so mistakes are caught before they leave your machine.
- Before pasting code into any chat, ticket or forum, run it through a scanner. It takes seconds.
Knowing the limits
No scanner sees everything. A secret split across two strings, encoded in Base64 or using an in-house format can slip past both patterns and entropy. Treat a clean result as reassurance, not proof, and keep secrets out of source files by design. The scanner is also strictly defensive: it reads only what you give it and never tests whether a key works.



