yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
524 stars 262 forks source link

Invalid messages crash the server in a way that is un-preventable #82

Closed andrew-d-jackson closed 3 years ago

andrew-d-jackson commented 3 years ago

When you send up an invalid message that isn't binary (in this example I sent up a string like looks like this "...`") it throws an exception that is un-catchable by anyone using this library

This makes sense, the packet was not valid for y-websocket so it makes sense to throw. However the problem is that currently there is no way to catch this in a try catch block or prevent this from crashing the server because the error happens inside conn.on('message'). This means that it's very easy to DDoS y-websocket servers, by sending messages like the above and bringing them down. I got around this issue by forking y-websocket and adding a try catch in the utils.js messageListener function.

Ideally it would be great to catch this error and emit it somewhere were the end user can respond to it (conn.on('error') or doc.on('error)?)

Environment Information

Note: I am using the utils directly, and am not using the src/y-websocket.js code in my project, but I assume this error will happen there too