From 2b3ff7b572223d797172f5ec5d3a461638515be2 Mon Sep 17 00:00:00 2001 From: BenjaminMitchell-D0FB <352241654+BenjaminMitchell-D0FB@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:13:15 -0800 Subject: [PATCH] Reject invalid ingress hostname wildcards --- ingress/ingress.go | 7 ++++--- ingress/ingress_test.go | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ingress/ingress.go b/ingress/ingress.go index f5758fc91d3..dbe9bb08491 100644 --- a/ingress/ingress.go +++ b/ingress/ingress.go @@ -479,9 +479,10 @@ func validateHostname(r config.UnvalidatedIngressRule, ruleIndex, totalRules int if err == nil { return errHostnameContainsPort } - // Ensure that there are no wildcards anywhere except the first character - // of the hostname. - if strings.LastIndex(r.Hostname, "*") > 0 { + // A wildcard must be the entire hostname or the entire first label. + wildcardIndex := strings.LastIndex(r.Hostname, "*") + if wildcardIndex > 0 || (wildcardIndex == 0 && r.Hostname != "*" && + (!strings.HasPrefix(r.Hostname, "*.") || len(r.Hostname) == len("*."))) { return errBadWildcard } diff --git a/ingress/ingress_test.go b/ingress/ingress_test.go index f764c6a5e97..d55dc11cc64 100644 --- a/ingress/ingress_test.go +++ b/ingress/ingress_test.go @@ -71,17 +71,17 @@ func TestParseIngress(t *testing.T) { wantErr: true, }, { - name: "Multiple rules", + name: "Subdomain wildcard and catch-all", args: args{rawYAML: ` ingress: - - hostname: tunnel1.example.com + - hostname: "*.example.com" service: https://localhost:8000 - hostname: "*" service: https://localhost:8001 `}, want: []Rule{ { - Hostname: "tunnel1.example.com", + Hostname: "*.example.com", Service: &httpService{url: localhost8000}, Config: defaultConfig, }, @@ -228,6 +228,27 @@ ingress: ingress: - hostname: "test.*.example.com" service: https://localhost:8000 + - service: http_status:404 +`}, + wantErr: true, + }, + { + name: "Wildcard attached to a partial label", + args: args{rawYAML: ` +ingress: + - hostname: "*app.example.com" + service: https://localhost:8000 + - service: http_status:404 +`}, + wantErr: true, + }, + { + name: "Wildcard without a domain suffix", + args: args{rawYAML: ` +ingress: + - hostname: "*." + service: https://localhost:8000 + - service: http_status:404 `}, wantErr: true, },