Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: remove empty cookie from proxy and ignore in signer #143

Merged
merged 2 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/proxy/oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func deleteSSOCookieHeader(req *http.Request, cookieName string) {
headers = append(headers, cookie.String())
}
}

if len(headers) == 0 {
// there are no cookies other then session cookie so we delete the header entirely
req.Header.Del("Cookie")
return
}

// if there are other headers to keep, we set them minus the session cookie
req.Header.Set("Cookie", strings.Join(headers, ";"))
}

Expand Down
17 changes: 14 additions & 3 deletions internal/proxy/request_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func NewRequestSigner(signingKeyPemStr string) (*RequestSigner, error) {
// <URL>
// <BODY>
// where:
// <HEADER.k> is the ','-joined concatenation of all header values of `signedHeaders[k]`; all
// other headers in the request are ignored,
// <HEADER.k> is the ','-joined concatenation of all header values of `signedHeaders[k]`; empty
// values such as '' and all other headers in the request are ignored,
// <URL> is the string "<PATH>(?<QUERY>)(#FRAGMENT)", where "?<QUERY>" and "#<FRAGMENT>" are
// ommitted if the associated components are absent from the request URL,
// <BODY> is the body of the Request (may be `nil`; e.g. for GET requests).
Expand All @@ -109,7 +109,8 @@ func mapRequestToHashInput(req *http.Request) (string, error) {

// Add signed headers.
for _, hdr := range signedHeaders {
if hdrValues := req.Header[hdr]; len(hdrValues) > 0 {
hdrValues := removeEmpty(req.Header[hdr])
if len(hdrValues) > 0 {
entries = append(entries, strings.Join(hdrValues, ","))
}
}
Expand Down Expand Up @@ -189,3 +190,13 @@ func (signer RequestSigner) Sign(req *http.Request) error {
func (signer RequestSigner) PublicKey() (string, string) {
return signer.publicKeyID, signer.publicKeyStr
}

func removeEmpty(s []string) []string {
r := []string{}
for _, str := range s {
if len(str) > 0 {
r = append(r, str)
}
}
return r
}
1 change: 1 addition & 0 deletions internal/proxy/request_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func addHeaders(req *http.Request, examples []string, extras map[string][]string
"Content-Type": {"application/json"},
"Date": {"2018-11-08"},
"Authorization": {"Bearer ab12cd34"},
"Cookie": {""},
"X-Forwarded-User": {"octoboi"},
"X-Forwarded-Email": {"octoboi@example.com"},
"X-Forwarded-Groups": {"molluscs", "security_applications"},
Expand Down