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
caddyhttp: Strictly forbid unnecessary blocks on matchers (#3229)
Francis Lavoie committed
Apr 6, 2020 at 15:07 UTC
5b355cbed0cc2e9d136f7cbb05804b284c92308e
1 file changed
+26
-1
modules/caddyhttp/matchers.go
+26
-1
@@ -145,6 +145,9 @@ func (MatchHost) CaddyModule() caddy.ModuleInfo {
145
func (m *MatchHost) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
146
for d.Next() {
147
*m = append(*m, d.RemainingArgs()...)
148
+ if d.NextBlock(0) {
149
+ return d.Err("malformed host matcher: blocks are not supported")
150
+ }
151
}
152
return nil
153
}
@@ -271,6 +274,9 @@ func (m MatchPath) Match(r *http.Request) bool {
274
func (m *MatchPath) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
275
for d.Next() {
276
*m = append(*m, d.RemainingArgs()...)
277
+ if d.NextBlock(0) {
278
+ return d.Err("malformed path matcher: blocks are not supported")
279
+ }
280
}
281
return nil
282
}
@@ -301,6 +307,9 @@ func (MatchMethod) CaddyModule() caddy.ModuleInfo {
307
func (m *MatchMethod) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
308
for d.Next() {
309
*m = append(*m, d.RemainingArgs()...)
310
+ if d.NextBlock(0) {
311
+ return d.Err("malformed method matcher: blocks are not supported")
312
+ }
313
}
314
return nil
315
}
@@ -339,6 +348,9 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
348
return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val())
349
}
350
url.Values(*m).Set(parts[0], parts[1])
351
+ if d.NextBlock(0) {
352
+ return d.Err("malformed query matcher: blocks are not supported")
353
+ }
354
}
355
return nil
356
}
@@ -374,9 +386,12 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
386
for d.Next() {
387
var field, val string
388
if !d.Args(&field, &val) {
377
- return d.Errf("expected both field and value")
389
+ return d.Errf("malformed header matcher: expected both field and value")
390
}
391
http.Header(*m).Set(field, val)
392
+ if d.NextBlock(0) {
393
+ return d.Err("malformed header matcher: blocks are not supported")
394
+ }
395
}
396
return nil
397
}
@@ -461,6 +476,10 @@ func (m *MatchHeaderRE) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
476
}
477
478
(*m)[field] = &MatchRegexp{Pattern: val, Name: name}
479
+
480
+ if d.NextBlock(0) {
481
+ return d.Err("malformed header_regexp matcher: blocks are not supported")
482
+ }
483
}
484
return nil
485
}
@@ -646,6 +665,9 @@ func (MatchRemoteIP) CaddyModule() caddy.ModuleInfo {
665
func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
666
for d.Next() {
667
m.Ranges = append(m.Ranges, d.RemainingArgs()...)
668
+ if d.NextBlock(0) {
669
+ return d.Err("malformed remote_ip matcher: blocks are not supported")
670
+ }
671
}
672
return nil
673
}
@@ -796,6 +818,9 @@ func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
818
default:
819
return d.ArgErr()
820
}
821
+ if d.NextBlock(0) {
822
+ return d.Err("malformed path_regexp matcher: blocks are not supported")
823
+ }
824
}
825
return nil
826
}