1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

caddyhttp: Strictly forbid unnecessary blocks on matchers (#3229)

This commit is contained in:
Francis Lavoie 2020-04-06 15:07:07 -04:00 committed by GitHub
parent a3cfe437b1
commit 5b355cbed0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -145,6 +145,9 @@ func (MatchHost) CaddyModule() caddy.ModuleInfo {
func (m *MatchHost) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (m *MatchHost) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() { for d.Next() {
*m = append(*m, d.RemainingArgs()...) *m = append(*m, d.RemainingArgs()...)
if d.NextBlock(0) {
return d.Err("malformed host matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -271,6 +274,9 @@ func (m MatchPath) Match(r *http.Request) bool {
func (m *MatchPath) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (m *MatchPath) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() { for d.Next() {
*m = append(*m, d.RemainingArgs()...) *m = append(*m, d.RemainingArgs()...)
if d.NextBlock(0) {
return d.Err("malformed path matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -301,6 +307,9 @@ func (MatchMethod) CaddyModule() caddy.ModuleInfo {
func (m *MatchMethod) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (m *MatchMethod) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() { for d.Next() {
*m = append(*m, d.RemainingArgs()...) *m = append(*m, d.RemainingArgs()...)
if d.NextBlock(0) {
return d.Err("malformed method matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -339,6 +348,9 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val()) return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val())
} }
url.Values(*m).Set(parts[0], parts[1]) url.Values(*m).Set(parts[0], parts[1])
if d.NextBlock(0) {
return d.Err("malformed query matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -374,9 +386,12 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() { for d.Next() {
var field, val string var field, val string
if !d.Args(&field, &val) { if !d.Args(&field, &val) {
return d.Errf("expected both field and value") return d.Errf("malformed header matcher: expected both field and value")
} }
http.Header(*m).Set(field, val) http.Header(*m).Set(field, val)
if d.NextBlock(0) {
return d.Err("malformed header matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -461,6 +476,10 @@ func (m *MatchHeaderRE) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
} }
(*m)[field] = &MatchRegexp{Pattern: val, Name: name} (*m)[field] = &MatchRegexp{Pattern: val, Name: name}
if d.NextBlock(0) {
return d.Err("malformed header_regexp matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -646,6 +665,9 @@ func (MatchRemoteIP) CaddyModule() caddy.ModuleInfo {
func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() { for d.Next() {
m.Ranges = append(m.Ranges, d.RemainingArgs()...) m.Ranges = append(m.Ranges, d.RemainingArgs()...)
if d.NextBlock(0) {
return d.Err("malformed remote_ip matcher: blocks are not supported")
}
} }
return nil return nil
} }
@ -796,6 +818,9 @@ func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
default: default:
return d.ArgErr() return d.ArgErr()
} }
if d.NextBlock(0) {
return d.Err("malformed path_regexp matcher: blocks are not supported")
}
} }
return nil return nil
} }