Skip to content

Commit 13db455

Browse files
committed
Bugfixes
* Fix #41 (using an aborted sandbox in the browser doesn't result in an error) * Fix an issue with `file://` ancestors preventing sandbox init * Fix an issue with only the first argument of external methods working * Update dependencies
1 parent 6d48240 commit 13db455

File tree

7 files changed

+197
-192
lines changed

7 files changed

+197
-192
lines changed

package-lock.json

Lines changed: 168 additions & 168 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@exact-realty/lot",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"description": "Sandbox for isolating ECMAScript code",
55
"main": "./dist/index.cjs",
66
"types": "./dist/index.d.cts",
@@ -136,15 +136,15 @@
136136
"@exact-realty/esbuild-plugin-closure-compiler": "^1.0.4",
137137
"@exact-realty/esbuild-plugin-inline-js": "^1.1.7",
138138
"@types/selenium-webdriver": "^4.1.23",
139-
"@typescript-eslint/eslint-plugin": "^7.12.0",
140-
"@typescript-eslint/parser": "^7.12.0",
141-
"esbuild": "^0.21.4",
139+
"@typescript-eslint/eslint-plugin": "^7.13.0",
140+
"@typescript-eslint/parser": "^7.13.0",
141+
"esbuild": "^0.21.5",
142142
"eslint": "^8.56.0",
143143
"eslint-config-prettier": "^9.1.0",
144144
"eslint-plugin-prettier": "^5.1.3",
145145
"glob": "^10.4.1",
146146
"google-closure-compiler": "^20240317.0.0",
147-
"prettier": "^3.3.1",
147+
"prettier": "^3.3.2",
148148
"selenium-webdriver": "^4.21.0",
149149
"ts-node": "^10.9.2",
150150
"ts-patch": "^3.2.0",

src/trusted/lib/setupSandboxListeners.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ const setupSandboxListeners = <T>(
8282
return;
8383
}
8484

85-
requestHandler(externalMethods, data[1], data[2], data[3]);
85+
requestHandler(
86+
externalMethods,
87+
data[1],
88+
data[2],
89+
...data.slice(3),
90+
);
8691

8792
return;
8893
}

src/untrusted/impl/browser/iframeSandboxInit.inline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ const parentOrigin =
7575
'ancestorOrigins' in location &&
7676
location['ancestorOrigins'] &&
7777
location['ancestorOrigins'][0] &&
78-
location['ancestorOrigins'][0] !== 'null'
78+
location['ancestorOrigins'][0] !== 'null' &&
79+
// `file://` URLs seem to be problematic as window.origin can be `null`
80+
/^https?:/i.test(location['ancestorOrigins'][0])
7981
? location['ancestorOrigins'][0]
8082
: '*';
8183

src/untrusted/lib/performTaskFactory.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,18 @@ const performTaskFactory = <T>(
106106
return taskPromise;
107107
};
108108

109-
const performTaskProxy = proxyMaybeRevocable(
109+
const [performTaskProxy, revoke] = proxyMaybeRevocable(
110110
revocable || null,
111111
performTask,
112112
{},
113113
);
114114

115115
return [
116-
performTaskProxy['proxy'],
116+
performTaskProxy,
117117
() => {
118-
performTaskProxy.revoke();
118+
if (revoke) {
119+
revoke();
120+
}
119121
const e = new E('Task aborted');
120122
// Abort all pending tasks
121123
unresolved.splice(0).forEach((x) => {

src/untrusted/lib/proxyMaybeRevocable.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ describe('proxyMaybeRevocable', () => {
2424
get: (obj, prop) => (prop in obj ? obj[prop] : 42),
2525
};
2626

27-
const { proxy, revoke } = proxyMaybeRevocable(true, target, handler);
27+
const [proxy, revoke] = proxyMaybeRevocable(true, target, handler);
2828

2929
assert.equal(proxy.someNonExistentProp, 42);
30+
assert.ok(typeof revoke === 'function');
3031

3132
revoke();
3233

@@ -41,10 +42,9 @@ describe('proxyMaybeRevocable', () => {
4142
get: (obj, prop) => (prop in obj ? obj[prop] : 42),
4243
};
4344

44-
const { proxy, revoke } = proxyMaybeRevocable(false, target, handler);
45+
const [proxy, revoke] = proxyMaybeRevocable(false, target, handler);
4546
assert.equal(proxy.someNonExistentProp, 42);
46-
47-
revoke();
47+
assert.ok(!revoke);
4848

4949
assert.equal(proxy.someNonExistentProp, 42);
5050
});
@@ -53,6 +53,6 @@ describe('proxyMaybeRevocable', () => {
5353
const someObject = {};
5454
const result = proxyMaybeRevocable(null, someObject, someObject);
5555

56-
assert.strictEqual(result.proxy, someObject);
56+
assert.strictEqual(result[0], someObject);
5757
});
5858
});

src/untrusted/lib/proxyMaybeRevocable.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ type TProxyMaybeRevocable = {
2020
revocable: boolean | null,
2121
target: T,
2222
handler: ProxyHandler<T>,
23-
): {
24-
proxy: T;
25-
revoke: () => void;
26-
};
23+
): [T] | [T, () => void];
2724
};
2825

2926
/**
@@ -43,12 +40,11 @@ type TProxyMaybeRevocable = {
4340
*/
4441
const proxyMaybeRevocable: TProxyMaybeRevocable = (revocable, ...args) => {
4542
if (revocable) {
46-
return Proxy.revocable(...args);
43+
const r = Proxy.revocable(...args);
44+
return [r['proxy'], r['revoke'].bind(r)];
4745
}
48-
return {
49-
['proxy']: revocable === null ? args[0] : new PX(...args),
50-
['revoke']: Boolean,
51-
};
46+
47+
return [revocable === null ? args[0] : new PX(...args)];
5248
};
5349

5450
export default proxyMaybeRevocable;

0 commit comments

Comments
 (0)