Skip to content

Find, verify, and analyze leaked credentials

[THOG-234] Update security trails detector's regex and keywords. (#429)

ahrav96c9c5bf7cbe
diff --git a/pkg/detectors/detectors.go b/pkg/detectors/detectors.go
index 7fb169c07..bfc722d08 100644
--- a/pkg/detectors/detectors.go
+++ b/pkg/detectors/detectors.go
@@ -92,7 +92,7 @@ func CleanResults(results []Result) []Result {
func PrefixRegex(keywords []string) string {
pre := `(?i)(?:`
middle := strings.Join(keywords, "|")
- post := `).{0,40}`
+ post := `)(?:.|[\n\r]){0,40}`
return pre + middle + post
}
diff --git a/pkg/detectors/detectors_test.go b/pkg/detectors/detectors_test.go
new file mode 100644
index 000000000..f0f487a73
--- /dev/null
+++ b/pkg/detectors/detectors_test.go
@@ -0,0 +1,36 @@
+package detectors
+
+import "testing"
+
+func TestPrefixRegex(t *testing.T) {
+ tests := []struct {
+ keywords []string
+ expected string
+ }{
+ {
+ keywords: []string{"securitytrails"},
+ expected: `(?i)(?:securitytrails).|(?:[\n\r]){0,40}`,
+ },
+ {
+ keywords: []string{"zipbooks"},
+ expected: `(?i)(?:zipbooks).|(?:[\n\r]){0,40}`,
+ },
+ {
+ keywords: []string{"wrike"},
+ expected: `(?i)(?:wrike).|(?:[\n\r]){0,40}`,
+ },
+ }
+ for _, tt := range tests {
+ got := PrefixRegex(tt.keywords)
+ if got != tt.expected {
+ t.Errorf("PrefixRegex(%v) got: %v want: %v", tt.keywords, got, tt.expected)
+ }
+ }
+}
+
+func BenchmarkPrefixRegex(b *testing.B) {
+ kws := []string{"securitytrails"}
+ for i := 0; i < b.N; i++ {
+ PrefixRegex(kws)
+ }
+}
diff --git a/pkg/detectors/securitytrails/securitytrails.go b/pkg/detectors/securitytrails/securitytrails.go
index de674bfd4..1f79f0849 100644
--- a/pkg/detectors/securitytrails/securitytrails.go
+++ b/pkg/detectors/securitytrails/securitytrails.go
@@ -26,7 +26,7 @@ var (
// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
- return []string{"securitytrails"}
+ return []string{"securitytrails", "security trails"}
}
// FromData will find and optionally verify SecurityTrails secrets in a given set of bytes.
diff --git a/pkg/detectors/securitytrails/securitytrails_test.go b/pkg/detectors/securitytrails/securitytrails_test.go
index 7e0720bf6..dd94c53f1 100644
--- a/pkg/detectors/securitytrails/securitytrails_test.go
+++ b/pkg/detectors/securitytrails/securitytrails_test.go
@@ -38,6 +38,22 @@ func TestSecurityTrails_FromChunk(t *testing.T) {
{
name: "found, verified",
s: Scanner{},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("You can find a securitytrails secret\n %s within", secret)),
+ verify: true,
+ },
+ want: []detectors.Result{
+ {
+ DetectorType: detectorspb.DetectorType_SecurityTrails,
+ Verified: true,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "found, verified inline",
+ s: Scanner{},
args: args{
ctx: context.Background(),
data: []byte(fmt.Sprintf("You can find a securitytrails secret %s within", secret)),