Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Improved Besttime detector regex pattern (#4059)
Kashif Khanad258d848807
diff --git a/pkg/detectors/besttime/besttime.go b/pkg/detectors/besttime/besttime.goindex 315950f90..c88565d99 100644--- a/pkg/detectors/besttime/besttime.go+++ b/pkg/detectors/besttime/besttime.go@@ -22,7 +22,7 @@ var (client = common.SaneHttpClient()// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.- keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"besttime"}) + `\b([0-9A-Za-z_]{36})\b`)+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"besttime"}) + `\b(pri_[a-f0-9]{32})\b`))// Keywords are used for efficiently pre-filtering chunks.diff --git a/pkg/detectors/besttime/besttime_test.go b/pkg/detectors/besttime/besttime_test.goindex fef150cf5..abc930ef2 100644--- a/pkg/detectors/besttime/besttime_test.go+++ b/pkg/detectors/besttime/besttime_test.go@@ -12,10 +12,10 @@ import ()var (- validPattern = "4K1WTb2ysVeg_jHDwtwhH68K9MuOjiTtXQCS"+ validPattern = "pri_099889f14d114dfaae476569b395eade"complexPattern = `func main() {- url := "https://api.example.com/v1/besttime/keys/4K1WTb2ysVeg_jHDwtwhH68K9MuOjiTtXQCS"+ url := "https://api.example.com/v1/besttime/keys/pri_099889f14d114dfaae476569b395eade"// Create a new request with the secret as a headerreq, err := http.NewRequest("GET", url, http.NoBody)@@ -52,12 +52,12 @@ func TestBestTime_Pattern(t *testing.T) {{name: "valid pattern",input: fmt.Sprintf("besttime credentials: %s", validPattern),- want: []string{"4K1WTb2ysVeg_jHDwtwhH68K9MuOjiTtXQCS"},+ want: []string{"pri_099889f14d114dfaae476569b395eade"},},{name: "valid pattern - complex",input: complexPattern,- want: []string{"4K1WTb2ysVeg_jHDwtwhH68K9MuOjiTtXQCS"},+ want: []string{"pri_099889f14d114dfaae476569b395eade"},},{name: "invalid pattern",