Skip to content

Commit 5bb8bb4

Browse files
committed
Adress review comments
1 parent 2a37a31 commit 5bb8bb4

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

docs/03-how-to-use-session-affinity.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ for the old non-partitioned `__VCAP_ID__` cookie alongside the new partitioned o
107107
<img src="images/sticky_sessions_chips_migration.png" alt="Sticky Sessions - CHIPS migration sequence" width="800">
108108

109109
### Does Gorouter support `__Host-` prefixed session cookies?
110-
Yes. [RFC 6265bis](https://www.rfc-editor.org/rfc/draft-ietf-httpbis-rfc6265bis-19.html#name-the-__host-prefix) defines
110+
Yes. [RFC 6265bis](https://datatracker.ietf.org/doc/draft-ietf-httpbis-rfc6265bis/) defines
111111
the `__Host-` cookie prefix, which instructs browsers to enforce additional security constraints
112112
(the cookie must be `Secure`, must not specify a `Domain`, and the `Path` must be `/`).
113113

@@ -135,7 +135,8 @@ browser's jar, the expected migration path is for the application to simply stop
135135
Note: if an application were to set a new `__Host-JSESSIONID` alongside a delete (`Max-Age=0`) for
136136
the old `JSESSIONID` in the same response, both would produce a `__VCAP_ID__` in the same cookie
137137
jar partition. Depending on processing order, the browser could apply the delete `__VCAP_ID__`
138-
after the new one, effectively removing it.
138+
after the new one, effectively removing it. Developers should therefore avoid setting both cookies
139+
in the same response to prevent temporarily losing session stickiness.
139140

140141
### What happens if only one of `JSESSIONID` or `__VCAP_ID__` cookies is set on a request?
141142
Gorouter requires both `JSESSIONID` and `__VCAP_ID__` to be present for sticky session routing.

src/code.cloudfoundry.org/gorouter/handlers/helpers.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ func GetStickySession(request *http.Request, stickySessionCookieNames config.Str
9191
// Try choosing a backend using sticky session.
9292
// Also match the "__Host-" prefixed variant of each configured cookie name (RFC 6265bis).
9393
for _, c := range request.Cookies() {
94-
name := c.Name
95-
if strings.HasPrefix(name, "__Host-") {
96-
name = name[7:]
97-
}
94+
name := strings.TrimPrefix(c.Name, "__Host-")
9895
if _, ok := stickySessionCookieNames[name]; ok {
9996
if sticky, err := request.Cookie(VcapCookieId); err == nil {
10097
return sticky.Value, false

src/code.cloudfoundry.org/gorouter/proxy/round_tripper/proxy_round_tripper.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,9 @@ func getSessionCookies(response *http.Response, stickySessionCookieNames config.
607607
// IsSessionCookie reports whether cookieName matches a configured sticky session cookie name,
608608
// either directly or after stripping the "__Host-" prefix (RFC 6265bis).
609609
func IsSessionCookie(cookieName string, stickySessionCookieNames config.StringSet) bool {
610-
if _, ok := stickySessionCookieNames[cookieName]; ok {
611-
return true
612-
}
613-
if strings.HasPrefix(cookieName, "__Host-") {
614-
_, ok := stickySessionCookieNames[cookieName[7:]]
615-
return ok
616-
}
617-
return false
610+
name := strings.TrimPrefix(cookieName, "__Host-")
611+
_, ok := stickySessionCookieNames[name]
612+
return ok
618613
}
619614

620615
// getAttributesFromMetaCookie returns the __VCAP_ID_META__ cookie from the request cookies, when it exists

0 commit comments

Comments
 (0)