Skip to content

Commit c0d1ae2

Browse files
committed
fixup! unhardenable proxies refuse suppressTrapping
1 parent 5bc9589 commit c0d1ae2

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

packages/captp/src/trap.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export const nearTrapImpl = harden({
1919
},
2020
});
2121

22-
/** @type {ProxyHandler<any>} */
22+
/**
23+
* While the resulting proxy can be frozen, it refuses to be made non-trapping
24+
* and so cannot be hardened.
25+
*
26+
* @type {ProxyHandler<any>}
27+
*/
2328
const baseFreezableProxyHandler = {
2429
set(_target, _prop, _value) {
2530
return false;
@@ -33,6 +38,10 @@ const baseFreezableProxyHandler = {
3338
deleteProperty(_target, _prop) {
3439
return false;
3540
},
41+
// @ts-expect-error suppressTrapping is not yet in the TS ProxyHandler
42+
suppressTrapping(_target) {
43+
return false;
44+
},
3645
};
3746

3847
/**

packages/eventual-send/src/E.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const { assign, create, freeze } = Object;
1010

1111
const onSend = makeMessageBreakpointTester('ENDO_SEND_BREAKPOINTS');
1212

13-
/** @type {ProxyHandler<any>} */
13+
/**
14+
* While the resulting proxy can be frozen, it refuses to be made non-trapping
15+
* and so cannot be hardened.
16+
*
17+
* @type {ProxyHandler<any>}
18+
*/
1419
const baseFreezableProxyHandler = {
1520
set(_target, _prop, _value) {
1621
return false;
@@ -24,6 +29,10 @@ const baseFreezableProxyHandler = {
2429
deleteProperty(_target, _prop) {
2530
return false;
2631
},
32+
// @ts-expect-error suppressTrapping is not yet in the TS ProxyHandler
33+
suppressTrapping(_target) {
34+
return false;
35+
},
2736
};
2837

2938
// E Proxy handlers pretend that any property exists on the target and returns

packages/eventual-send/src/handled-promise.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,32 @@ export const makeHandledPromise = () => {
307307
const { proxy: proxyOpts } = options;
308308
let presence;
309309
if (proxyOpts) {
310-
// TODO for these cases, it will be unreasonably hard for all uses
311-
// to avoid hardening the returned proxy.
312310
const {
313311
handler: proxyHandler,
314312
target: proxyTarget,
315313
revokerCallback,
316314
} = proxyOpts;
315+
316+
// While the resulting proxy can be frozen, by default,
317+
// it refuses to be made non-trapping and so cannot be hardened.
318+
// However, we allow proxyOpts.proxyHandler to explicitly override
319+
// this default `suppressTrapping`.
320+
const fullProxyHandler = {
321+
suppressTrapping(_target) {
322+
return false;
323+
},
324+
...proxyHandler,
325+
}
317326
if (revokerCallback) {
318327
// Create a proxy and its revoke function.
319328
const { proxy, revoke } = Proxy.revocable(
320329
proxyTarget,
321-
proxyHandler,
330+
fullProxyHandler,
322331
);
323332
presence = proxy;
324333
revokerCallback(revoke);
325334
} else {
326-
presence = new Proxy(proxyTarget, proxyHandler);
335+
presence = new Proxy(proxyTarget, fullProxyHandler);
327336
}
328337
} else {
329338
// Default presence.

packages/marshal/src/marshal-stringify.js

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const doNotConvertValToSlot = val =>
1515
const doNotConvertSlotToVal = (slot, _iface) =>
1616
Fail`Marshal's parse must not encode any slots ${slot}`;
1717

18+
/**
19+
* While the resulting proxy can be frozen, it refuses to be made non-trapping
20+
* and so cannot be hardened.
21+
*
22+
* @type {ProxyHandler<any>}
23+
*/
1824
const badArrayHandler = harden({
1925
get: (_target, name, _receiver) => {
2026
if (name === 'length') {
@@ -23,6 +29,9 @@ const badArrayHandler = harden({
2329
// `throw` is noop since `Fail` throws. But linter confused
2430
throw Fail`Marshal's parse must not encode any slot positions ${name}`;
2531
},
32+
suppressTrapping(_target) {
33+
return false;
34+
},
2635
});
2736

2837
// Note the use of `freeze` rather than `harden` below. This is because

packages/ses/src/strict-scope-terminator.js

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export const alwaysThrowHandler = new Proxy(
3535
* scopeTerminatorHandler manages a strictScopeTerminator Proxy which serves as
3636
* the final scope boundary that will always return "undefined" in order
3737
* to prevent access to "start compartment globals".
38+
*
39+
* While the resulting proxy can be frozen, it refuses to be made non-trapping
40+
* and so cannot be hardened.
41+
*
42+
* @type {ProxyHandler<any>}
3843
*/
3944
const scopeProxyHandlerProperties = {
4045
get(_shadow, _prop) {
@@ -76,6 +81,10 @@ const scopeProxyHandlerProperties = {
7681
ownKeys(_shadow) {
7782
return [];
7883
},
84+
85+
suppressTrapping(_target) {
86+
return false;
87+
},
7988
};
8089

8190
// The scope handler's prototype is a proxy that throws if any trap other

0 commit comments

Comments
 (0)