fix: global commit allowlist silently bypassed due to misscoped continue
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in sources/git.go at the global allowlist loop described in the issue, then trace how each diff file proceeds to commitInfo construction and scanning. Reproduce the case with a commit SHA in a global [[allowlists]] block and run gitleaks git; done means the allowlisted commit produces no findings and is not scanned.
Written by the indexing model from the issue text.
Description
Description
Global [[allowlists]] entries with commits = [...] are silently ignored during gitleaks git scans. The commit is logged as skipped but is fully scanned anyway, producing findings that should be suppressed.
Root Cause
In sources/git.go, the continue statement inside the allowlist loop only advances to the next allowlist entry — it does not skip the outer diff-file processing:
// BEFORE (buggy)
for _, a := range s.Config.Allowlists {
if ok, c := a.CommitAllowed(gitdiffFile.PatchHeader.SHA); ok {
logging.Trace().Str("allowed-commit", c).Msg("skipping commit: global allowlist")
continue // ← only continues inner for-loop, not the outer select/for
}
}
// commitInfo build and goroutine launch always happen regardless
After the inner for loop completes, execution falls through unconditionally to build commitInfo and launch the scanning goroutine for every commit — including ones that matched the allowlist.
Steps to Reproduce
- Create a repo with at least one commit containing a secret
- Add a global
[[allowlists]]block to your config with that commit's SHA:[[allowlists]] commits = ["<sha-of-commit-with-secret>"] - Run
gitleaks git
Expected: No findings reported (commit is allowlisted)
Actual: Finding is reported; trace log says "skipping commit: global allowlist" but the commit is still scanned
Fix
Use a boolean flag to escape the allowlist loop and then continue the outer loop:
// AFTER (fixed)
commitAllowed := false
for _, a := range s.Config.Allowlists {
if ok, c := a.CommitAllowed(gitdiffFile.PatchHeader.SHA); ok {
logging.Trace().Str("allowed-commit", c).Msg("skipping commit: global allowlist")
commitAllowed = true
break
}
}
if commitAllowed {
continue // ← correctly skips to next diff file
}
Environment
- Affects all versions of gitleaks that include global
[[allowlists]]commit support - Rule-level
[[rules.allowlists]]with commits is not affected (different code path indetect.go)
- Dominant language
- Go
- Stars
- 29.4k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gitleaks/gitleaks
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-2 days Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in gitleaks/gitleaks
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100