# 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: 1. **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. 2. **Decode** — TruffleHog decodes Base64, UTF-16 and escaped-Unicode substrings and unpacks archives (ar/deb, zip, tar…) before matching. 3. **Verify** — a stateless, read-only call to the provider (e.g. Doppler `GET /v3/me`) decides live vs dead. Verification is detector-specific: Zenscrape returns `429` for a valid but rate-limited key, Braintree returns `200` with 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: ```bash 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.sarif ``` Inline 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.json` leaks, 63% of occurrences were generic (passwords, bearer tokens, JWTs, user/pass pairs); Apiiro measured Gitleaks + TruffleHog together missing 1 in 5 leaking files. ## 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 - [[raw/trufflesecurity.com/how-trufflehog-verifies-secrets-4077|How TruffleHog Verifies Secrets]] - [[raw/trufflesecurity.com/secret-scanning-encoded-and-archived-data-4076|Secret Scanning Encoded and Archived Data]] - [[raw/github.com/gitleaks-find-secrets-with-gitleaks-2775|Gitleaks - Find Secrets with Gitleaks]] - [[raw/github.com/trufflehog-find-verify-and-analyze-leaked-credentials-2776|TruffleHog - Find, Verify, and Analyze Leaked Credentials]] - [[raw/appsecsanta.com/gitleaks-vs-trufflehog-2026-benchmarks-appsec-santa-4491|Gitleaks vs TruffleHog 2026 Benchmarks]] - [[raw/rafter.so/rafter-detect-secrets-vs-gitleaks-vs-trufflehog-4492|Rafter: detect-secrets vs gitleaks vs TruffleHog]] - [[raw/aikido.dev/better-generic-secrets-detection-starts-with-finding-non-secrets-10741|Better generic secrets detection starts with finding non-secrets]] - [[raw/docs.github.com/about-secret-scanning-github-docs-4504|About secret scanning (GitHub Docs)]] - [[raw/github.blog/github-found-39m-secret-leaks-in-2024-the-github-blog-4711|GitHub Found 39M Secret Leaks in 2024]] - [[raw/docs.gitlab.com/secret-detection-gitlab-docs-4502|Secret detection (GitLab Docs)]] - [[raw/unit42.paloaltonetworks.com/from-exposure-to-lockdown-how-aws-neutralizes-compromised-iam-credenti-12067|From Exposure to Lockdown: How AWS Neutralizes Compromised IAM Credentials]] - [[raw/peris.ai/26-400-working-keys-in-7-25m-repos-deleting-from-git-does-not-revoke-13287|26,400 working keys in 7.25M repos]] - [[raw/blog.gitguardian.com/claude-code-settings-local-json-secrets-17-months-of-exposure-on-githu-13955|Claude Code settings.local.json Secrets: 17 Months of Exposure]] - [[raw/thehackernews.com/the-state-of-secrets-sprawl-2026-9-takeaways-for-cisos-3777|The State of Secrets Sprawl 2026: 9 Takeaways for CISOs]] - [[raw/trufflesecurity.com/github-comments-leak-live-api-keys-4075|GitHub Comments Leak Live API Keys]] - [[raw/github.com/github-trufflesecurity-trufflehog-burp-suite-extension-official-truffl-6946|trufflehog-burp-suite-extension]] - [[raw/krebsonsecurity.com/cisa-admin-leaked-aws-govcloud-keys-on-github-8102|CISA Admin Leaked AWS GovCloud Keys on Github]] - [[raw/flare.io/thousands-of-secrets-exposed-on-docker-hub-4067|Thousands of Secrets Exposed on Docker Hub]] - [[raw/trufflesecurity.com/trufflehog-the-chrome-extension-6955|TruffleHog The Chrome Extension]]