diff --git a/pkg/custom_detectors/validation.go b/pkg/custom_detectors/validation.go index 62bc14910..35f720297 100644 --- a/pkg/custom_detectors/validation.go +++ b/pkg/custom_detectors/validation.go @@ -2,6 +2,7 @@ package custom_detectors import ( "fmt" + "regexp" "strconv" "strings" ) @@ -23,6 +24,11 @@ func ValidateRegex(regex map[string]string) error { if len(regex) == 0 { return fmt.Errorf("no regex") } + for name, reg := range regex { + if _, err := regexp.Compile(reg); err != nil { + return fmt.Errorf("regex '%s': %w", name, err) + } + } return nil } diff --git a/pkg/custom_detectors/validation_test.go b/pkg/custom_detectors/validation_test.go index 1aa36f4e0..c5f7f56d6 100644 --- a/pkg/custom_detectors/validation_test.go +++ b/pkg/custom_detectors/validation_test.go @@ -53,6 +53,13 @@ func TestCustomDetectorsRegexValidation(t *testing.T) { input: map[string]string{}, wantErr: true, }, + { + name: "Test invalid regex", + input: map[string]string{ + "test": "!!?(?:?)[a-zA-Z0-9]{32}", + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {