Skip to content

WebSocket: wrong subprotocol choose check (response Sec-WebSocket-Protocol header) #2844

@farwayer

Description

@farwayer

Bug Description

  1. client sends Sec-WebSocket-Protocol header with protocol list (separated by ',')
  2. server responds with one protocol from this list
  3. WebSocket client compares request header (protocol list) with response header (one protocol) value and fails with the error Protocol was not set in the opening handshake

if (secProtocol !== null && secProtocol !== request.headersList.get('Sec-WebSocket-Protocol')) {

Reproducible By

let ws = new WebSocket('ws://server...', ['msgpack', 'json'])
ws.addEventListener('error', e => console.log(e.error))
// server choses json and responds with `Sec-WebSocket-Protocol: json`
// client failed

Expected Behavior

Correct subprotocol check

Environment

  • Node.js v21.6.2
  • --experimental-websocket flag

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions