Fix builtin_scan to respect ScanScope (--staged/--range) - #21
Merged
Conversation
builtin_scan() ignored ScanScope entirely and always walked the whole target tree, so --staged (and --range) still let the always-on built-in scanner flag secrets sitting in unstaged/untracked files, defeating the "only check what I'm about to commit" contract. Give builtin_scan a scope parameter and branch like try_gitleaks/ try_trufflehog already do: Staged scans only `git diff --cached --name-only` output, Range scans only `git diff --name-only <range>` output, Filesystem/History keep the existing full working-tree walk. Fixes #20 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
builtin_scan()had noscopeparameter and always walked the entire target tree, so--staged(and--range) still let the always-on built-in scanner flag secrets in unstaged/untracked files — breaking the "only check what I'm about to commit" contract.builtin_scannow takesscope: &ScanScopeand branches the same waytry_gitleaks/try_trufflehogalready do:Stagedscans onlygit diff --cached --name-onlyoutput,Rangescans onlygit diff --name-only <range>output,Filesystem/Historykeep the existing full working-tree walk (builtin has no historical-content path).scan_file_intoso the size-cap/binary/UTF-8 filters and match logic stay identical across the walk-based and git-file-list-based branches.Fixes #20
Test plan
cargo test— 25/25 pass, including newbuiltin_scan_staged_scope_only_scans_staged_filesregression test (asserts a secret in an unstaged file is not reported underScanScope::Staged, only the staged file's secret is; sanity-checksFilesystemscope still sees both).cargo build --all-targetscargo fmt --all -- --checkcargo clippy --all-targets— no new warnings; the 10 pre-existing warnings (8&PathBuf/&Pathinmain.rs,Defaultderive +hash_onein untouchedscanners.rslines) are unchanged frommainand out of scope for this fix.