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

Gorouter does not support session affinity for WebSockets #351

Open
domdom82 opened this issue Sep 22, 2023 · 1 comment
Open

Gorouter does not support session affinity for WebSockets #351

domdom82 opened this issue Sep 22, 2023 · 1 comment
Assignees

Comments

@domdom82
Copy link
Contributor

Is this a security vulnerability?

No.

Issue

Gorouter supports session affinity as described in the docs.
However, this support currently works only for regular HTTP traffic. Requests to WebSocket apps ignore JSESSIONID or other session cookies and will be routed randomly instead.

Affected Versions

All.

Context

  • Session affinity is currently handled only in ProxyRoundTripper
  • ProxyRoundTripper does only handle regular HTTP traffic
  • WebSocket traffic is intercepted in Proxy and returns early. This explains why cookies are ignored.

Steps to Reproduce

  1. Push a CF app that implements a WebSocket that sets a JSESSIONID cookie
  2. Scale the app to two or more instances
  3. Re-use the JSESSIONID cookie in the next request
  4. Observe the backend instance that is used with the request

Expected result

The same instance is used that has originated the JSESSIONID cookie

Current result

A random instance is used. JSESSIONID cookie is ignored.

Possible Fix

  • Refactor the session affinity logic and move it out of ProxyRoundTripper, up one level, to Proxy.
  • Another option would be to add a specific handler for session handling that sets the endpoint hint for the load balancer in RequestInfo
  • The hint would then be picked up by ProxyRoundTripper and RequestHandler respectively.
  • A positive side-effect would be that the code length of ProxyRoundTripper would shrink considerably, making it easier to maintain down the road.
@maxmoehl
Copy link
Member

IMO option 2 (dedicated handler, communicate via RequestInfo) is the most desirable. RequestInfo is already used to communicate / collect information related to that request and it clearly separates the logic (hopefully) making the code more maintainable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pending Review | Discussion
Development

No branches or pull requests

3 participants