Prompt
How do I quickly revoke a leaked API key and find every place it was used?
Latest observation
Here’s a fast incident-response playbook for a leaked API key.
1) Revoke it immediately
Do this first, before searching too much.
- Disable / delete the key in the provider console.
- If the provider supports it, rotate the key:
- create a new key,
- deploy it,
- then revoke the old one.
- If the key is tied to a service account or bot, check what permissions that identity has and reduce them if needed.
2) Assume it was exposed publicly
Treat it as compromised if it was in:
- GitHub / GitLab / Bitbucket
- CI logs
- Slack / Discord / email
- browser console / frontend bundle
- issue trackers
- pasted into tickets or docs
3) Find every place it was used
Search in these places:
Code and config
Use a repo-wide search:
grep -R "PASTE_KEY_PREFIX_OR_LAST_4_CHARS" .
Better: search for likely variable names and key patterns:
rg -n "api[_-]?key|secret|token|authorization|bearer" .
If you know the exact key, search for it directly:
rg -n "sk_live_ABC123..." .
Git history
The key may have been removed from current files but still exist in history:
git log -S "PASTE_KEY_OR_UNIQUE_FRAGMENT" --all --oneline
git grep "PASTE_KEY_OR_UNIQUE_FRAGMENT" $(git rev-list --all)
If you want the exact commits where it appeared:
git log -p -S "PASTE_KEY_OR_UNIQUE_FRAGMENT" --all
CI/CD and build logs
Check:
- GitHub Actions
- GitLab CI
- Jenkins
- CircleCI
- Buildkite
- deployment logs
Search pipeline logs for:
- the key itself,
- its last 4–8 chars,
- the secret name / env var name.
Secret managers and environment variables
Check:
- AWS Secrets Manager / Parameter Store
- GCP Secret Manager
- Azure Key Vault
- Vault
- Kubernetes secrets
.envfiles and runtime config
Infrastructure and app telemetry
Look for usage in:
- application logs
- access logs
- API gateway logs
- cloud audit logs
- WAF logs
- provider usage dashboards
If the provider offers it, check:
- IP addresses
- timestamps
- user agents
- endpoint names
- usage volume
That tells you whether the key was used only by your app or possibly by someone else.
4) Search in your org quickly
If you have many repos, use org-wide search tools:
- GitHub code search
- GitHub secret scanning
- GitLab group search
ripgrepacross checked-out repos- a script to scan all repos for key patterns
Example local sweep:
find /path/to/repos -name ".git" -type d | while read d; do
repo="$(dirname "$d")"
echo "Scanning $repo"
rg -n "PASTE_KEY_OR_FRAGMENT" "$repo" >/dev/null && echo "MATCH in $repo"
done
5) Check for hardcoded copies and derived references
People often copy secrets into:
- test files
- example configs
- README snippets
- shell history
- notebooks
- Terraform/Helm charts
- Dockerfiles
Search for the key prefix, not just the full key, because copies may be truncated or masked.
6) After revocation, look for fallout
- Review provider logs for suspicious calls.
- Check billing for unexpected spikes.
- Check whether the leaked key had write/delete permissions.
- If it did, verify data integrity and resource changes.
7) Prevent it from happening again
- Store secrets in a secret manager, not in code.
- Use short-lived tokens where possible.
- Enable secret scanning and push protection.
- Restrict key scope and permissions.
- Separate dev/staging/prod keys.
- Rotate regularly.
- Add pre-commit hooks and CI checks for secret detection.
If you want the fastest practical path
- Revoke the key now.
- Search all repos and history for the exact key or unique fragment.
- Check CI logs and secret managers.
- Review provider access logs for usage from unknown IPs.
- Rotate any related credentials.
If you tell me the platform for the key (AWS, OpenAI, GitHub, Stripe, Google, etc.), I can give you the exact revoke-and-audit steps and the best logs to check.