Skip to content

Commit

Permalink
caddyhttp: Corrected host label index check (fix #3502)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jun 30, 2020
1 parent ddd690d commit 77f233a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/caddyhttp/replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
reqHost = req.Host // OK; assume there was no port
}
hostLabels := strings.Split(reqHost, ".")
if idx > len(hostLabels) {
if idx >= len(hostLabels) {
return "", true
}
return hostLabels[len(hostLabels)-idx-1], true
Expand Down
4 changes: 4 additions & 0 deletions modules/caddyhttp/replacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ eqp31wM9il1n+guTNyxJd+FzVAH+hCZE5K+tCgVDdVFUlDEHHbS/wqb2PSIoouLV
input: "{http.request.host.labels.1}",
expect: "example",
},
{
input: "{http.request.host.labels.2}",
expect: "<empty>",
},
{
input: "{http.request.tls.cipher_suite}",
expect: "TLS_AES_256_GCM_SHA384",
Expand Down

0 comments on commit 77f233a

Please sign in to comment.