httpcaddyfile: Take into account host scheme/port (fix #4113)

This commit is contained in:
Matthew Holt 2021-04-16 11:17:15 -06:00
parent 00e12aa918
commit 96bb365929
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with 32 additions and 4 deletions

View File

@ -54,7 +54,7 @@ func (st ServerType) buildTLSApp(
// a hostless key, so that they don't get forgotten/omitted // a hostless key, so that they don't get forgotten/omitted
// by auto-HTTPS (since they won't appear in route matchers) // by auto-HTTPS (since they won't appear in route matchers)
var serverBlocksWithTLSHostlessKey int var serverBlocksWithTLSHostlessKey int
hostsSharedWithHostlessKey := make(map[string]struct{}) httpsHostsSharedWithHostlessKey := make(map[string]struct{})
for _, pair := range pairings { for _, pair := range pairings {
for _, sb := range pair.serverBlocks { for _, sb := range pair.serverBlocks {
for _, addr := range sb.keys { for _, addr := range sb.keys {
@ -70,8 +70,8 @@ func (st ServerType) buildTLSApp(
if otherAddr.Original == addr.Original { if otherAddr.Original == addr.Original {
continue continue
} }
if otherAddr.Host != "" { if otherAddr.Host != "" && otherAddr.Scheme != "http" && otherAddr.Port != httpPort {
hostsSharedWithHostlessKey[otherAddr.Host] = struct{}{} httpsHostsSharedWithHostlessKey[otherAddr.Host] = struct{}{}
} }
} }
break break
@ -289,7 +289,7 @@ func (st ServerType) buildTLSApp(
internalAP := &caddytls.AutomationPolicy{ internalAP := &caddytls.AutomationPolicy{
IssuersRaw: []json.RawMessage{json.RawMessage(`{"module":"internal"}`)}, IssuersRaw: []json.RawMessage{json.RawMessage(`{"module":"internal"}`)},
} }
for h := range hostsSharedWithHostlessKey { for h := range httpsHostsSharedWithHostlessKey {
al = append(al, h) al = append(al, h)
if !certmagic.SubjectQualifiesForPublicCert(h) { if !certmagic.SubjectQualifiesForPublicCert(h) {
internalAP.Subjects = append(internalAP.Subjects, h) internalAP.Subjects = append(internalAP.Subjects, h)

View File

@ -0,0 +1,28 @@
# Issue #4113
:80, http://example.com {
respond "foo"
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":80"
],
"routes": [
{
"handle": [
{
"body": "foo",
"handler": "static_response"
}
]
}
]
}
}
}
}
}