diff --git a/config/config.go b/config/config.go index 18a71c3df..e89336ddc 100644 --- a/config/config.go +++ b/config/config.go @@ -10,7 +10,6 @@ import ( "path" "regexp" - "gopkg.in/yaml.v3" "github.com/sirupsen/logrus" "go.mozilla.org/sops/v3" "go.mozilla.org/sops/v3/age" @@ -21,6 +20,7 @@ import ( "go.mozilla.org/sops/v3/logging" "go.mozilla.org/sops/v3/pgp" "go.mozilla.org/sops/v3/publish" + "gopkg.in/yaml.v3" ) var log *logrus.Logger @@ -326,11 +326,13 @@ func parseCreationRuleForFile(conf *configFile, filePath string, kmsEncryptionCo rule = &r break } - if r.PathRegex != "" { - if match, _ := regexp.MatchString(r.PathRegex, filePath); match { - rule = &r - break - } + reg, err := regexp.Compile(r.PathRegex) + if err != nil { + return nil, fmt.Errorf("can not compile regexp: %w", err) + } + if reg.MatchString(filePath) { + rule = &r + break } } diff --git a/config/config_test.go b/config/config_test.go index 183eb7836..ac8aca6f3 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -208,6 +208,24 @@ destination_rules: path_regex: "vault-v1/*" `) +var sampleConfigWithInvalidComplicatedRegexp = []byte(` +creation_rules: + - path_regex: "[ ]\\K(?