From 80d29764a0bc0f269607d3eb7b2774a0f31e5da3 Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Thu, 25 Nov 2021 11:17:03 -0600 Subject: [PATCH] add global regex check (#717) --- detect/detect.go | 2 +- detect/detect_test.go | 6 ++++++ testdata/config/allow_global_aws_re.toml | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 testdata/config/allow_global_aws_re.toml diff --git a/detect/detect.go b/detect/detect.go index e3322c3b..6bcef851 100644 --- a/detect/detect.go +++ b/detect/detect.go @@ -72,7 +72,7 @@ func DetectFindings(cfg config.Config, b []byte, filePath string, commit string) Tags: r.Tags, } - if r.Allowlist.RegexAllowed(f.Secret) { + if r.Allowlist.RegexAllowed(f.Secret) || cfg.Allowlist.RegexAllowed(f.Secret) { continue } diff --git a/detect/detect_test.go b/detect/detect_test.go index 8b7abd02..71ad40b4 100644 --- a/detect/detect_test.go +++ b/detect/detect_test.go @@ -118,6 +118,12 @@ func TestDetectFindings(t *testing.T) { filePath: filepath.Join(configPath, "simple.toml"), expectedFindings: []report.Finding{}, }, + { + cfgName: "allow_global_aws_re", + bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`), + filePath: "tmp.go", + expectedFindings: []report.Finding{}, + }, } for _, tt := range tests { diff --git a/testdata/config/allow_global_aws_re.toml b/testdata/config/allow_global_aws_re.toml new file mode 100644 index 00000000..7b7c3eee --- /dev/null +++ b/testdata/config/allow_global_aws_re.toml @@ -0,0 +1,8 @@ +[[rules]] + description = "AWS Access Key" + id = "aws-access-key" + regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}''' + tags = ["key", "AWS"] + +[allowlist] + regexes = ['''AKIALALEMEL33243OLIA''']