From 7a8b10bd7da6661ced54ca93985a7e628079544f Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 13:09:20 -0700 Subject: [PATCH] Guard remote runtime PTY id decoding (#3626) --- .../src/runtime/runtime-terminal-stream.test.ts | 7 +++++++ src/renderer/src/runtime/runtime-terminal-stream.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/runtime/runtime-terminal-stream.test.ts b/src/renderer/src/runtime/runtime-terminal-stream.test.ts index d08b413af..0c42a7345 100644 --- a/src/renderer/src/runtime/runtime-terminal-stream.test.ts +++ b/src/renderer/src/runtime/runtime-terminal-stream.test.ts @@ -27,6 +27,13 @@ describe('remote runtime terminal ids', () => { expect(getRemoteRuntimePtyEnvironmentId('remote:terminal-1')).toBeNull() expect(getRemoteRuntimeTerminalHandle('remote:terminal-1')).toBe('terminal-1') }) + + it('treats malformed encoded ids as invalid instead of throwing', () => { + const malformed = 'remote:%E0%A4%A@@terminal-1' + + expect(getRemoteRuntimePtyEnvironmentId(malformed)).toBeNull() + expect(getRemoteRuntimeTerminalHandle(malformed)).toBeNull() + }) }) describe('remote runtime terminal data subscriptions', () => { diff --git a/src/renderer/src/runtime/runtime-terminal-stream.ts b/src/renderer/src/runtime/runtime-terminal-stream.ts index 8beec2d0d..c7046378e 100644 --- a/src/renderer/src/runtime/runtime-terminal-stream.ts +++ b/src/renderer/src/runtime/runtime-terminal-stream.ts @@ -27,9 +27,13 @@ export function parseRemoteRuntimePtyId(ptyId: string): RemoteRuntimePtyIdParts if (separatorIndex === -1) { return { environmentId: null, handle: rest } } - return { - environmentId: decodeURIComponent(rest.slice(0, separatorIndex)), - handle: decodeURIComponent(rest.slice(separatorIndex + REMOTE_PTY_OWNER_SEPARATOR.length)) + try { + return { + environmentId: decodeURIComponent(rest.slice(0, separatorIndex)), + handle: decodeURIComponent(rest.slice(separatorIndex + REMOTE_PTY_OWNER_SEPARATOR.length)) + } + } catch { + return null } }