git.iko.soy/typeable/oauth2-proxy
on master help sign in
Fix - Refresh Session not working for multiple cookies (#1209) (#1227)

* Fix - Refresh Session not working for multiple cookies (#1209) * added comments for flattenheaders fix Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> * Updated Changelog.md Co-authored-by: Rishi Kambil <rishi.kambil@lntinfotech.com> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

commit41cd418a5d9a2aafaa8d8080fcaaeb1072afbc91 authorRishi Kambil <rishikambil@gmail.com> dateWed 9 Jun 2021, 14:52 (5 years ago) parentcfd82da
3 files changed+39−2
CHANGELOG.md+1−1 pkg/middleware/headers.go+2−1 pkg/middleware/headers_test.go+36
CHANGELOG.md+1−1
@@ -7,7 +7,7 @@
77## Breaking Changes
88
99## Changes since v7.1.3
10−
10+- [#1227](https://github.com/oauth2-proxy/oauth2-proxy/pull/1227) Fix Refresh Session not working for multiple cookies (@rishi1111)
1111- [#1063](https://github.com/oauth2-proxy/oauth2-proxy/pull/1063) Add Redis lock feature to lock persistent sessions (@Bibob7)
1212- [#1108](https://github.com/oauth2-proxy/oauth2-proxy/pull/1108) Add alternative ways to generate cookie secrets to docs (@JoelSpeed)
1313- [#1142](https://github.com/oauth2-proxy/oauth2-proxy/pull/1142) Add pagewriter to upstream proxy (@JoelSpeed)
pkg/middleware/headers.go+2−1
@@ -43,7 +43,8 @@ func newStripHeaders(headers []options.Header) alice.Constructor {
4343
4444func flattenHeaders(headers http.Header) {
4545 for name, values := range headers {
46− if len(values) > 1 {
46+ // Set-Cookie should not be flattened, ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
47+ if len(values) > 1 && name != "Set-Cookie" {
4748 headers.Set(name, strings.Join(values, ","))
4849 }
4950 }
pkg/middleware/headers_test.go+36
@@ -253,6 +253,42 @@ var _ = Describe("Headers Suite", func() {
253253 },
254254 expectedErr: "",
255255 }),
256+
257+ Entry("with flattenHeaders (set-cookie and any other)", headersTableInput{
258+ headers: []options.Header{
259+ {
260+ Name: "Set-Cookie",
261+ Values: []options.HeaderValue{
262+ {
263+ SecretSource: &options.SecretSource{
264+ Value: []byte("_oauth2_proxy=ey123123123"),
265+ },
266+ },
267+ },
268+ },
269+ {
270+ Name: "X-Auth-User",
271+ Values: []options.HeaderValue{
272+ {
273+ SecretSource: &options.SecretSource{
274+ Value: []byte("oauth_user"),
275+ },
276+ },
277+ },
278+ },
279+ },
280+ initialHeaders: http.Header{
281+ "Set-Cookie": []string{"cookie1=value1", "cookie2=value2"},
282+ "X-Auth-User": []string{"oauth_user_1"},
283+ },
284+
285+ expectedHeaders: http.Header{
286+ "Set-Cookie": []string{"cookie1=value1", "cookie2=value2", "_oauth2_proxy=ey123123123"},
287+ "X-Auth-User": []string{"oauth_user_1,oauth_user"},
288+ },
289+ expectedErr: "",
290+ }),
291+
256292 Entry("with a claim valued header", headersTableInput{
257293 headers: []options.Header{
258294 {