Skip to content

Commit 7f44397

Browse files
committed
feat(ses,pass-style): use no-trapping integrity level for safety
1 parent f7d527c commit 7f44397

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

packages/ses/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
8686
},
8787
"dependencies": {
88-
"@endo/env-options": "workspace:^"
88+
"@endo/env-options": "workspace:^",
89+
"@endo/no-trapping-shim": "^0.1.0"
8990
},
9091
"devDependencies": {
9192
"@endo/compartment-mapper": "workspace:^",

packages/ses/src/commons.js

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/* global globalThis */
1515
/* eslint-disable no-restricted-globals */
1616

17+
import '@endo/no-trapping-shim/shim.js';
18+
1719
// We cannot use globalThis as the local name since it would capture the
1820
// lexical name.
1921
const universalThis = globalThis;
@@ -75,6 +77,11 @@ export const {
7577
setPrototypeOf,
7678
values,
7779
fromEntries,
80+
// https://github.com/endojs/endo/pull/2673
81+
// @ts-expect-error TS does not yet have this on ObjectConstructor.
82+
isNoTrapping,
83+
// @ts-expect-error TS does not yet have this on ObjectConstructor.
84+
suppressTrapping,
7885
} = Object;
7986

8087
export const {
@@ -125,6 +132,11 @@ export const {
125132
ownKeys,
126133
preventExtensions: reflectPreventExtensions,
127134
set: reflectSet,
135+
// https://github.com/endojs/endo/pull/2673
136+
// @ts-expect-error TS does not yet have this on typeof Reflect.
137+
isNoTrapping: reflectIsNoTrapping,
138+
// @ts-expect-error TS does not yet have this on typeof Reflect.
139+
suppressTrapping: reflectSuppressTrapping,
128140
} = Reflect;
129141

130142
export const { isArray, prototype: arrayPrototype } = Array;

packages/ses/src/make-hardener.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
apply,
3131
arrayForEach,
3232
defineProperty,
33-
freeze,
3433
getOwnPropertyDescriptor,
3534
getOwnPropertyDescriptors,
3635
getPrototypeOf,
@@ -49,6 +48,8 @@ import {
4948
FERAL_STACK_GETTER,
5049
FERAL_STACK_SETTER,
5150
isError,
51+
isFrozen,
52+
suppressTrapping,
5253
} from './commons.js';
5354
import { assert } from './error/assert.js';
5455

@@ -182,8 +183,17 @@ export const makeHardener = () => {
182183
// Also throws if the object is an ArrayBuffer or any TypedArray.
183184
if (isTypedArray(obj)) {
184185
freezeTypedArray(obj);
186+
if (isFrozen(obj)) {
187+
// After `freezeTypedArray`, the typed array might actually be
188+
// frozen if
189+
// - it has no indexed properties
190+
// - it is backed by an Immutable ArrayBuffer as proposed.
191+
// In either case, this makes it a candidate to be made
192+
// non-trapping.
193+
suppressTrapping(obj);
194+
}
185195
} else {
186-
freeze(obj);
196+
suppressTrapping(obj);
187197
}
188198

189199
// we rely upon certain commitments of Object.freeze and proxies here

packages/ses/src/permits.js

+8
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ export const permitted = {
488488
groupBy: fn,
489489
// Seen on QuickJS
490490
__getClass: false,
491+
// https://github.com/endojs/endo/pull/2673
492+
isNoTrapping: fn,
493+
suppressTrapping: fn,
491494
},
492495

493496
'%ObjectPrototype%': {
@@ -1624,12 +1627,17 @@ export const permitted = {
16241627
set: fn,
16251628
setPrototypeOf: fn,
16261629
'@@toStringTag': 'string',
1630+
// https://github.com/endojs/endo/pull/2673
1631+
isNoTrapping: fn,
1632+
suppressTrapping: fn,
16271633
},
16281634

16291635
Proxy: {
16301636
// Properties of the Proxy Constructor
16311637
'[[Proto]]': '%FunctionPrototype%',
16321638
revocable: fn,
1639+
// https://github.com/endojs/endo/pull/2673
1640+
prototype: 'undefined',
16331641
},
16341642

16351643
// Appendix B

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ __metadata:
702702
languageName: unknown
703703
linkType: soft
704704

705-
"@endo/no-trapping-shim@workspace:packages/no-trapping-shim":
705+
"@endo/no-trapping-shim@npm:^0.1.0, @endo/no-trapping-shim@workspace:packages/no-trapping-shim":
706706
version: 0.0.0-use.local
707707
resolution: "@endo/no-trapping-shim@workspace:packages/no-trapping-shim"
708708
dependencies:
@@ -8960,6 +8960,7 @@ __metadata:
89608960
"@endo/compartment-mapper": "workspace:^"
89618961
"@endo/env-options": "workspace:^"
89628962
"@endo/module-source": "workspace:^"
8963+
"@endo/no-trapping-shim": "npm:^0.1.0"
89638964
"@endo/test262-runner": "workspace:^"
89648965
ava: "npm:^6.1.3"
89658966
babel-eslint: "npm:^10.1.0"

0 commit comments

Comments
 (0)