fix: the server could crash if a client sends invalid frames

This commit is contained in:
Jonas Gloning 2022-11-17 20:58:06 +01:00
parent 3165d77f60
commit 29394dea5e
No known key found for this signature in database
GPG Key ID: 684639B5E59E7614

View File

@ -47,6 +47,9 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
} }
private _onSocketConnection(socket: WebSocket, req: IncomingMessage): void { private _onSocketConnection(socket: WebSocket, req: IncomingMessage): void {
// An unhandled socket error might crash the server. Handle it first.
socket.on("error", error => this._onSocketError(error))
const { query = {} } = url.parse(req.url ?? '', true); const { query = {} } = url.parse(req.url ?? '', true);
const { id, token, key }: IAuthParams = query; const { id, token, key }: IAuthParams = query;