Executive brief
@fastify/websocket is a popular WebSocket support library for the Fastify web framework. A vulnerability in the library causes the application to crash when processing certain malformed WebSocket packets (such as those with invalid control bits), resulting in a denial-of-service condition. Attackers with network access can send a single crafted packet to crash the entire server and interrupt service for all users.
Technical details
This is an uncaught exception vulnerability (CWE-248) in the WebSocket packet parsing logic. When the underlying 'ws' library encounters certain malformed WebSocket frames—specifically packets with RSV2 and RSV3 bits set without negotiation—it throws a RangeError that is not caught by @fastify/websocket. The error propagates uncaught, causing a Node.js process crash. The vulnerability is triggered by sending a malformed packet over the network to an application using @fastify/websocket; no authentication or user interaction is required. The attack vector is network-based with no complexity requirement. The fix adds an error handler to gracefully catch and handle these exceptions. Patches are available in @fastify/websocket v5.0.1 (for fastify v3) and v7.1.1 (for fastify v4). The deprecated fastify-websocket module is not being patched.
Affected products
- fastify @fastify/websocket 5.0.0 to <5.0.1, >=6.0.0 to <7.1.1
- fastify-websocket all versions through 4.3.0 (deprecated, unpatched)
Timeline
- 2022-11-07: disclosed: Advisory GHSA-4pcg-wr6c-h9cq published
- 2022-11-04: patched: Fixed in @fastify/websocket v5.0.1 and v7.1.1
References
- https://github.com/fastify/fastify-websocket/security/advisories/GHSA-4pcg-wr6c-h9cq
- https://github.com/fastify/fastify-websocket/pull/228
- https://github.com/fastify/fastify-websocket/commit/7e8c41a51c101c3d5ce88caee4f71d9c29eb2863
- https://github.com/fastify/fastify-websocket/commit/c24adeb3efd57a18b2f287c35d029e88b5a47194
- https://github.com/fastify/fastify-websocket
- https://github.com/fastify/fastify-websocket/releases/tag/v5.0.1