Skip to content

Commit de0947d

Browse files
committed
proxy: signer should ignore empty string values
1 parent df7c47b commit de0947d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

internal/proxy/request_signer.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func NewRequestSigner(signingKeyPemStr string) (*RequestSigner, error) {
9696
// <URL>
9797
// <BODY>
9898
// where:
99-
// <HEADER.k> is the ','-joined concatenation of all header values of `signedHeaders[k]`; all
100-
// other headers in the request are ignored,
99+
// <HEADER.k> is the ','-joined concatenation of all header values of `signedHeaders[k]`; empty
100+
// values such as '' and all other headers in the request are ignored,
101101
// <URL> is the string "<PATH>(?<QUERY>)(#FRAGMENT)", where "?<QUERY>" and "#<FRAGMENT>" are
102102
// ommitted if the associated components are absent from the request URL,
103103
// <BODY> is the body of the Request (may be `nil`; e.g. for GET requests).
@@ -109,7 +109,8 @@ func mapRequestToHashInput(req *http.Request) (string, error) {
109109

110110
// Add signed headers.
111111
for _, hdr := range signedHeaders {
112-
if hdrValues := req.Header[hdr]; len(hdrValues) > 0 {
112+
hdrValues := removeEmpty(req.Header[hdr])
113+
if len(hdrValues) > 0 {
113114
entries = append(entries, strings.Join(hdrValues, ","))
114115
}
115116
}
@@ -189,3 +190,13 @@ func (signer RequestSigner) Sign(req *http.Request) error {
189190
func (signer RequestSigner) PublicKey() (string, string) {
190191
return signer.publicKeyID, signer.publicKeyStr
191192
}
193+
194+
func removeEmpty(s []string) []string {
195+
r := []string{}
196+
for _, str := range s {
197+
if len(str) > 0 {
198+
r = append(r, str)
199+
}
200+
}
201+
return r
202+
}

internal/proxy/request_signer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func addHeaders(req *http.Request, examples []string, extras map[string][]string
2727
"Content-Type": {"application/json"},
2828
"Date": {"2018-11-08"},
2929
"Authorization": {"Bearer ab12cd34"},
30+
"Cookie": {""},
3031
"X-Forwarded-User": {"octoboi"},
3132
"X-Forwarded-Email": {"[email protected]"},
3233
"X-Forwarded-Groups": {"molluscs", "security_applications"},

0 commit comments

Comments
 (0)