ci(gitleaks): scan commit messages, not just diffs#126
Merged
Conversation
`gitleaks-action@v2` only scans diffs — verified empirically that v8 `git` mode does NOT inspect commit-message bodies. A PII string can be sneaked into CI by living in the commit message only. Add a second pass that extracts every message in the relevant range and runs `gitleaks detect --no-git` against them, using the same config as the diff scan. Mirrors the local pre-push hook so CI and local have the same coverage.
There was a problem hiding this comment.
Pull request overview
Adds a second gitleaks pass to the reusable CI workflow that scans commit messages, closing a gap where gitleaks-action@v2's git mode only inspects diffs. This mirrors the existing local pre-push hook so CI and local enforcement have equivalent coverage.
Changes:
- Adds an "Install gitleaks" step that downloads a pinned gitleaks 8.21.4 binary into
/tmp/gitleaks-bin. - Adds a "Scan commit messages for PII" step that derives a commit range from
pull_request/pushevent metadata (handling new-branch pushes with zero SHA), dumpsgit logbodies to a tmp file, and runsgitleaks detect --no-git, using the fetched/baseline.gitleaks.tomlwhen present. - Both new steps use
if: always()so a failure in pass 1 does not mask pass 2.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gitleaks-action@v2runs gitleaks ingitmode, which only scans diffs. Verified empirically: a commit whose message contains a PII string slips past the existing CI scan with "no leaks found".git log --format='%H%n%B%n---DELIM---', then rungitleaks detect --no-git --source <tmpdir>against the dumped file using the same.gitleaks.tomlalready fetched for the diff scan.if: always()) so one failure does not mask the other..git/hooks/pre-pushtwo-pass logic already added in the bb-dpi caller repo; CI and local now have the same coverage.Test plan
бастеркиттон.рф. Result: exit 1, "leaks found: 1", IDN string redacted in output.CONFIG_PAT) — fixture: same range with.gitleaks.tomlremoved before the run. Result: shell branch falls through togitleaks detect ... --redact(no--config), default rules apply, exit 0.pushevent, brand-new branch (zerobeforeSHA) — fixture:PUSH_BEFORE=000…0,PUSH_AFTER=<head>. Result:range="$PUSH_AFTER",git log "$range"walked the full ancestry, all reachable commits scanned, exit 0.pushevent, normal push (non-zerobefore) — fixture:PUSH_BEFORE=HEAD~2,PUSH_AFTER=HEAD. Result:range="$PUSH_BEFORE..$PUSH_AFTER", only the 2 commits in the push scanned, baseline excluded.before == after) — Result: early exit 0 with "No commits in range … — nothing to scan." log line.The bb-dpi e2e draft PR did surface one unrelated, pre-existing false positive: the
telegram-handlesrule (infitz123/gitleaks-config) matches@<word>inside a workflowuses: org/repo/...@<branchname>line. Worth a follow-up allowlist entry (uses:\s+\S+@), but separate from this PR — the new commit-message pass itself ran successfully.