Skip to content

Commit 26fbd09

Browse files
authored
Merge pull request #143 from buzzfeed/jhines-remove-empty-cookie
proxy: remove empty cookie from proxy and ignore in signer
2 parents 97b15cb + 9ed2cb3 commit 26fbd09

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

internal/proxy/oauthproxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func deleteSSOCookieHeader(req *http.Request, cookieName string) {
112112
headers = append(headers, cookie.String())
113113
}
114114
}
115+
116+
if len(headers) == 0 {
117+
// there are no cookies other then session cookie so we delete the header entirely
118+
req.Header.Del("Cookie")
119+
return
120+
}
121+
122+
// if there are other headers to keep, we set them minus the session cookie
115123
req.Header.Set("Cookie", strings.Join(headers, ";"))
116124
}
117125

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)