Secrets detection
Secrets detection: finding passwords and keys in code
Secrets detection checks code and repository history for passwords, tokens, API keys, connection strings and private keys that ended up there.
A secret that was committed once stays in git history even after it is removed from the file. A found key must be revoked and reissued. Erasing it is not enough.
How it works
- Signatures of known formats: cloud and payment provider keys, GitHub tokens, JWTs, private keys.
- Entropy analysis: finding random strings that look like a secret.
- Scanning the whole commit history, not only the current version.
- Pre-commit checks, so the secret never reaches the repository.
Tools
gitleaksTruffleHogdetect-secrets
Questions and answers
What if a secret is already in the repository?
Revoke and reissue the key immediately. Cleaning git history helps but comes second, because copies of the repository may already be out there.
Where should secrets be stored?
In a secrets store (HashiCorp Vault, cloud KMS or Secrets Manager), issued to the application at runtime.