From bb10858e2736e1eeee10681d7af3a5fb82e3e3c9 Mon Sep 17 00:00:00 2001 From: Ayush7614 Date: Sun, 6 Sep 2026 01:15:54 +0530 Subject: [PATCH 1/2] fix(app): guard live screen socket against non-object payloads --- app/src/components/computer/live-screen.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/components/computer/live-screen.tsx b/app/src/components/computer/live-screen.tsx index bbc989389..00ab436b4 100644 --- a/app/src/components/computer/live-screen.tsx +++ b/app/src/components/computer/live-screen.tsx @@ -64,18 +64,26 @@ export function LiveScreen({ computerId, driving, onProblem }: Props) { }; socket.onmessage = async (event) => { - let message: { + let parsed: unknown; + try { + parsed = JSON.parse(String(event.data)); + } catch { + return; + } + // A frame that is not an object (`null`, a number, a string, an array) has + // no `type` to read: reaching for it throws a `TypeError` inside this + // handler and stops the live view from drawing further frames. Drop it. + if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + return; + } + const message = parsed as { type: string; data?: string; width?: number; height?: number; error?: string; }; - try { - message = JSON.parse(String(event.data)); - } catch { - return; - } + if (typeof message.type !== "string") return; if (message.type === "error") { onProblem?.(message.error ?? "The screen could not be shown."); return; From ba7015ad156e7abdcc488f9034ae7bba25ef6658 Mon Sep 17 00:00:00 2001 From: David McKay Date: Sun, 6 Sep 2026 09:21:18 -0700 Subject: [PATCH 2/2] format --- app/src/components/computer/live-screen.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/components/computer/live-screen.tsx b/app/src/components/computer/live-screen.tsx index 00ab436b4..370231122 100644 --- a/app/src/components/computer/live-screen.tsx +++ b/app/src/components/computer/live-screen.tsx @@ -73,7 +73,11 @@ export function LiveScreen({ computerId, driving, onProblem }: Props) { // A frame that is not an object (`null`, a number, a string, an array) has // no `type` to read: reaching for it throws a `TypeError` inside this // handler and stops the live view from drawing further frames. Drop it. - if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + if ( + typeof parsed !== "object" || + parsed === null || + Array.isArray(parsed) + ) { return; } const message = parsed as {