Explorar o código

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

Jonas Gloning %!s(int64=2) %!d(string=hai) anos
pai
achega
29394dea5e
Modificáronse 1 ficheiros con 3 adicións e 0 borrados
  1. 3 0
      src/services/webSocketServer/index.ts

+ 3 - 0
src/services/webSocketServer/index.ts

@@ -47,6 +47,9 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
   }
 
   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 { id, token, key }: IAuthParams = query;