Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update validation regex for path spec #2783

Merged
merged 5 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/k8s/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const (
const (
commaDelimiter = ","
annotationValueFmt = `([^"$\\]|\\[^$])*`
pathFmt = `/[^\s{};]*`
pathFmt = `/[^\s{};\\]*`
jwtTokenValueFmt = "\\$" + annotationValueFmt
)

Expand Down
75 changes: 75 additions & 0 deletions internal/k8s/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,81 @@ func TestValidateIngressSpec(t *testing.T) {
},
msg: "test invalid characters in path",
},
{
spec: &networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "foo.example.com",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: `/tea\{custom_value}`,
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{},
},
},
},
},
},
},
},
},
expectedErrors: []field.ErrorType{
field.ErrorTypeInvalid,
},
msg: "test invalid characters in path",
},
{
spec: &networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "foo.example.com",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: `/tea\`,
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{},
},
},
},
},
},
},
},
},
expectedErrors: []field.ErrorType{
field.ErrorTypeInvalid,
},
msg: "test invalid characters in path",
},
{
spec: &networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "foo.example.com",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: `/tea\n`,
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{},
},
},
},
},
},
},
},
},
expectedErrors: []field.ErrorType{
field.ErrorTypeInvalid,
},
msg: "test invalid characters in path",
},
{
spec: &networking.IngressSpec{
Rules: []networking.IngressRule{
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/configuration/validation/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ func validateRegexPath(path string, fieldPath *field.Path) field.ErrorList {
}

const (
pathFmt = `/[^\s{};]*`
pathFmt = `/[^\s{};\\]*`
pathErrMsg = "must start with / and must not include any whitespace character, `{`, `}` or `;`"
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ func TestValidatePath(t *testing.T) {
"/{",
"/}",
"/abc;",
`/path\`,
`/path\n`,
}

for _, path := range invalidPaths {
Expand Down