Skip to content

Commit

Permalink
fix: remove partitioned cookie workaround (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmoehl authored Sep 26, 2024
1 parent 8c4f7a4 commit 38453e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
40 changes: 10 additions & 30 deletions proxy/round_tripper/proxy_round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http/httptrace"
"net/textproto"
"net/url"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -63,20 +62,6 @@ func GetRoundTripper(endpoint *route.Endpoint, roundTripperFactory RoundTripperF
return endpoint.RoundTripper()
}

type Cookie struct {
http.Cookie
// indicates, whether this cookie is partitioned. Relevant for embedding in iframes.
Partitioned bool
}

func (c *Cookie) String() string {
cookieString := c.Cookie.String()
if c.Partitioned {
return cookieString + "; Partitioned"
}
return cookieString
}

//go:generate counterfeiter -o fakes/fake_error_handler.go --fake-name ErrorHandler . errorHandler
type errorHandler interface {
HandleError(utils.ProxyResponseWriter, error)
Expand Down Expand Up @@ -451,11 +436,8 @@ func setupStickySession(
secure = v.Secure
sameSite = v.SameSite
expiry = v.Expires
partitioned = v.Partitioned

// temporary workaround for "Partitioned" cookies, used in embedded websites (iframe),
// until Golang natively supports parsing the Partitioned flag.
// See also https://github.com/golang/go/issues/62490
partitioned = slices.Contains(v.Unparsed, "Partitioned")
break
}
}
Expand All @@ -475,17 +457,15 @@ func setupStickySession(
secure = true
}

vcapIDCookie := &Cookie{
Cookie: http.Cookie{
Name: VcapCookieId,
Value: endpoint.PrivateInstanceId,
Path: path,
MaxAge: maxAge,
HttpOnly: true,
Secure: secure,
SameSite: sameSite,
Expires: expiry,
},
vcapIDCookie := http.Cookie{
Name: VcapCookieId,
Value: endpoint.PrivateInstanceId,
Path: path,
MaxAge: maxAge,
HttpOnly: true,
Secure: secure,
SameSite: sameSite,
Expires: expiry,
Partitioned: partitioned,
}

Expand Down
21 changes: 7 additions & 14 deletions proxy/round_tripper/proxy_round_tripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ var _ = Describe("ProxyRoundTripper", func() {

Context("when using sticky sessions", func() {
var (
sessionCookie *round_tripper.Cookie
sessionCookie *http.Cookie
endpoint1 *route.Endpoint
endpoint2 *route.Endpoint

Expand Down Expand Up @@ -1090,11 +1090,9 @@ var _ = Describe("ProxyRoundTripper", func() {
}

setVCAPID := func(resp *http.Response) (response *http.Response) {
vcapCookie := round_tripper.Cookie{
Cookie: http.Cookie{
Name: round_tripper.VcapCookieId,
Value: "vcap-id-property-already-on-the-response",
},
vcapCookie := http.Cookie{
Name: round_tripper.VcapCookieId,
Value: "vcap-id-property-already-on-the-response",
}

if c := vcapCookie.String(); c != "" {
Expand Down Expand Up @@ -1138,10 +1136,8 @@ var _ = Describe("ProxyRoundTripper", func() {
}

JustBeforeEach(func() {
sessionCookie = &round_tripper.Cookie{
Cookie: http.Cookie{
Name: StickyCookieKey, //JSESSIONID
},
sessionCookie = &http.Cookie{
Name: StickyCookieKey, //JSESSIONID
}

endpoint1 = route.NewEndpoint(&route.EndpointOpts{
Expand Down Expand Up @@ -1433,10 +1429,7 @@ var _ = Describe("ProxyRoundTripper", func() {
newCookies := resp.Cookies()
Expect(newCookies).To(HaveLen(2))
Expect(newCookies[0].Raw).To(Equal(sessionCookie.String()))

// This should fail when Golang introduces parsing for the Partitioned flag on cookies.
// see https://github.com/golang/go/issues/62490
Expect(newCookies[0].Unparsed).To(Equal([]string{"Partitioned"}))
Expect(newCookies[0].Partitioned).To(BeTrue())

Expect(newCookies[1].Name).To(Equal(round_tripper.VcapCookieId))
Expect(newCookies[1].Value).To(Equal(cookies[1].Value)) // still pointing to the same app
Expand Down

0 comments on commit 38453e0

Please sign in to comment.