From 8f0b9205dd6efbdb937623d3db743932a34e552a Mon Sep 17 00:00:00 2001 From: Gerdriaan Mulder Date: Tue, 29 Oct 2019 20:28:41 +0100 Subject: [PATCH] detector: remove confusing/incorrectly used | in character classes of detectorPatterns Fixes #161 --- detector/match_pattern_test.go | 4 ++-- detector/pattern_detector.go | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/detector/match_pattern_test.go b/detector/match_pattern_test.go index 4589c86c..fdf71caf 100644 --- a/detector/match_pattern_test.go +++ b/detector/match_pattern_test.go @@ -7,8 +7,8 @@ import ( ) var ( - testRegexpPassword = regexp.MustCompile(`(?i)(['|"|_]?password['|"]? *[:|=][^,|;]{8,})`) - testRegexpPw = regexp.MustCompile(`(?i)(['|"|_]?pw['|"]? *[:|=][^,|;]{8,})`) + testRegexpPassword = regexp.MustCompile(`(?i)(['"_]?password['"]? *[:=][^,;]{8,})`) + testRegexpPw = regexp.MustCompile(`(?i)(['"_]?pw['"]? *[:=][^,;]{8,})`) ) func TestShouldReturnEmptyStringWhenDoesNotMatchAnyRegex(t *testing.T) { diff --git a/detector/pattern_detector.go b/detector/pattern_detector.go index 6aa93969..2fc7429f 100644 --- a/detector/pattern_detector.go +++ b/detector/pattern_detector.go @@ -14,19 +14,19 @@ type PatternDetector struct { var ( detectorPatterns = []*regexp.Regexp{ - regexp.MustCompile("(?i)(['|\"|_]?password['|\"]? *[:|=][^,|;|\n]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?pw['|\"]? *[:|=][^,|;|\n]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?pwd['|\"]? *[:|=][^,|;|\n]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?pass['|\"]? *[:|=][^,|;|\n]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?pword['|\"]? *[:|=][^,|;|\n]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?adminPassword['|\"]? *[:|=|\n][^,|;]{8,})"), - regexp.MustCompile("(?i)(['|\"|_]?passphrase['|\"]? *[:|=|\n][^,|;]{8,})"), + regexp.MustCompile("(?i)(['\"_]?password['\"]? *[:=][^,;\n]{8,})"), + regexp.MustCompile("(?i)(['\"_]?pw['\"]? *[:=][^,;\n]{8,})"), + regexp.MustCompile("(?i)(['\"_]?pwd['\"]? *[:=][^,;\n]{8,})"), + regexp.MustCompile("(?i)(['\"_]?pass['\"]? *[:=][^,;\n]{8,})"), + regexp.MustCompile("(?i)(['\"_]?pword['\"]? *[:=][^,;\n]{8,})"), + regexp.MustCompile("(?i)(['\"_]?adminPassword['\"]? *[:=\n][^,;]{8,})"), + regexp.MustCompile("(?i)(['\"_]?passphrase['\"]? *[:=\n][^,;]{8,})"), regexp.MustCompile("(<[^(><.)]?password[^(><.)]*?>[^(><.)]+<.)]?password[^(><.)]*?>)"), regexp.MustCompile("(<[^(><.)]?passphrase[^(><.)]*?>[^(><.)]+<.)]?passphrase[^(><.)]*?>)"), regexp.MustCompile("(?i)(\\S*<\\/ConsumerKey>)"), regexp.MustCompile("(?i)(\\S*<\\/ConsumerSecret>)"), - regexp.MustCompile("(?i)(AWS[ |\\w]+key[ |\\w]+[:|=])"), - regexp.MustCompile("(?i)(AWS[ |\\w]+secret[ |\\w]+[:|=])"), + regexp.MustCompile("(?i)(AWS[ \\w]+key[ \\w]+[:=])"), + regexp.MustCompile("(?i)(AWS[ \\w]+secret[ \\w]+[:=])"), regexp.MustCompile("(?s)(BEGIN RSA PRIVATE KEY.*END RSA PRIVATE KEY)"), } )