mirror of
https://github.com/traefik/traefik.git
synced 2026-06-09 08:43:26 -04:00
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
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:
parent
f143e15595
commit
69a738ccf0
2 changed files with 9 additions and 13 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue