@marcel91200 / caddy Mirror · read-only / commits / 1455d6bb
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: Fix panic in automation policy consolidation (#4104)

* httpcaddyfile: Add reproduce test * httpcaddyfile: Don't allow `i` to go below zero

Francis Lavoie committed Apr 2, 2021 at 18:47 UTC 1455d6bb690d8c91159a709cc6d1a0dc01ed9153
2 files changed +157 -1
caddyconfig/httpcaddyfile/tlsapp.go
+2 -1
@@ -491,13 +491,13 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
491 }
492
493 // remove or combine duplicate policies
494 +outer:
495 for i := 0; i < len(aps); i++ {
496 // compare only with next policies; we sorted by specificity so we must not delete earlier policies
497 for j := i + 1; j < len(aps); j++ {
498 // if they're exactly equal in every way, just keep one of them
499 if reflect.DeepEqual(aps[i], aps[j]) {
500 aps = append(aps[:j], aps[j+1:]...)
500 - i--
501 break
502 }
503
@@ -524,6 +524,7 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
524 if automationPolicyShadows(i, aps) >= j {
525 aps = append(aps[:i], aps[i+1:]...)
526 i--
527 + continue outer
528 }
529 } else {
530 // avoid repeated subjects
caddytest/integration/caddyfile_adapt/tls_automation_policies_4.txt new
+155
@@ -0,0 +1,155 @@
1 +{
2 + email my.email@example.com
3 +}
4 +
5 +:82 {
6 + redir https://example.com{uri}
7 +}
8 +
9 +:83 {
10 + redir https://example.com{uri}
11 +}
12 +
13 +:84 {
14 + redir https://example.com{uri}
15 +}
16 +
17 +abc.de {
18 + redir https://example.com{uri}
19 +}
20 +----------
21 +{
22 + "apps": {
23 + "http": {
24 + "servers": {
25 + "srv0": {
26 + "listen": [
27 + ":443"
28 + ],
29 + "routes": [
30 + {
31 + "match": [
32 + {
33 + "host": [
34 + "abc.de"
35 + ]
36 + }
37 + ],
38 + "handle": [
39 + {
40 + "handler": "subroute",
41 + "routes": [
42 + {
43 + "handle": [
44 + {
45 + "handler": "static_response",
46 + "headers": {
47 + "Location": [
48 + "https://example.com{http.request.uri}"
49 + ]
50 + },
51 + "status_code": 302
52 + }
53 + ]
54 + }
55 + ]
56 + }
57 + ],
58 + "terminal": true
59 + }
60 + ]
61 + },
62 + "srv1": {
63 + "listen": [
64 + ":82"
65 + ],
66 + "routes": [
67 + {
68 + "handle": [
69 + {
70 + "handler": "static_response",
71 + "headers": {
72 + "Location": [
73 + "https://example.com{http.request.uri}"
74 + ]
75 + },
76 + "status_code": 302
77 + }
78 + ]
79 + }
80 + ]
81 + },
82 + "srv2": {
83 + "listen": [
84 + ":83"
85 + ],
86 + "routes": [
87 + {
88 + "handle": [
89 + {
90 + "handler": "static_response",
91 + "headers": {
92 + "Location": [
93 + "https://example.com{http.request.uri}"
94 + ]
95 + },
96 + "status_code": 302
97 + }
98 + ]
99 + }
100 + ]
101 + },
102 + "srv3": {
103 + "listen": [
104 + ":84"
105 + ],
106 + "routes": [
107 + {
108 + "handle": [
109 + {
110 + "handler": "static_response",
111 + "headers": {
112 + "Location": [
113 + "https://example.com{http.request.uri}"
114 + ]
115 + },
116 + "status_code": 302
117 + }
118 + ]
119 + }
120 + ]
121 + }
122 + }
123 + },
124 + "tls": {
125 + "automation": {
126 + "policies": [
127 + {
128 + "issuers": [
129 + {
130 + "email": "my.email@example.com",
131 + "module": "acme"
132 + },
133 + {
134 + "email": "my.email@example.com",
135 + "module": "zerossl"
136 + }
137 + ]
138 + },
139 + {
140 + "issuers": [
141 + {
142 + "email": "my.email@example.com",
143 + "module": "acme"
144 + },
145 + {
146 + "email": "my.email@example.com",
147 + "module": "zerossl"
148 + }
149 + ]
150 + }
151 + ]
152 + }
153 + }
154 + }
155 +}
\ No newline at end of file