From 78876c01ba4ef53e0cbc6c77cd31dc87fc4ccc0f Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Thu, 29 Oct 2026 00:18:00 -0700 Subject: [PATCH] fix(runtime): reject non-object E2EE handshake JSON (#35583) Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- src/main/runtime/rpc/e2ee-channel.test.ts | 4 ++-- src/main/runtime/rpc/e2ee-channel.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/runtime/rpc/e2ee-channel.test.ts b/src/main/runtime/rpc/e2ee-channel.test.ts index dfac64f5189..383af48069b 100644 --- a/src/main/runtime/rpc/e2ee-channel.test.ts +++ b/src/main/runtime/rpc/e2ee-channel.test.ts @@ -192,9 +192,9 @@ describe('E2EEChannel', () => { expect(ctx.onReady).not.toHaveBeenCalled() }) - it('rejects malformed JSON', () => { + it.each(['not json', 'null'])('rejects invalid handshake JSON: %s', (raw) => { const ctx = setup() - ctx.channel.handleRawMessage('not json') + ctx.channel.handleRawMessage(raw) expect(ctx.onError).toHaveBeenCalledWith(4001, 'Invalid handshake message') }) diff --git a/src/main/runtime/rpc/e2ee-channel.ts b/src/main/runtime/rpc/e2ee-channel.ts index 34b9aa777a8..cdba6b9d02f 100644 --- a/src/main/runtime/rpc/e2ee-channel.ts +++ b/src/main/runtime/rpc/e2ee-channel.ts @@ -188,7 +188,12 @@ export class E2EEChannel { private handleHello(raw: string): void { let hello: Record try { - hello = parseRemoteRuntimeJsonText(raw) as Record + const parsed = parseRemoteRuntimeJsonText(raw) + if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) { + this.onError(4001, 'Invalid handshake message') + return + } + hello = { ...parsed } } catch { this.onError(4001, 'Invalid handshake message') return