Skip to content

Commit 0ef2856

Browse files
committed
Verify signatures with Host header
Golang promotes the "Host" header in a server-side request by removing it from the Header map and putting it into the Host field, which had the effect of removing the "Host" header and failing validation. Now, we successfully validate HTTP Signatures that contain a "Host" header.
1 parent f4c3604 commit 0ef2856

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

httpsig.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,22 @@ type Verifier interface {
186186
Verify(pKey crypto.PublicKey, algo Algorithm) error
187187
}
188188

189+
const (
190+
// host is treated specially because golang may not include it in the
191+
// request header map on the server side of a request.
192+
hostHeader = "Host"
193+
)
194+
189195
// NewVerifier verifies the given request. It returns an error if the HTTP
190196
// Signature parameters are not present in any headers, are present in more than
191197
// one header, are malformed, or are missing required parameters. It ignores
192198
// unknown HTTP Signature parameters.
193199
func NewVerifier(r *http.Request) (Verifier, error) {
194-
return newVerifier(r.Header, func(h http.Header, toInclude []string) (string, error) {
200+
h := r.Header
201+
if _, hasHostHeader := h[hostHeader]; len(r.Host) > 0 && !hasHostHeader {
202+
h[hostHeader] = []string{r.Host}
203+
}
204+
return newVerifier(h, func(h http.Header, toInclude []string) (string, error) {
195205
return signatureString(h, toInclude, addRequestTarget(r))
196206
})
197207
}

0 commit comments

Comments
 (0)