Secret Scanning
Automated detection of credentials in code, history, artifacts and collaboration tools, using provider-specific patterns, generic/entropy rules and live verification against the issuing service.
How it works
A detector has up to three stages:
- Match — a regex per credential type (TruffleHog ships 800+ detectors; Gitleaks 150+ rules). Prefixed formats (
AKIA,ABSK,AIza…,ghp_) are high-precision; generic rules (keyword near a high-entropy string) catch bare passwords and custom tokens at the cost of noise. - Decode — TruffleHog decodes Base64, UTF-16 and escaped-Unicode substrings and unpacks archives (ar/deb, zip, tar…) before matching.
- Verify — a stateless, read-only call to the provider (e.g. Doppler
GET /v3/me) decides live vs dead. Verification is detector-specific: Zenscrape returns429for a valid but rate-limited key, Braintree returns200with validity in the JSON body, and DB connection strings need a real driver connection. A network error is “unknown”, not “invalid”.
Verification is what makes findings actionable, but it is not sufficient: GitGuardian reports 46% of critical secrets are missed by validation-only prioritization, because many internal or generic credentials cannot be verified automatically.
Where to scan
| Point | Tooling | Catches | Misses |
|---|---|---|---|
| Pre-commit | Gitleaks, detect-secrets, TruffleHog via pre-commit | Secret before it enters history | SKIP=gitleaks, unhooked clones, AI agents committing |
| Push protection | GitHub, GitLab secret push protection | Known provider formats at push | Encoded secrets; GitHub skips very large pushes (thousands of files / >50 MB repo) |
| CI / pipeline | TruffleHog --fail, Gitleaks action, GitLab pipeline detection | Branch diffs, full history | Anything outside git |
| Platform-wide | GitHub secret scanning (all branches, full history, issues, PRs, Discussions, wikis, secret gists), partner program, validity checks | Leaks in comments and metadata | Private repos without Secret Protection licence |
| Artifacts | trufflehog docker, S3/GCS sources | Image layers, buckets | — |
| Collaboration / endpoint | GitGuardian, TruffleHog Slack/Jira sources | 28% of incidents that never touch code | — |
Commands:
gitleaks git -v --redact # history
gitleaks git --baseline-path gitleaks-report.json --report-path new.json # brownfield
gitleaks dir ./build # files / bundles
trufflehog git file://. --since-commit main --branch feature-1 --results=verified,unknown --fail
trufflehog github --org=acme --exclude-archived
trufflehog docker --image acme/app:latest --results=verified
trufflehog filesystem . --sarif --no-verification > results.sarifInline suppressions: gitleaks:allow comment; a .gitleaks.toml for custom rules.
For testing, the TruffleHog Burp extension scans proxied traffic every ~10s for 800+ secret types (with verification), and the TruffleHog Chrome extension flags keys and exposed .git/.env in client-side code. See Burp Suite Extensions and JavaScript Analysis.
Tool comparison (OSS)
- git-secrets — basic, AWS-focused.
- detect-secrets — plugin + baseline model, good for brownfield, higher FP rate.
- Gitleaks — fast regex, SARIF output, ideal pre-commit; maintainer has frozen features and moved to Betterleaks.
- TruffleHog — verification, many sources (git, GitHub org, S3, GCS, Docker, Slack, Jenkins).
- Common pattern: Gitleaks pre-commit + TruffleHog in CI.
Scanners disagree a lot: on 7.25M Gitee repos TruffleHog found 12,737 working credentials and Kingfisher 14,664, with only 1,001 in common — run more than one.
Precision and noise
- Publishable keys (e.g. Stripe publishable key) look like secrets. Betterleaks added a publishable-credential denylist: −2.37% false positives (27,886 fewer findings on 100 GB of Common Crawl) for ~5% more scan time. Some “public” keys still carry risk and need per-provider review.
- GitHub cites an academic benchmark giving its Secret Protection 75% precision vs 46% for the next tool (vendor-cited).
- Generic detectors matter: in Claude Code’s
settings.local.jsonleaks, 63% of occurrences were generic (passwords, bearer tokens, JWTs, user/pass pairs); Apiiro measured Gitleaks + TruffleHog together missing 1 in 5 leaking files.
Benchmarking scanners
GitGuardian’s method for comparing engines without biasing the result (vendor-authored, so read it as method, not verdict) (GitGuardian):
- Label the union of all findings. “Does B find what A found?” only measures B’s recall on A’s output.
- Don’t use valid-only sets. Generic secrets (passwords, custom tokens, internal keys) can’t be validity-checked and are ~70% of GitGuardian’s customer detections. Avoid hand-made dummies (
password123,sk_test_XXXX), which good engines ignore by design. Prefer sampled public GitHub data: several time windows, one patch per repo, deduplicated, scanned commits recorded. - Run fairly: pin versions and detector tiers (specific / generic / AI / push-only), identical input, results as the user sees them after validity checks and exclusions, and run twice to check determinism.
- Match on location plus overlap, not exact string: multi-part secrets, different boundaries (whole connection string vs password), normalised quoting/encoding; check every reported value exists verbatim, since LLM engines can truncate or invent strings.
- Three labels: real, test/example/intentionally public, false positive. An LLM judge scales labelling if blinded to the engine, given the same context a human gets, and run with a different model than any LLM engine under test; validate a sample by hand.
- Report precision and recall together, split generic vs specific and by category, weight by impact, flag categories under ~100 secrets, and put cost and latency next to accuracy. GitGuardian’s numbers: its rule engine ~100 MB/s per thread vs ~9 MB/s for the fastest LLMs at full parallelism; ~0.5 TB/day would cost $10,000+/day with an LLM vs tens of cents with rules. Pre-commit needs ~1 s answers.
- Look beyond detection: validity checks, prioritisation, permission/scope analysis, revoke-from-tool, and non-git coverage.
Notable cases
- CISA “Private-CISA” repo (2025–26) — the contractor’s commit logs show GitHub’s default secret-blocking was explicitly disabled; GitGuardian’s public monitoring caught AWS GovCloud admin keys and a plaintext password CSV. See Leaked Cloud Credentials.
- GitHub comments — TruffleHog sampled PR/issue comments and found 721 live keys; 97% were posted by humans, mostly with no relation to the repo.
- Docker Hub — Flare found 10,000+ images leaking secrets in a month; 42% held five or more.
Defenses (program level)
- Layer it: pre-commit → push protection → CI → org-wide + public monitoring → artifacts/collab tools/endpoints.
- Route verified findings straight into Credential Rotation and Revocation; measure time-to-revoke, not time-to-close.
- Add custom patterns for internal token formats; give internal tokens unique prefixes so they become high-precision detectors.
Related
- Secrets Management
- Hardcoded Secrets · Secrets in Git History · Developer Workstation Secrets
- CI-CD Pipeline Attacks · Burp Suite Extensions
Sources
- How TruffleHog Verifies Secrets · original
- Secret Scanning Encoded and Archived Data · original
- Gitleaks - Find Secrets with Gitleaks · original
- TruffleHog - Find, Verify, and Analyze Leaked Credentials · original
- Gitleaks vs TruffleHog 2026 Benchmarks · original
- Rafter: detect-secrets vs gitleaks vs TruffleHog · original
- Better generic secrets detection starts with finding non-secrets · original
- About secret scanning (GitHub Docs) · original
- GitHub Found 39M Secret Leaks in 2024 · original
- Secret detection (GitLab Docs) · original
- From Exposure to Lockdown: How AWS Neutralizes Compromised IAM Credentials · original
- 26,400 working keys in 7.25M repos · original
- Claude Code settings.local.json Secrets: 17 Months of Exposure · original
- The State of Secrets Sprawl 2026: 9 Takeaways for CISOs · original
- GitHub Comments Leak Live API Keys · original
- trufflehog-burp-suite-extension · original
- CISA Admin Leaked AWS GovCloud Keys on Github · original
- Thousands of Secrets Exposed on Docker Hub · original
- TruffleHog The Chrome Extension · original
- GitGuardian — How to Benchmark Secret Detection Vendors Without Fooling Yourself · original