You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Secure WebSocket connection with cookie authentication (#621)
This PR adds the support of cookie when using the websocket protocol. To do that, when Kuzzle cookieAuth option is true, Kuzzle will call the method enableCookieSupport from the given protocol. When called, this method will throw if outside the browser or if cookie are not supported by the protocol, otherwise this will change how the protocol behave.
For the HTTP protocol it's simple, when enableCookieSupport is called, the protocol will be changing if the request are made with withCredentials set to true or false depending if he should be able to receive cookies.
For the Websocket protocol, this is a bit more complex, when enableCookieSupport is called, the protocol, will be creating a instance of the HTTP Protocol, with the same option (host, port, ssl, ...) as the websocket protocol, after that, when a request auth:login, auth:logout or auth:refreshToken is made, the protocol will use the HTTP Protocol instead of the websocket client to make the request.
[ex: auth:login request is made -> websocket closes the connection -> then send the request with the http protocol -> when a response is received it reopens the connection -> then resolve the request]
Copy file name to clipboardExpand all lines: doc/7/protocols/websocket/introduction/index.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,3 +23,28 @@ This application-level PING has been especially added for web browsers, which do
23
23
When run in a browser, our Javascript SDK uses that feature for its keep-alive mechanism: a message will periodically be sent to Kuzzle in the form `"{"p":1}"` through websocket.
24
24
That message will call a response from Kuzzle in the form `"{"p":2}"` for the SDK to keep the connection alive.
25
25
26
+
### Cookie Authentication
27
+
28
+
Kuzzle supports cookie authentications, meaning that when using this SDK in a browser, you can ask Kuzzle to return authentication tokens in secure cookies, handled by browsers. This means that, when using that option, browser clients will never have access to said tokens, preventing a few common attacks.
29
+
The support for cookie authentication can be enabled, using the [cookieAuth](/sdk/js/7/core-classes/kuzzle/constructor) option at the SDK initialization.
30
+
31
+
When you enable the [cookieAuth](/sdk/js/7/core-classes/kuzzle/constructor) option, it changes the way the websocket protocol behaves when you're sending requests that should otherwise return authentication tokens in their response payload.
32
+
33
+
When a request susceptible of changing an authentication cookie is about to be sent, the WebSocket Protocol send it using the [HTTP Protocol](/sdk/js/7/protocols/http/introduction) instead, to allow browsers to apply the received cookie.
34
+
35
+
If a new cookie is received from Kuzzle that way, the WebSocket connection is automatically renewed.
36
+
37
+
::: info
38
+
Cookies can only be applied to WebSocket connections during the connection handshake (upgrade from HTTP to WebSocket), and they stay valid as long as the connection is active, and as long as the cookie hasn't expired.
Here is a list of controller's actions that are affected by this behavior, when the [cookieAuth](/sdk/js/7/core-classes/kuzzle/constructor) option is enabled:
0 commit comments