From 6d482409fe7c8b5c0d462b3edfd80c6f9c13d672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Iv=C3=A1n=20Vieitez=20Parra?= <3857362+corrideat@users.noreply.github.com> Date: Mon, 10 Jun 2024 02:54:20 +0000 Subject: [PATCH] Bugfixes * `crypto` didn't work in Firefox due to it being a getter * Fix forwarding to work with message ports --- package-lock.json | 4 +-- package.json | 2 +- .../impl/worker/workerSandboxManager.ts | 33 ++++--------------- src/untrusted/lib/createContext.ts | 8 ++++- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index a898b6a..5a41497 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@exact-realty/lot", - "version": "0.0.23", + "version": "0.0.24", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@exact-realty/lot", - "version": "0.0.23", + "version": "0.0.24", "license": "ISC", "devDependencies": { "@exact-realty/esbuild-plugin-closure-compiler": "^1.0.4", diff --git a/package.json b/package.json index 6a2bd52..79c0026 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@exact-realty/lot", - "version": "0.0.23", + "version": "0.0.24", "description": "Sandbox for isolating ECMAScript code", "main": "./dist/index.cjs", "types": "./dist/index.d.cts", diff --git a/src/untrusted/impl/worker/workerSandboxManager.ts b/src/untrusted/impl/worker/workerSandboxManager.ts index 6483380..b782807 100644 --- a/src/untrusted/impl/worker/workerSandboxManager.ts +++ b/src/untrusted/impl/worker/workerSandboxManager.ts @@ -158,35 +158,14 @@ const workerSandboxManager = async ( const revokeWorkerMessageEventListener = createMessageEventListener( worker, (data: unknown[]) => { - if ( - ![ - EMessageTypes.REQUEST, - EMessageTypes.RESULT, - EMessageTypes.ERROR, - ].includes(data[0] as EMessageTypes) - ) - return; + if (EMessageTypes.REQUEST !== data[0]) return; - if (data[0] === EMessageTypes.REQUEST) { - Logger.debug( - 'Forwarding REQUEST from worker to parent for executing task [' + - data[1] + - '] ' + - data[2], - ); - } else { - Logger.debug( - 'Forwarding ' + - (data[0] === EMessageTypes.RESULT - ? 'RESULT' - : 'ERROR') + - ' from worker to parent from executing task [' + - data[1] + - ']', - ); - } + Logger.debug( + 'Forwarding REQUEST from worker to parent for executing task' + + data[2], + ); - postMessageOutgoing(data); + postMessageOutgoing(data, [data[1] as unknown as MessagePort]); }, ); diff --git a/src/untrusted/lib/createContext.ts b/src/untrusted/lib/createContext.ts index 6806139..f5dee9c 100644 --- a/src/untrusted/lib/createContext.ts +++ b/src/untrusted/lib/createContext.ts @@ -22,6 +22,7 @@ import { aMap, aPush, fnApply, + fnCall, oCreate, oDefineProperties, oDefineProperty, @@ -166,7 +167,7 @@ const descriptorToFunctionProxy = (ctx: object, a?: PropertyDescriptor) => { if (typeof a['value'] === 'function') { a['value'] = createGlobalFunctionProxy(ctx, a['value']); } else if (typeof a['get'] === 'function') { - const v = a['get'].call($global); + const v = fnCall(a['get'], $global); if (typeof v === 'function') { const nameDescriptor = oGetOwnPropertyDescriptor(a['get'], 'name'); const newGetter = (() => createGlobalFunctionProxy(ctx, v)).bind( @@ -176,6 +177,11 @@ const descriptorToFunctionProxy = (ctx: object, a?: PropertyDescriptor) => { oDefineProperty(newGetter, 'name', nameDescriptor); } a['get'] = newGetter; + } else { + a['get'] = (() => v).bind(null); + } + if (typeof a['set'] === 'function') { + a['set'] = (() => {}).bind(null); } } return a;