Skip to content

Find, verify, and analyze leaked credentials

Improved Besttime detector regex pattern (#4059)

Kashif Khanad258d848807
diff --git a/pkg/detectors/besttime/besttime.go b/pkg/detectors/besttime/besttime.go
index 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.go
index 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 header
req, 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",