Repository navigation
proto_ws: mask empty frames sent as a client - #4455
Open
dragos-oancea wants to merge 1 commit into
Open
dragos-oancea wants to merge 1 commit into
dragos-oancea wants to merge 1 commit into
Conversation
A WebSocket client must mask every frame, even one with no payload (RFC 6455, section 5.1). A server must close the connection when it gets an unmasked frame. ws_send() sent empty frames without the mask bit and the mask key, also when OpenSIPS is the client. So when a server sends an empty PING, OpenSIPS answers with an unmasked PONG, and a strict server (OpenSIPS itself, for example) closes the connection. Now a client always adds the mask, also for empty frames. This also fixes proto_wss, which uses the same code.
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.
Summary
proto_ws/proto_wss: when OpenSIPS is a WebSocket client, it sends empty frames without a mask.
Details
This is a bug fix.
The WebSocket standard (RFC 6455, section 5.1) says:
OpenSIPS has a shortcut for frames with no data. It sends only the 2-byte header. It does not add the mask, even when OpenSIPS is the client.
Example: OpenSIPS connects to a server over WS or WSS. The server sends an empty PING to keep the connection alive. OpenSIPS answers with a PONG without a mask. The server closes the connection. An OpenSIPS server does the same ("malformed WS msg").
Solution
Remove the shortcut. A client now always adds the mask, also to empty frames. Frames with data, and frames sent by a server, do not change.
proto_wss uses the same code, so it is fixed too.