WebSockets: support passing through sec-websocket-protocol header #5904
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.
Opening this MR to begin a wider discussion on this.
Let's start with the current state of things: in Phoenix it's not possible to access any headers of Websocket connections except the X-Foo headers if you explicitly enable it with
connect_info: [:x_headers]
. The docs are very clear about this limitation:However, this severely limits the capabilities of Phoenix. We converted Pleroma from Phoenix+Cowboy for websockets to
Phoenix.Socket.Transport
so we could support both Cowboy and Bandit. In the process I encountered a weird test case we had written that validated you could pass through an auth token in theSec-WebSocket-Protocol
header.Nobody could remember at the time why this existed.
It turns out, this is actually how the Mastodon client protocol authenticates over websockets!
At first I thought this was a case of abusing this header for something it wasn't meant for. The RFC doesn't make it sound like this is the purpose of the header. So why were they doing it this way?
As it turns out, lots of applications do this. Here's one from 3 weeks ago doing it in AWS Lambda.
So how can we make sure Phoenix is a suitable framework for all types of Websocket applications/protocols as the current limitations are very narrow-sighted? I do not want to have to maintain a fork of Phoenix to support this.