diff --git a/scan/commit.go b/scan/commit.go index 5b97d95e..6caaaeb4 100644 --- a/scan/commit.go +++ b/scan/commit.go @@ -42,6 +42,11 @@ func (cs *CommitScanner) SetRepoName(repoName string) { // Scan kicks off a CommitScanner Scan func (cs *CommitScanner) Scan() (Report, error) { var scannerReport Report + + if cs.cfg.Allowlist.CommitAllowed(cs.commit.Hash.String()) { + return scannerReport, nil + } + if len(cs.commit.ParentHashes) == 0 { facScanner := NewFilesAtCommitScanner(cs.opts, cs.cfg, cs.repo, cs.commit) return facScanner.Scan() diff --git a/scan/filesatcommit.go b/scan/filesatcommit.go index 0a226ea5..c79bc1b7 100644 --- a/scan/filesatcommit.go +++ b/scan/filesatcommit.go @@ -38,6 +38,11 @@ func NewFilesAtCommitScanner(opts options.Options, cfg config.Config, repo *git. // Scan kicks off a FilesAtCommitScanner Scan func (fs *FilesAtCommitScanner) Scan() (Report, error) { var scannerReport Report + + if fs.cfg.Allowlist.CommitAllowed(fs.commit.Hash.String()) { + return scannerReport, nil + } + fIter, err := fs.commit.Files() if err != nil { return scannerReport, err @@ -51,6 +56,11 @@ func (fs *FilesAtCommitScanner) Scan() (Report, error) { return err } + if fs.cfg.Allowlist.FileAllowed(filepath.Base(f.Name)) || + fs.cfg.Allowlist.PathAllowed(f.Name) { + return nil + } + content, err := f.Contents() if err != nil { return err diff --git a/scan/scan_test.go b/scan/scan_test.go index 23f7e9db..da0a43d2 100644 --- a/scan/scan_test.go +++ b/scan/scan_test.go @@ -463,6 +463,30 @@ func TestScan(t *testing.T) { }, wantPath: "../test_data/test_allow_list_docx_no_git.json", }, + { + description: "test local repo two allowlist Commit config", + opts: options.Options{ + Path: "../test_data/test_repos/test_repo_2", + Report: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json.got", + ConfigPath: "../test_data/test_configs/allowlist_commit.toml", + ReportFormat: "json", + FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + }, + wantPath: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json", + wantEmpty: true, + }, + { + description: "test local repo two global allowlist commit config", + opts: options.Options{ + Path: "../test_data/test_repos/test_repo_2", + Report: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json.got", + ConfigPath: "../test_data/test_configs/allowlist_global_files.toml", + ReportFormat: "json", + FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c", + }, + wantPath: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json", + wantEmpty: true, + }, } for _, test := range tests { diff --git a/test_data/test_configs/allowlist_global_files.toml b/test_data/test_configs/allowlist_global_files.toml new file mode 100644 index 00000000..2555a4b1 --- /dev/null +++ b/test_data/test_configs/allowlist_global_files.toml @@ -0,0 +1,9 @@ +[[rules]] + description = "AWS Access Key" + regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + tags = ["key", "AWS"] + +[allowlist] + description = "Allowlisted files" + paths = ['''.py'''] + files = ['''.md$''']