@marcel91200 / caddy Mirror · read-only / commits / 61c75f74
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 13, 13:00 UTC

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>

Francis Lavoie committed Sep 13, 2022 at 13:18 UTC 61c75f74dec6b0524feef9b24ef8d6005f096b09
1 file changed +13
modules/caddyhttp/matchers.go
+13
@@ -1001,6 +1001,12 @@ func (m *MatchHeaderRE) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
1001 val = second
1002 }
1003
1004 + // If there's already a pattern for this field
1005 + // then we would end up overwriting the old one
1006 + if (*m)[field] != nil {
1007 + return d.Errf("header_regexp matcher can only be used once per named matcher, per header field: %s", field)
1008 + }
1009 +
1010 (*m)[field] = &MatchRegexp{Pattern: val, Name: name}
1011
1012 if d.NextBlock(0) {
@@ -1469,6 +1475,13 @@ func (mre *MatchRegexp) Match(input string, repl *caddy.Replacer) bool {
1475 // UnmarshalCaddyfile implements caddyfile.Unmarshaler.
1476 func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
1477 for d.Next() {
1478 + // If this is the second iteration of the loop
1479 + // then there's more than one path_regexp matcher
1480 + // and we would end up overwriting the old one
1481 + if mre.Pattern != "" {
1482 + return d.Err("regular expression can only be used once per named matcher")
1483 + }
1484 +
1485 args := d.RemainingArgs()
1486 switch len(args) {
1487 case 1: