Skip to content

Scope the gitleaks scan to HEAD's history (#1024) - #1031

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1024
Oct 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1024

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1024

Problem

The Secret Scan job checks out with fetch-depth: 0 (fetches every branch) and ran gitleaks detect --source . with no --log-opts, which gitleaks 8.21.2 turns into git log --all. So one branch's finding failed every open PR's Secret Scan (fix/968's old commit 4453716 failing #1011 and fix/1015).

Change

  • security.yml: gitleaks git --log-opts="HEAD" --redact --verbose --exit-code 1 .. Checkout stays fetch-depth: 0 so leaked-then-removed secrets are still caught. On pull_request HEAD is refs/pull/N/merge, whose ancestry is main plus every PR commit; on push/schedule it is main's full history. Same pinned, hash-verified gitleaks 8.21.2; no action pins changed.
  • workflow_secret_scan_test.go (new gate): parses security.yml, and fails if any gitleaks invocation lacks --log-opts="HEAD", widens it (--all/--branches/--remotes/--glob), doesn't scan git history (dir/--no-git), runs in a job without an actions/checkout with fetch-depth: 0, or if no gitleaks invocation is found at all. Comment lines are dropped so the explanatory comment cannot satisfy it.
  • CHANGELOG entry under Fixed.

Verification (local, pinned gitleaks 8.21.2 darwin_arm64, sha256 checked against the release's checksums.txt)

In a fresh clone of this repo with all remote branches (like CI), a throwaway local branch added a generated AKIA… fake key (never pushed; branch and clone deleted afterwards):

invocation checkout result
old detect --source . main leaks found: 1 (737 commits, the other branch's)
new git --log-opts=HEAD main no leaks (631 commits)
new temp branch (key in HEAD) leaks found: 1
new temp branch after a commit removing the key leaks found: 1
new --no-ff merge of temp branch into main (like refs/pull/N/merge) leaks found: 1

Gate watched failing against four compiling reverts: old invocation, fetch-depth: 1, --log-opts="HEAD --all", and deleting the scan line. make check passes apart from the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker; make check-nested and make check-tidy pass.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The Secret Scan job checked out with fetch-depth 0, which fetches every
branch, and ran `gitleaks detect` with no --log-opts, i.e. `git log --all`.
One open PR's finding therefore failed every other PR's Secret Scan until that
branch was force-pushed (seen with fix/968's old commit failing #1011).

Run `gitleaks git --log-opts="HEAD"` instead, keeping the full-history checkout:
on pull_request HEAD is the merge commit, so main plus every PR commit is
scanned (a secret added and removed within the PR is still caught); on push and
schedule it is main's full history.

workflow_secret_scan_test.go parses security.yml and fails if the gitleaks
invocation loses --log-opts="HEAD", widens with --all/--branches/--remotes/
--glob, stops scanning git history, its job loses fetch-depth 0, or no gitleaks
invocation is found.

Fixes #1024
@scttfrdmn
scttfrdmn merged commit ce824c3 into main Oct 16, 2026
6 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1024 branch October 16, 2026 17:34
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.

gitleaks job scans every branch, so one branch's finding fails every open PR's Secret Scan

1 participant