From 0ace009a54f6b781def9386298a2b053f3224bc6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 18 Aug 2020 22:52:54 +0900 Subject: [PATCH] fix(server): Prevent error when recieve non-json data from websocket Fix #6658 --- src/server/api/stream/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index d420c6e79..36e08ec05 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -71,7 +71,15 @@ export default class Connection { private async onWsConnectionMessage(data: websocket.IMessage) { if (data.utf8Data == null) return; - const { type, body } = JSON.parse(data.utf8Data); + let obj: Record; + + try { + obj = JSON.parse(data.utf8Data); + } catch (e) { + return; + } + + const { type, body } = obj; switch (type) { case 'api': this.onApiRequest(body); break;