Skip to content

Conversation

@lukebakken
Copy link
Collaborator

Addresses #15001

The Web MQTT handler only accepts the mqtt WebSocket subprotocol, rejecting clients that request mqttv3.1. This prevents some MQTT clients from establishing WebSocket connections.

This change updates the protocol negotiation to accept either mqtt or mqttv3.1 subprotocols. The handler uses lists:search/2 to find the first matching protocol and echoes that exact value back in the sec-websocket-protocol response header, ensuring proper protocol negotiation with the client.

Addresses rabbitmq#15001

The Web MQTT handler only accepts the `mqtt` WebSocket subprotocol,
rejecting clients that request `mqttv3.1`. This prevents some MQTT
clients from establishing WebSocket connections.

This change updates the protocol negotiation to accept either `mqtt` or
`mqttv3.1` subprotocols. The handler uses `lists:search/2` to find the
first matching protocol and echoes that exact value back in the
`sec-websocket-protocol` response header, ensuring proper protocol
negotiation with the client.
@lukebakken lukebakken self-assigned this Nov 24, 2025
@lukebakken lukebakken marked this pull request as draft November 24, 2025 19:44
Copy link
Collaborator

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like VerneMQ has similar handling code for sec-websocket-protocol and matching mqttv3.1 or mqtt: https://github.com/vernemq/vernemq/blob/main/apps/vmq_server/src/vmq_websocket.erl. We should also follow this approach and parse this header as a list, checking membership with supported protocols.

@lukebakken lukebakken marked this pull request as ready for review November 24, 2025 20:00
@lukebakken
Copy link
Collaborator Author

@the-mikedavis yep that's exactly what this PR does, minus the macro 😸

@the-mikedavis
Copy link
Collaborator

the-mikedavis commented Nov 24, 2025

Aha, cowboy_req:parse_header/3 for <<"sec-websocket-protocol">> is already handling the list part - I totally missed that 😅

Looks like it's guaranteed to be a list of binaries: https://github.com/ninenines/cowlib/blob/f30cc9e2fbb14705751cbe2c32895f59d91e4906/src/cow_http_hd.erl#L2851-L2855

@michaelklishin michaelklishin added this to the 4.3.0 milestone Nov 24, 2025
@michaelklishin michaelklishin merged commit d8da574 into rabbitmq:main Nov 24, 2025
289 checks passed
@the-mikedavis the-mikedavis deleted the rabbitmq-server-15001 branch November 24, 2025 20:59
michaelklishin added a commit that referenced this pull request Nov 25, 2025
Support `mqttv3.1` WebSocket subprotocol in addition to `mqtt` (backport #15008)
michaelklishin added a commit that referenced this pull request Nov 25, 2025
Support `mqttv3.1` WebSocket subprotocol in addition to `mqtt` (backport #15008) (backport #15009)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants