Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
* `crypto` didn't work in Firefox due to it being a getter
* Fix forwarding to work with message ports
  • Loading branch information
corrideat committed Jun 10, 2024
1 parent d216392 commit 6d48240
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 6 additions & 27 deletions src/untrusted/impl/worker/workerSandboxManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
},
);

Expand Down
8 changes: 7 additions & 1 deletion src/untrusted/lib/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
aMap,
aPush,
fnApply,
fnCall,
oCreate,
oDefineProperties,
oDefineProperty,
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit 6d48240

Please sign in to comment.