fix(server): authenticate websocket upgrades via session cookie - #21
Open
Antisophy wants to merge 1 commit into
Open
fix(server): authenticate websocket upgrades via session cookie#21Antisophy wants to merge 1 commit into
Antisophy wants to merge 1 commit into
Conversation
WebKit on old iOS Safari never attaches the basic-auth Authorization header to WebSocket upgrade requests, so /ws got a 401 on every attempt and the UI hung at "Connecting" forever. Generate a random token from /dev/urandom when the transport's auth credentials are configured, hand it to clients as an HttpOnly session cookie on the first authenticated page response, and accept that cookie in checkAuth as an alternative to basic auth. Browsers do attach cookies to WebSocket handshakes, so the upgrade authenticates after one authenticated page load. No frontend changes needed. The spec drives an authenticated page load, then replays the handshake condition directly: an upgrade carrying only the session cookie is accepted, and one carrying nothing stays rejected.
Owner
|
The HTTP basic mechanism has a few flaws (incl. that a cached client will fail to connect as the credentials dialog will not show), but cookie based sessions need more consideration than this - e.g. a proper implementation likely involves switching to a classical login form, and more importantly, a new logout button in the UI to invalidate the session server side. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebKit on old iOS Safari never attaches the basic-auth Authorization header to WebSocket upgrade requests, so /ws got a 401 on every attempt and the UI hung at "Connecting" forever.
Generate a random token from /dev/urandom when the transport's auth credentials are configured, hand it to clients as an HttpOnly session cookie on the first authenticated page response, and accept that cookie in checkAuth as an alternative to basic auth. Browsers do attach cookies to WebSocket handshakes, so the upgrade authenticates after one authenticated page load. No frontend changes needed.
The spec drives an authenticated page load, then replays the handshake condition directly: an upgrade carrying only the session cookie is accepted, and one carrying nothing stays rejected.