Automated bots scan public commits continuously for exposed API credentials. Following GitHub Secret Scanning best practices prevents accidental credential leaks before they reach production.
1. Prevention Checklist (Use Fake Placeholders Only)
- Never Hardcode Real Keys: Store fake placeholders like
API_KEY=sk-example-000000000000in.env.exampleand keep real.envfiles in.gitignore. - Enable Push Protection & Pre-Commit Hooks: Use GitHub Push Protection and
gitleakslocally to block commits containing secrets. - Set Hard Spending Caps: Configure monthly budget limits and alerts in every AI/cloud dashboard.
2. Rotation vs Removal (Critical Distinction)
Deleting an exposed key from your code in a new commit does not make it safeāthe old key remains readable in Git history. Always revoke and rotate the compromised key in the provider dashboard first, then audit billing logs before cleaning Git history.