Skip to content

Find, verify, and analyze leaked credentials

Change log order and path filtering.

Bill Rich206b99704b3f
diff --git a/pkg/engine/git.go b/pkg/engine/git.go
index 1bd9e4f6f..9f4c003e8 100644
--- a/pkg/engine/git.go
+++ b/pkg/engine/git.go
@@ -23,9 +23,7 @@ func (e *Engine) ScanGit(ctx context.Context, repoPath, gitScanBranch, headRef s
}
logOptions := &gogit.LogOptions{
- All: true,
- Order: gogit.LogOrderCommitterTime,
- PathFilter: func(s string) bool { return filter.Pass(s) },
+ All: true,
}
var sinceCommit, headCommit *object.Commit
diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.go
index 1fe946328..6265a4bdf 100644
--- a/pkg/sources/git/git.go
+++ b/pkg/sources/git/git.go
@@ -286,6 +286,10 @@ func (s *Git) ScanRepo(ctx context.Context, repo *git.Repository, scanOptions *S
breakIteration = true
}
+ if FilterCommitByFiles(commit, scanOptions.Filter) {
+ return nil
+ }
+
// TODO: Clean up this conditional mess.
if (scanOptions.SinceCommit != nil && commit.Hash == scanOptions.SinceCommit.Hash && !scanOneCommit) ||
(scanOptions.MaxDepth >= 0 && depth >= scanOptions.MaxDepth) {
@@ -580,3 +584,22 @@ func PrepareRepo(uriString string) (string, bool, error) {
log.Debugf("Git repo local path: %s", path)
return path, remote, nil
}
+
+func FilterCommitByFiles(commit *object.Commit, filter *common.Filter) bool {
+ fileCount := 0
+ fileIter, err := commit.Files()
+ foundErr := errors.New("file found")
+ err = fileIter.ForEach(func(file *object.File) error {
+ fileCount++
+ if filter.Pass(file.Name) {
+ return foundErr
+ }
+ return nil
+ })
+ // fileIter will return a "file found" "error" if any files match the filter. If there are no files, there will
+ // not be a match, but the commit should pass anyway in case we want to do something with the commit message.
+ if !errors.Is(err, foundErr) && fileCount > 0 {
+ return true
+ }
+ return false
+}
\ No newline at end of file
diff --git a/pkg/sources/git/scan_options.go b/pkg/sources/git/scan_options.go
index 2d0155b04..2abd4e9d1 100644
--- a/pkg/sources/git/scan_options.go
+++ b/pkg/sources/git/scan_options.go
@@ -45,8 +45,7 @@ func NewScanOptions(options ...ScanOption) *ScanOptions {
SinceCommit: nil,
MaxDepth: -1,
LogOptions: &git.LogOptions{
- All: true,
- Order: git.LogOrderCommitterTime,
+ All: true,
},
}
for _, option := range options {