Skip to content

proto_ws: mask empty frames sent as a client - #4455

Open
dragos-oancea wants to merge 1 commit into
OpenSIPS:masterfrom
dragos-oancea:fix/proto_ws-mask-empty-frames
Open

dragos-oancea wants to merge 1 commit into
OpenSIPS:masterfrom
dragos-oancea:fix/proto_ws-mask-empty-frames

Conversation

@dragos-oancea

Copy link
Copy Markdown
Contributor

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:

  • A client must mask every frame. This includes frames with no data.
  • A server must close the connection if it gets a frame without a mask.

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant