summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-06-03 09:35:13 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-06-03 09:35:13 -0600
commit97e61c16a3a0e74be0810b4714de1dab345fba8b (patch)
tree8a0675822fb38022ccda2cc6c310060ba7cd6d02 /caddyconfig
parent83551edf3e050b5dd094fc1cff20a3f78c4d621f (diff)
httpcaddyfile: Sort site blocks with wildcards last (fix #3410)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index 7bb7c56..7be932f 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -377,7 +377,11 @@ func (st *ServerType) serversFromPairings(
// but I don't expect many blocks will have THAT many keys...
var iLongestPath, jLongestPath string
var iLongestHost, jLongestHost string
+ var iWildcardHost, jWildcardHost bool
for _, addr := range p.serverBlocks[i].keys {
+ if strings.Contains(addr.Host, "*.") {
+ iWildcardHost = true
+ }
if specificity(addr.Host) > specificity(iLongestHost) {
iLongestHost = addr.Host
}
@@ -386,6 +390,9 @@ func (st *ServerType) serversFromPairings(
}
}
for _, addr := range p.serverBlocks[j].keys {
+ if strings.Contains(addr.Host, "*.") {
+ jWildcardHost = true
+ }
if specificity(addr.Host) > specificity(jLongestHost) {
jLongestHost = addr.Host
}
@@ -393,6 +400,12 @@ func (st *ServerType) serversFromPairings(
jLongestPath = addr.Path
}
}
+ if iWildcardHost != jWildcardHost {
+ // site blocks that have a key with a wildcard in the hostname
+ // must always be less specific than blocks without one; see
+ // https://github.com/caddyserver/caddy/issues/3410
+ return jWildcardHost && !iWildcardHost
+ }
if specificity(iLongestHost) == specificity(jLongestHost) {
return len(iLongestPath) > len(jLongestPath)
}