Fix incorrect hostname matching between listener and route
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Build and Publish Documentation / Doc Process (push) Waiting to run
Build experimental image on branch / build-webui (push) Waiting to run
Build experimental image on branch / Build experimental image on branch (push) Waiting to run

This commit is contained in:
Alexander 2026-03-16 16:42:05 +01:00 committed by GitHub
parent f143e15595
commit 69a738ccf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 13 deletions

View file

@ -1093,24 +1093,13 @@ func findMatchingHostname(h1, h2 gatev1.Hostname) gatev1.Hostname {
}
trimmedH1 := strings.TrimPrefix(string(h1), "*")
// root domain doesn't match subdomain wildcard.
if trimmedH1 == string(h2) {
return ""
}
if !strings.HasSuffix(string(h2), trimmedH1) {
return ""
}
return lessWildcards(h1, h2)
}
func lessWildcards(h1, h2 gatev1.Hostname) gatev1.Hostname {
if strings.Count(string(h1), "*") > strings.Count(string(h2), "*") {
return h2
}
return h1
// since h1 is a suffix of h2, we know h2 is the more specific host
return h2
}
func allowRoute(listener gatewayListener, routeNamespace, routeKind string) bool {

View file

@ -7630,6 +7630,13 @@ func Test_findMatchingHostnames(t *testing.T) {
want: []gatev1.Hostname{"toto.foo.com", "test.foo.com"},
wantOk: true,
},
{
desc: "Matching wildcard subsubdomain with listener wildcard subdomain",
listenerHostname: ptr.To(gatev1.Hostname("*.foo.com")),
routeHostnames: []gatev1.Hostname{"*.bar.foo.com"},
want: []gatev1.Hostname{"*.bar.foo.com"},
wantOk: true,
},
}
for _, test := range testCases {