Unauthenticated denial of service of the Realtime daemon via malformed client input
Description
A single malformed websocket frame or HTTP request from a visitor stops the Realtime extension's daemon (flarum/realtime), disconnecting every connected user. No account and no signature are needed.
Details
For pusher: events, extensions/realtime/src/Websocket/Message/ProtocolMessage.php turns the rest of the event name into a method name and calls it with the frame's data value. subscribe() and unsubscribe() declare that argument as stdClass, so a frame whose data is a string makes PHP throw a TypeError. Ratchet's server catches only \Exception around message handling; a TypeError is an \Error, so it ends the daemon process. Other frame shapes end it the same way: a channel that is a list, or an event that is a list. Sending a frame needs only the app key, which is public in the forum payload, and an Origin header naming the forum host, which a non-browser client sets itself.
Two other inputs end the process the same way, before any key or signature is checked:
- a request to the daemon's HTTP interface (
/apps/1/...) with aContent-Lengthheader that is not a number (Connection/Controller.php,contentLength()); - a websocket handshake whose
appKeyquery parameter is a list, such asappKey[]=x(Server/QueryParams.php,get()).
The fix checks the shape of each frame before use (event a string, data an object naming a string channel), dispatches only to the named protocol handlers (ping, subscribe, unsubscribe), and reads query parameters and Content-Length only in the expected shape. As a backstop, the daemon's HTTP server now closes only the offending connection if handling its input raises an error.
Proof of concept
On a forum with Realtime enabled and its daemon running:
- Read the app key from the forum payload.
- Open a websocket to the daemon with that key and an
Originheader naming the forum host. - Send
{"event":"pusher:subscribe","data":"x"}.
The daemon exits with Uncaught TypeError: ...ProtocolMessage::subscribe(): Argument #2 ($payload) must be of type stdClass, string given, and every other client is disconnected.
Without any key, POST /apps/1/events with the header Content-Length: abc, or a websocket handshake to /app/x?appKey[]=x, ends the process the same way.
Impact
Any visitor can stop realtime updates (new posts, notifications, typing indicators) for every user, and keep them stopped by sending the frame again each time a supervisor restarts the daemon. The forum itself keeps working: pages load and posting works without realtime updates.
Patches
Fixed in flarum/realtime 2.0.3 (Flarum 2.0) and 2.1.0-beta.2.1 (Flarum 2.1 beta). Update, then restart the daemon with your process manager (or stop and start php flarum realtime:serve):
composer update flarum/realtimeWorkarounds
None short of disabling the Realtime extension (or stopping its daemon) until you can update.
References
- CWE-20: Improper Input Validation
- CWE-248: Uncaught Exception
- Affected files:
extensions/realtime/src/Websocket/Message/ProtocolMessage.php,extensions/realtime/src/Websocket/Message/Factory.php,extensions/realtime/src/Websocket/Connection/Controller.php,extensions/realtime/src/Websocket/Server/QueryParams.php