From 901f932a89d71965877e2f527498a08c8496addb Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Fri, 22 Jan 2021 11:49:21 -0500 Subject: [PATCH] Add file type checking for unstaged commits (#512) --- scan/unstaged.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scan/unstaged.go b/scan/unstaged.go index 94112f70..c7fc35ba 100644 --- a/scan/unstaged.go +++ b/scan/unstaged.go @@ -57,6 +57,28 @@ func (us *UnstagedScanner) Scan() (Report, error) { if err != nil { continue } + + // Check if file is allow listed + if us.cfg.Allowlist.FileAllowed(filepath.Base(fn)) || + us.cfg.Allowlist.PathAllowed(fn) { + continue + } + // Check individual file path ONLY rules + for _, rule := range us.cfg.Rules { + if rule.HasFileOrPathLeakOnly(fn) { + leak := NewLeak("", "Filename or path offender: "+ fn, defaultLineNumber) + leak.Repo = us.repoName + leak.File = fn + leak.RepoURL = us.opts.RepoURL + leak.LeakURL = leak.URL() + leak.Rule = rule.Description + leak.Tags = strings.Join(rule.Tags, ", ") + leak.Log(us.opts) + scannerReport.Leaks = append(scannerReport.Leaks, leak) + continue + } + } + if _, err := io.Copy(workTreeBuf, workTreeFile); err != nil { return scannerReport, err }