Use this when a secret may have leaked into code, logs or images.
Secrets Leakage
Secrets leakage happens when credentials end up in Git repositories, logs, container images, tickets or chat. Use secret scanning, revoke and rotate immediately on discovery, and check for misuse.
1. Leaks: code repos, logs, images, tickets, chat.
2. Scan continuously (pre-commit and CI).
3. On leak: revoke/rotate first, then clean history.
4. Check for misuse.
5. Root-cause the process.
secret exposed → detected → revoked/rotated → investigated
Context & applicabilityCommon mistakes · platform/version boundaries
- Deleting the commit and assuming the secret is safe.
- Rotating the secret but not checking logs for misuse.
- Secrets in CI logs, container layers and crash reports.
- Not using pre-commit hooks or push protection.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Revoke first, then clean up.
- History in Git keeps the secret.
- Check whether it was used.
gitleaks detect --source . --log-opts=--all— full history scan- GitHub secret scanning alerts — provider detection
- Incident procedure: revoke, rotate, investigate — response
ReferenceWhy it matters1 section · depth on demand
Prevention and response
Prevent: pre-commit hooks and push protection (gitleaks, TruffleHog, GitHub secret scanning), no secrets in Dockerfiles or CI logs (mask variables), scan images and artefacts.
Respond: treat a leaked secret as compromised — revoke and rotate immediately (deleting the commit is not enough; Git history and forks keep it), then check logs for use of the secret.
ReferenceImportant terms & boundaries2 sections · depth on demand
Detection tools
| Tool | Use |
|---|---|
| gitleaks, trufflehog | Scan repositories and history |
| GitHub secret scanning / push protection | Blocks known token formats on push |
| detect-secrets (pre-commit) | Developer machines |
| Cloud provider leak alerts | Revoke exposed keys automatically |
After a leak, revoke first; rewriting Git history does not remove forks and clones.
In depth
Secrets leakage is the exposure of credentials through code repositories, logs, tickets, chat, container images, CI output or public storage. Leaked secrets are found and abused by automated scanners within minutes of appearing in public repositories.
Prevention and detection:
| Measure | Tool examples |
|---|---|
| Pre-commit scanning | gitleaks, detect-secrets, trufflehog |
| Repository scanning | GitHub secret scanning/push protection, GitLab secret detection |
| Log masking | CI masking, application log filters |
| Image scanning | Trivy, registry scanners |
Response to a leak: revoke and rotate the secret immediately (deleting the commit is not enough — history and forks keep it), check usage logs for misuse, and find out how it leaked.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Secrets Management → Secrets Leakage. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html · confidence 94%