Stop Leaking API Keys: A Practical Secrets Guide
Why hardcoding and committing secrets (CWE-798) is dangerous, and how to fix it with env vars, secret managers, pre-commit scanning, and rotation.
- Hardcoded credentials (CWE-798) map to OWASP A07:2021 and are trivially harvested from repos, bundles, and images.
- Git history is forever: deleting a secret in a later commit does not remove it, so a leaked key is compromised the moment it is pushed.
- Load secrets from the environment or a secret manager (AWS Secrets Manager, GCP Secret Manager, HashiCorp Vault), never from source.
- Add a pre-commit secret scanner (gitleaks/trufflehog) so keys are blocked before they ever reach history.
- After a leak, rotate first and investigate second: revoke the key, issue a new one, then scrub history.
Guard what you build. Prove what you guard. This app needs JavaScript to run an audit; please enable it.