@marcel91200 / caddy Mirror · read-only / commits / 96bb3659
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

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

Matthew Holt committed Apr 16, 2021 at 11:17 UTC 96bb3659299ae5ef28ffb3f9a23e16417c570924
2 files changed +32 -4
caddyconfig/httpcaddyfile/tlsapp.go
+4 -4
@@ -54,7 +54,7 @@ func (st ServerType) buildTLSApp(
54 // a hostless key, so that they don't get forgotten/omitted
55 // by auto-HTTPS (since they won't appear in route matchers)
56 var serverBlocksWithTLSHostlessKey int
57 - hostsSharedWithHostlessKey := make(map[string]struct{})
57 + httpsHostsSharedWithHostlessKey := make(map[string]struct{})
58 for _, pair := range pairings {
59 for _, sb := range pair.serverBlocks {
60 for _, addr := range sb.keys {
@@ -70,8 +70,8 @@ func (st ServerType) buildTLSApp(
70 if otherAddr.Original == addr.Original {
71 continue
72 }
73 - if otherAddr.Host != "" {
74 - hostsSharedWithHostlessKey[otherAddr.Host] = struct{}{}
73 + if otherAddr.Host != "" && otherAddr.Scheme != "http" && otherAddr.Port != httpPort {
74 + httpsHostsSharedWithHostlessKey[otherAddr.Host] = struct{}{}
75 }
76 }
77 break
@@ -289,7 +289,7 @@ func (st ServerType) buildTLSApp(
289 internalAP := &caddytls.AutomationPolicy{
290 IssuersRaw: []json.RawMessage{json.RawMessage(`{"module":"internal"}`)},
291 }
292 - for h := range hostsSharedWithHostlessKey {
292 + for h := range httpsHostsSharedWithHostlessKey {
293 al = append(al, h)
294 if !certmagic.SubjectQualifiesForPublicCert(h) {
295 internalAP.Subjects = append(internalAP.Subjects, h)
caddytest/integration/caddyfile_adapt/http_only_on_hostless_block.txt new
+28
@@ -0,0 +1,28 @@
1 +# Issue #4113
2 +:80, http://example.com {
3 + respond "foo"
4 +}
5 +----------
6 +{
7 + "apps": {
8 + "http": {
9 + "servers": {
10 + "srv0": {
11 + "listen": [
12 + ":80"
13 + ],
14 + "routes": [
15 + {
16 + "handle": [
17 + {
18 + "body": "foo",
19 + "handler": "static_response"
20 + }
21 + ]
22 + }
23 + ]
24 + }
25 + }
26 + }
27 + }
28 +}
\ No newline at end of file