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: Fix header matcher when using nil
Uncovered in #3807
Matthew Holt committed
Nov 17, 2020 at 11:29 UTC
4fc570711e170da2bd1164966d2c47f9dc3d3d6d
2 files changed
+14
modules/caddyhttp/matchers.go
+4
@@ -445,6 +445,10 @@ func matchHeaders(input, against http.Header, host string) bool {
445
// match if the header field exists at all
446
continue
447
}
448
+ if allowedFieldVals == nil && actualFieldVals == nil {
449
+ // a nil list means match if the header does not exist at all
450
+ continue
451
+ }
452
var match bool
453
fieldVals:
454
for _, actualFieldVal := range actualFieldVals {
modules/caddyhttp/matchers_test.go
+10
@@ -480,6 +480,16 @@ func TestHeaderMatcher(t *testing.T) {
480
host: "caddyserver.com",
481
expect: false,
482
},
483
+ {
484
+ match: MatchHeader{"Must-Not-Exist": nil},
485
+ input: http.Header{},
486
+ expect: true,
487
+ },
488
+ {
489
+ match: MatchHeader{"Must-Not-Exist": nil},
490
+ input: http.Header{"Must-Not-Exist": []string{"do not match"}},
491
+ expect: false,
492
+ },
493
} {
494
req := &http.Request{Header: tc.input, Host: tc.host}
495
actual := tc.match.Match(req)