summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-09-13 13:18:37 -0400
committerGitHub <noreply@github.com>2022-09-13 11:18:37 -0600
commit61c75f74dec6b0524feef9b24ef8d6005f096b09 (patch)
tree12846639933363b6fdeaeb4e3e6ea157221c6144 /modules/caddyhttp/matchers.go
parentd35f618b10e9f530b068f42d1dcecb9e70b6ae0a (diff)
caddyhttp: Explicitly disallow multiple regexp matchers (#5030)
* caddyhttp: Explicitly disallow multiple regexp matchers Fix #5028 Since the matchers would overwrite eachother, we should error out to tell the user their config doesn't make sense. * Update modules/caddyhttp/matchers.go Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index f86ce0a..3d5791f 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -1001,6 +1001,12 @@ func (m *MatchHeaderRE) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
val = second
}
+ // If there's already a pattern for this field
+ // then we would end up overwriting the old one
+ if (*m)[field] != nil {
+ return d.Errf("header_regexp matcher can only be used once per named matcher, per header field: %s", field)
+ }
+
(*m)[field] = &MatchRegexp{Pattern: val, Name: name}
if d.NextBlock(0) {
@@ -1469,6 +1475,13 @@ func (mre *MatchRegexp) Match(input string, repl *caddy.Replacer) bool {
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
+ // If this is the second iteration of the loop
+ // then there's more than one path_regexp matcher
+ // and we would end up overwriting the old one
+ if mre.Pattern != "" {
+ return d.Err("regular expression can only be used once per named matcher")
+ }
+
args := d.RemainingArgs()
switch len(args) {
case 1: