fix(runtime): reject non-object E2EE handshake JSON (#35583)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-29 00:18:00 -07:00
committed by GitHub
co-authored by OrcaWin
parent c5f362831e
commit 78876c01ba
2 changed files with 8 additions and 3 deletions
+2 -2
View File
@@ -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')
})
+6 -1
View File
@@ -188,7 +188,12 @@ export class E2EEChannel {
private handleHello(raw: string): void {
let hello: Record<string, unknown>
try {
hello = parseRemoteRuntimeJsonText(raw) as Record<string, unknown>
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