Skip to content

ci(gitleaks): scan commit messages, not just diffs#126

Merged
fitz123 merged 1 commit into
mainfrom
gitleaks-scan-commit-messages
May 18, 2026
Merged

ci(gitleaks): scan commit messages, not just diffs#126
fitz123 merged 1 commit into
mainfrom
gitleaks-scan-commit-messages

Conversation

@fitz123
Copy link
Copy Markdown
Owner

@fitz123 fitz123 commented May 18, 2026

Summary

  • gitleaks-action@v2 runs gitleaks in git mode, which only scans diffs. Verified empirically: a commit whose message contains a PII string slips past the existing CI scan with "no leaks found".
  • Add a second pass: extract every commit message in the event's range with git log --format='%H%n%B%n---DELIM---', then run gitleaks detect --no-git --source <tmpdir> against the dumped file using the same .gitleaks.toml already fetched for the diff scan.
  • Both passes run unconditionally (if: always()) so one failure does not mask the other.
  • Mirrors the .git/hooks/pre-push two-pass logic already added in the bb-dpi caller repo; CI and local now have the same coverage.

Test plan

  • PR with clean diff + PII commit message — fixture: commit message body containing бастеркиттон.рф. Result: exit 1, "leaks found: 1", IDN string redacted in output.
  • Clean PR — fixture: two ordinary commits. Result: exit 0, both messages dumped (161 bytes scanned), "no leaks found". Also validated end-to-end against bb-dpi via a draft PR pinned to this branch — new step ran in CI on ubuntu-latest, gitleaks 8.21.4 installed cleanly, "no leaks found".
  • Fork PR (no CONFIG_PAT) — fixture: same range with .gitleaks.toml removed before the run. Result: shell branch falls through to gitleaks detect ... --redact (no --config), default rules apply, exit 0.
  • push event, brand-new branch (zero before SHA) — 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.
  • push event, normal push (non-zero before) — fixture: PUSH_BEFORE=HEAD~2, PUSH_AFTER=HEAD. Result: range="$PUSH_BEFORE..$PUSH_AFTER", only the 2 commits in the push scanned, baseline excluded.
  • Empty range (no-op push, 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-handles rule (in fitz123/gitleaks-config) matches @<word> inside a workflow uses: 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.

`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.
Copilot AI review requested due to automatic review settings May 18, 2026 09:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/push event metadata (handling new-branch pushes with zero SHA), dumps git log bodies to a tmp file, and runs gitleaks detect --no-git, using the fetched/baseline .gitleaks.toml when 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.

@fitz123 fitz123 merged commit e4d7be3 into main May 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants