Short version. Scanning git history for secrets produces an inventory of strings that matched a pattern, while closing the exposure needs a per-credential answer from the provider. Two queries carry most of the work: GET /orgs/{org}/secret-scanning/alerts?validity=active&resolution=revoked names every credential somebody already marked revoked that the provider says still works, and trufflehog git file://. --results=verified --fail turns a hunch into exit code 183 or 0.

This is written for the person who has to answer the auditor, not the person who runs the tool. GitGuardian's State of Secrets Sprawl 2026, published 17 March 2026, counted 28,649,024 new hardcoded secrets on public GitHub during 2025, a 34% rise, with AI-service credentials at 1,275,105 (up 81%). The number that should set your budget sits further down that report: 64% of the credentials GitGuardian confirmed valid in 2022 were still unrevoked in 2026. Detection stopped being the bottleneck some years ago.

I picked up the habit of distrusting inventories on an end-of-life Node 20 box, where a behavioural Brotli probe returned errno=-9 out of the decoder while the installed version string disagreed with the runtime in both directions across distros. A pattern match in a repo tells you a string exists. Only the issuing provider tells you whether it still opens anything.

An assistant will answer "how do I scan git history for secrets" correctly and still leave the exposure open, for three reasons you can check: gitleaks declared itself feature complete and its author shipped a successor in March 2026, GitHub's validity data has a documented blind spot for generic and custom patterns, and rewriting history with git filter-repo does not remove the object from a GitHub fork network. Under all eleven tips below sits one structural fix, which is credentials that expire without anyone remembering to kill them, the way npm's OIDC trusted publishing replaces a static publish token.

Commit carrying a live keyPush to repo or forkFork-network object storeGH Archive push eventforce-push or delete the forkRef removed, object retainedFetchable by SHA, unauthenticatedDoes the credential still authenticate?Exposure is liveExposure closed"yes""no, rotated at the provider"

The tips

1. Run the query that catches a rotation nobody performed. GitHub's alert object carries both validity (active, inactive, unknown) and resolution (false_positive, wont_fix, revoked, used_in_tests). resolution: revoked is a human claim; validity: active is the provider's answer. Rows where the two disagree are the finding, and the secret scanning REST reference lets both filters compose on one call.

gh api -X GET /orgs/ACME/secret-scanning/alerts -f validity=active -f resolution=revoked --paginate --jq '.[] | [.secret_type, .repository.full_name, .html_url] | @tsv'

2. Budget for iterating orgs, because there is no enterprise rollup. The same reference documents alert listing at repository and organization scope only, and the repository endpoint returns 404 for public repositories. A fleet-wide posture report is a loop over GET /enterprises/{ent}/orgs plus a join you maintain yourself, so cost it as code you own rather than a dashboard you buy.

3. Treat unknown as two different facts before it reaches a slide. GitHub's table maps unknown to both "GitHub does not support validation checks for this token type yet" and "GitHub could not verify this secret", and the supported patterns reference states that validity checks are not supported for generic patterns or for passwords. "0 active secrets" is therefore compatible with every custom-pattern alert you have parked permanently at unknown. Group them by type and compare that list against the supported-patterns page: a type missing from the page was never checked, while a supported type at unknown failed its check.

gh api -X GET /orgs/ACME/secret-scanning/alerts -f validity=unknown --paginate --jq 'group_by(.secret_type)[] | [.[0].secret_type, length] | @tsv'

4. Audit the bypasses before you audit the findings. Push protection holds only where nobody waved it through. is_bypassed=true returns exactly the alerts that exist because someone overrode the block, and each alert carries push_protection_bypassed_by and push_protection_bypass_request_reviewer_comment for whatever conversation followed.

gh api -X GET /orgs/ACME/secret-scanning/alerts -F is_bypassed=true --paginate --jq '.[] | [.push_protection_bypassed_at, .push_protection_bypassed_by.login, .html_url] | @tsv'

5. Widen the walk, because gitleaks follows refs. Gitleaks drives git log -p and exposes the walk through --log-opts, so coverage is whatever you point it at. Scan everything reachable, then deal separately with what no ref reaches:

gitleaks git . --log-opts="--all --full-history" --redact --report-path leaks.json
git fsck --unreachable --no-reflogs | awk '$2=="blob"{print $3}' | xargs -r -n1 git cat-file -p | gitleaks stdin

This is the one claim here I could not fully settle: the README documents the walk as git log -p plus --log-opts, and I have not confirmed from the project's own tracker that unreachable blobs are skipped in every mode. Settle it in two runs. Commit a canary string, run the first command and record the finding count, then git reset --hard HEAD~1 and run both commands again. If the count drops on the first and returns on the second, the gap is real in your version.

6. A pre-commit hook cannot see the commit that already leaked. Gitleaks deprecated detect and protect in v8.19.0 in favour of git, dir and stdin, so the current hook form is gitleaks git --pre-commit --staged --redact. It guards the next commit only, it runs client-side, and --no-verify removes it. Server-side push protection is the control that leaves an audit trail; the hook is a courtesy to the committer.

7. Your CI history scan is probably a one-commit scan. actions/checkout clones with fetch-depth: 1 by default, which leaves a history scanner diffing a single commit while the job reports success. Set fetch-depth: 0, and fail on verified results rather than on every result, so the gate means "a credential authenticated" instead of "a regex matched":

- uses: actions/checkout@v5
  with: { fetch-depth: 0 }
- run: trufflehog git file://. --since-commit ${{ github.event.before }} --results=verified --fail

8. Go read your own force-pushes, because researchers already read them. Truffle Security's force-push research keys on push events containing zero commits, the fingerprint of a rewritten branch, and ships a Force Push Scanner alongside a public BigQuery table of those events; the guest researcher behind it reported roughly $25,000 in bounties from secrets recovered that way. The pre-force-push SHA sits in the event payload, and the object it points at is frequently still fetchable.

9. Stop budgeting for history rewrites and start budgeting for rotation. Truffle Security's 2024 CFOR disclosure showed commit data staying reachable through a fork network after the fork is deleted, with GitHub treating that as expected platform behaviour and access requiring only the hash. git filter-repo keeps its place in repository hygiene without being a remediation, since the provider-side credential is the only part of this you control. What an attacker does with a recovered string is unremarkable: Sentry MCP's public DSN reached a shell.

10. A cloud-provider quarantine will look like remediation. Palo Alto Unit 42 reported pushing an AWS access key to a public repo and seeing AWSCompromisedKeyQuarantineV3 attached within about 10 seconds, with CloudTrail giving no indication that the action was automated by AWS. The policy denies a specific action set, and the key still authenticates. Find the attachments in your own trail, then delete the key:

aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=AttachUserPolicy --query 'Events[].CloudTrailEvent' --output text | grep -c CompromisedKeyQuarantine

11. Pick the scanner for the audit you are facing. The gitleaks README now states that the project is feature complete and that future releases carry security patches only. Its original author shipped Betterleaks, whose v1.1.0 added CEL-expressed validation able to call the provider API, with provider auto-revocation named as a v2 goal rather than shipped behaviour. Choose on what you must evidence, not on GitHub stars:

Needgitleaks 8.xBetterleaks 1.xTruffleHogGitHub secret scanning
Blocks a push server-sidenononoyes
Confirms the credential still worksnoCEL validator--results=verifiedvalidity field
Covers generic/custom patternsyesyesyesyes, without validity
Receiving new features in 2026patches onlyyesyesyes

Wrap-up

One habit outranks every scanner choice: make the provider, not the diff, the authority on whether a credential is live, and record that answer per credential with a date and a named owner. The sweep itself is cheap, and the real cost sits in sequencing rotations against systems that break when the old key dies, then finding the human who can approve that break. Start with one organization and a count you can put in front of someone:

gh api -X GET /orgs/ACME/secret-scanning/alerts -f validity=active --paginate --jq '.[].html_url' | wc -l