diff --git a/pkg/kyverno/common/common.go b/pkg/kyverno/common/common.go index 1a3188d79c..f9e9bbe480 100644 --- a/pkg/kyverno/common/common.go +++ b/pkg/kyverno/common/common.go @@ -69,7 +69,7 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, errors []error) err error ) - isHttpPath := strings.Contains(path, "http") + isHttpPath := IsHttpRegex.MatchString(path) // path clean and retrieving file info can be possible if it's not an HTTP URL if !isHttpPath { diff --git a/pkg/kyverno/common/fetch.go b/pkg/kyverno/common/fetch.go index 14468246d3..23a50ae47a 100644 --- a/pkg/kyverno/common/fetch.go +++ b/pkg/kyverno/common/fetch.go @@ -219,7 +219,7 @@ func getFileBytes(path string) ([]byte, error) { err error ) - if strings.Contains(path, "http") { + if IsHttpRegex.MatchString(path) { resp, err := http.Get(path) if err != nil { return nil, err diff --git a/pkg/kyverno/common/regex.go b/pkg/kyverno/common/regex.go index 9bd4a4751b..18893ad5df 100644 --- a/pkg/kyverno/common/regex.go +++ b/pkg/kyverno/common/regex.go @@ -9,3 +9,6 @@ var RegexVariables = regexp.MustCompile(`\{\{[^{}]*\}\}`) // AllowedVariables represents regex for {{request.}}, {{serviceAccountName}}, {{serviceAccountNamespace}} and {{@}} var AllowedVariables = regexp.MustCompile(`\{\{\s*[request\.|serviceAccountName|serviceAccountNamespace|@][^{}]*\}\}`) + +// IsHttpRegex represents regex for starts with http:// or https:// +var IsHttpRegex = regexp.MustCompile("^(http|https)://") \ No newline at end of file