Skip to content

Commit

Permalink
caddyhttp: Fix header matcher when using nil
Browse files Browse the repository at this point in the history
Uncovered in caddyserver#3807
  • Loading branch information
mholt committed Nov 17, 2020
1 parent 99b8f44 commit 4fc5707
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/caddyhttp/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ func matchHeaders(input, against http.Header, host string) bool {
// match if the header field exists at all
continue
}
if allowedFieldVals == nil && actualFieldVals == nil {
// a nil list means match if the header does not exist at all
continue
}
var match bool
fieldVals:
for _, actualFieldVal := range actualFieldVals {
Expand Down
10 changes: 10 additions & 0 deletions modules/caddyhttp/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ func TestHeaderMatcher(t *testing.T) {
host: "caddyserver.com",
expect: false,
},
{
match: MatchHeader{"Must-Not-Exist": nil},
input: http.Header{},
expect: true,
},
{
match: MatchHeader{"Must-Not-Exist": nil},
input: http.Header{"Must-Not-Exist": []string{"do not match"}},
expect: false,
},
} {
req := &http.Request{Header: tc.input, Host: tc.host}
actual := tc.match.Match(req)
Expand Down

0 comments on commit 4fc5707

Please sign in to comment.