diff --git a/internal/ingress/controller/parser/parser.go b/internal/ingress/controller/parser/parser.go index eb51f360e3..afbf066d27 100644 --- a/internal/ingress/controller/parser/parser.go +++ b/internal/ingress/controller/parser/parser.go @@ -662,6 +662,12 @@ func (p *Parser) parseIngressRules( for j, rule := range rule.HTTP.Paths { path := rule.Path + if strings.Contains(path, "//") { + glog.Errorf("ingress rule skipped in Ingress'%v/%v', "+ + "'%v' is an invalid path", ingress.Namespace, + ingress.Name, path) + continue + } if path == "" { path = "/" } diff --git a/internal/ingress/controller/parser/parser_test.go b/internal/ingress/controller/parser/parser_test.go index c563c0d20b..f6731f2e87 100644 --- a/internal/ingress/controller/parser/parser_test.go +++ b/internal/ingress/controller/parser/parser_test.go @@ -2801,6 +2801,33 @@ func TestParseIngressRules(t *testing.T) { }, }, }, + // 7 + { + ObjectMeta: metav1.ObjectMeta{ + Name: "invalid-path", + Namespace: "foo-namespace", + }, + Spec: networking.IngressSpec{ + Rules: []networking.IngressRule{ + { + Host: "example.com", + IngressRuleValue: networking.IngressRuleValue{ + HTTP: &networking.HTTPIngressRuleValue{ + Paths: []networking.HTTPIngressPath{ + { + Path: "/foo//bar", + Backend: networking.IngressBackend{ + ServiceName: "foo-svc", + ServicePort: intstr.FromInt(80), + }, + }, + }, + }, + }, + }, + }, + }, + }, } tcpIngressList := []*configurationv1beta1.TCPIngress{ // 0 @@ -3010,6 +3037,12 @@ func TestParseIngressRules(t *testing.T) { assert.Equal("foo-svc.foo-namespace.80.svc", *parsedInfo.ServiceNameToServices["foo-namespace.foo-svc.80"].Host) assert.Equal("foo-svc.foo-namespace.8000.svc", *parsedInfo.ServiceNameToServices["foo-namespace.foo-svc.8000"].Host) }) + t.Run("Ingress rule with path containing multiple slashes ('//') is skipped", func(t *testing.T) { + parsedInfo := p.parseIngressRules([]*networking.Ingress{ + ingressList[7], + }, []*configurationv1beta1.TCPIngress{}) + assert.Empty(parsedInfo.ServiceNameToServices) + }) } func TestParseKnativeIngressRules(t *testing.T) {