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

PointToolingCatchesMisses
Pre-commitGitleaks, detect-secrets, TruffleHog via pre-commitSecret before it enters historySKIP=gitleaks, unhooked clones, AI agents committing
Push protectionGitHub, GitLab secret push protectionKnown provider formats at pushEncoded secrets; GitHub skips very large pushes (thousands of files / >50 MB repo)
CI / pipelineTruffleHog --fail, Gitleaks action, GitLab pipeline detectionBranch diffs, full historyAnything outside git
Platform-wideGitHub secret scanning (all branches, full history, issues, PRs, Discussions, wikis, secret gists), partner program, validity checksLeaks in comments and metadataPrivate repos without Secret Protection licence
Artifactstrufflehog docker, S3/GCS sourcesImage layers, buckets—
Collaboration / endpointGitGuardian, TruffleHog Slack/Jira sources28% 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.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.

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.

Sources