From 7882e47c85f05b5bc9a6c3b99237a212c31281cf Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 26 Jun 2026 14:50:13 -0700 Subject: [PATCH] Move async message data checks prior to execution. --- src/lib/nano25519.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/lib/nano25519.ts b/src/lib/nano25519.ts index b9c9790..286821b 100644 --- a/src/lib/nano25519.ts +++ b/src/lib/nano25519.ts @@ -198,27 +198,24 @@ const nano25519_worker_init = ({ derive, sign, verify }: typeof nano25519) => { */ function handleMessage (message: unknown): void { NODE: if (host == null) return queueMicrotask(() => handleMessage(message)) + if (message == null + || typeof message !== 'object' + || !('data' in message) + || message.data == null + || typeof message.data !== 'object' + || !('url' in message.data) + || typeof message.data.url !== 'string' + || !('id' in message.data) + || typeof message.data.id !== 'string' + || !('action' in message.data) + || typeof message.data.action !== 'string' + ) return let result: undefined | boolean | string | Uint8Array let url: undefined | string let id: undefined | string try { - if (message == null - || typeof message !== 'object' - || !('data' in message) - || message.data == null - || typeof message.data !== 'object' - || !('url' in message.data) - || typeof message.data.url !== 'string' - || !('id' in message.data) - || typeof message.data.id !== 'string' - || !('action' in message.data) - || typeof message.data.action !== 'string' - ) { - throw new TypeError('Invalid nano25519Worker request') - } const data: Data = message.data as object & { url: string, id: string, action: string } { ({ url, id } = data) } - if (typeof url !== 'string' || typeof id !== 'string') return if (url !== client) return if (data.action === 'start') { -- 2.52.0