ses 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEWS.md +25 -1
- package/README.md +1 -1
- package/dist/lockdown.cjs +962 -453
- package/dist/lockdown.mjs +962 -453
- package/dist/lockdown.umd.js +962 -453
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +962 -453
- package/dist/ses.mjs +962 -453
- package/dist/ses.umd.js +962 -453
- package/dist/ses.umd.min.js +1 -1
- package/package.json +15 -11
- package/src/compartment.js +13 -4
- package/src/enable-property-overrides.js +40 -36
- package/src/enablements.js +15 -0
- package/src/error/README.md +1 -1
- package/src/error/fatal-assert.js +1 -1
- package/src/error/note-log-args.js +1 -205
- package/src/error/tame-console.js +72 -51
- package/src/lockdown.js +43 -12
- package/src/make-lru-cachemap.js +221 -0
- package/src/module-instance.js +10 -10
- package/src/module-proxy.js +42 -14
- package/src/permits-intrinsics.js +29 -15
- package/src/permits.js +67 -2
- package/src/tame-domains.js +4 -6
- package/src/tame-faux-data-properties.js +210 -0
- package/types.d.ts +1 -1
package/src/module-proxy.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
reflectHas,
|
|
26
26
|
reflectIsExtensible,
|
|
27
27
|
reflectPreventExtensions,
|
|
28
|
+
toStringTagSymbol,
|
|
28
29
|
weakmapSet,
|
|
29
30
|
} from './commons.js';
|
|
30
31
|
import { assert } from './error/assert.js';
|
|
@@ -51,13 +52,21 @@ const { quote: q } = assert;
|
|
|
51
52
|
//
|
|
52
53
|
export const deferExports = () => {
|
|
53
54
|
let active = false;
|
|
54
|
-
const
|
|
55
|
+
const exportsTarget = create(null, {
|
|
56
|
+
// Make this appear like an ESM module namespace object.
|
|
57
|
+
[toStringTagSymbol]: {
|
|
58
|
+
value: 'Module',
|
|
59
|
+
writable: false,
|
|
60
|
+
enumerable: false,
|
|
61
|
+
configurable: false,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
55
64
|
return freeze({
|
|
56
65
|
activate() {
|
|
57
66
|
active = true;
|
|
58
67
|
},
|
|
59
|
-
|
|
60
|
-
exportsProxy: new Proxy(
|
|
68
|
+
exportsTarget,
|
|
69
|
+
exportsProxy: new Proxy(exportsTarget, {
|
|
61
70
|
get(_target, name, receiver) {
|
|
62
71
|
if (!active) {
|
|
63
72
|
throw TypeError(
|
|
@@ -66,7 +75,7 @@ export const deferExports = () => {
|
|
|
66
75
|
)} of module exports namespace, the module has not yet begun to execute`,
|
|
67
76
|
);
|
|
68
77
|
}
|
|
69
|
-
return reflectGet(
|
|
78
|
+
return reflectGet(exportsTarget, name, receiver);
|
|
70
79
|
},
|
|
71
80
|
set(_target, name, _value) {
|
|
72
81
|
throw TypeError(
|
|
@@ -81,7 +90,7 @@ export const deferExports = () => {
|
|
|
81
90
|
)}, the module has not yet begun to execute`,
|
|
82
91
|
);
|
|
83
92
|
}
|
|
84
|
-
return reflectHas(
|
|
93
|
+
return reflectHas(exportsTarget, name);
|
|
85
94
|
},
|
|
86
95
|
deleteProperty(_target, name) {
|
|
87
96
|
throw TypeError(
|
|
@@ -94,7 +103,7 @@ export const deferExports = () => {
|
|
|
94
103
|
'Cannot enumerate keys, the module has not yet begun to execute',
|
|
95
104
|
);
|
|
96
105
|
}
|
|
97
|
-
return ownKeys(
|
|
106
|
+
return ownKeys(exportsTarget);
|
|
98
107
|
},
|
|
99
108
|
getOwnPropertyDescriptor(_target, name) {
|
|
100
109
|
if (!active) {
|
|
@@ -104,7 +113,7 @@ export const deferExports = () => {
|
|
|
104
113
|
)}, the module has not yet begun to execute`,
|
|
105
114
|
);
|
|
106
115
|
}
|
|
107
|
-
return reflectGetOwnPropertyDescriptor(
|
|
116
|
+
return reflectGetOwnPropertyDescriptor(exportsTarget, name);
|
|
108
117
|
},
|
|
109
118
|
preventExtensions(_target) {
|
|
110
119
|
if (!active) {
|
|
@@ -112,7 +121,7 @@ export const deferExports = () => {
|
|
|
112
121
|
'Cannot prevent extensions of module exports namespace, the module has not yet begun to execute',
|
|
113
122
|
);
|
|
114
123
|
}
|
|
115
|
-
return reflectPreventExtensions(
|
|
124
|
+
return reflectPreventExtensions(exportsTarget);
|
|
116
125
|
},
|
|
117
126
|
isExtensible() {
|
|
118
127
|
if (!active) {
|
|
@@ -120,7 +129,7 @@ export const deferExports = () => {
|
|
|
120
129
|
'Cannot check extensibility of module exports namespace, the module has not yet begun to execute',
|
|
121
130
|
);
|
|
122
131
|
}
|
|
123
|
-
return reflectIsExtensible(
|
|
132
|
+
return reflectIsExtensible(exportsTarget);
|
|
124
133
|
},
|
|
125
134
|
getPrototypeOf(_target) {
|
|
126
135
|
return null;
|
|
@@ -147,11 +156,30 @@ export const deferExports = () => {
|
|
|
147
156
|
});
|
|
148
157
|
};
|
|
149
158
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
/**
|
|
160
|
+
* @typedef {object} DeferredExports
|
|
161
|
+
* @property {Record<string, any>} exportsTarget - The object to which a
|
|
162
|
+
* module's exports will be added.
|
|
163
|
+
* @property {Record<string, any>} exportsProxy - A proxy over the `exportsTarget`,
|
|
164
|
+
* used to expose its "exports" to other compartments.
|
|
165
|
+
* @property {() => void} activate - Activate the `exportsProxy` such that it can
|
|
166
|
+
* be used as a module namespace object.
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Memoizes the creation of a deferred module exports namespace proxy for any
|
|
171
|
+
* arbitrary full specifier in a compartment. It also records the compartment
|
|
172
|
+
* and specifier affiliated with that module exports namespace proxy so it
|
|
173
|
+
* can be used as an alias into another compartment when threaded through
|
|
174
|
+
* a compartment's `moduleMap` argument.
|
|
175
|
+
*
|
|
176
|
+
* @param {*} compartment - The compartment to retrieve deferred exports from.
|
|
177
|
+
* @param {*} compartmentPrivateFields - The private fields of the compartment.
|
|
178
|
+
* @param {*} moduleAliases - The module aliases of the compartment.
|
|
179
|
+
* @param {string} specifier - The module specifier to retrieve deferred exports for.
|
|
180
|
+
* @returns {DeferredExports} - The deferred exports for the module specifier of
|
|
181
|
+
* the compartment.
|
|
182
|
+
*/
|
|
155
183
|
export const getDeferredExports = (
|
|
156
184
|
compartment,
|
|
157
185
|
compartmentPrivateFields,
|
|
@@ -74,7 +74,18 @@ export default function whitelistIntrinsics(
|
|
|
74
74
|
intrinsics,
|
|
75
75
|
markVirtualizedNativeFunction,
|
|
76
76
|
) {
|
|
77
|
-
|
|
77
|
+
let groupStarted = false;
|
|
78
|
+
const inConsoleGroup = (level, ...args) => {
|
|
79
|
+
if (!groupStarted) {
|
|
80
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
81
|
+
console.groupCollapsed('Removing unpermitted intrinsics');
|
|
82
|
+
groupStarted = true;
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
85
|
+
return console[level](...args);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// These primitives are allowed for permits.
|
|
78
89
|
const primitives = ['undefined', 'boolean', 'number', 'string', 'symbol'];
|
|
79
90
|
|
|
80
91
|
// These symbols are allowed as well-known symbols
|
|
@@ -279,11 +290,7 @@ export default function whitelistIntrinsics(
|
|
|
279
290
|
// that we are removing it so we know to look into it, as happens when
|
|
280
291
|
// the language evolves new features to existing intrinsics.
|
|
281
292
|
if (subPermit !== false) {
|
|
282
|
-
|
|
283
|
-
// a debugging attempt. See the comment at top of file for an
|
|
284
|
-
// explanation.
|
|
285
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
286
|
-
console.warn(`Removing ${subPath}`);
|
|
293
|
+
inConsoleGroup('warn', `Removing ${subPath}`);
|
|
287
294
|
}
|
|
288
295
|
try {
|
|
289
296
|
delete obj[prop];
|
|
@@ -292,17 +299,17 @@ export default function whitelistIntrinsics(
|
|
|
292
299
|
if (typeof obj === 'function' && prop === 'prototype') {
|
|
293
300
|
obj.prototype = undefined;
|
|
294
301
|
if (obj.prototype === undefined) {
|
|
295
|
-
|
|
296
|
-
|
|
302
|
+
inConsoleGroup(
|
|
303
|
+
'warn',
|
|
304
|
+
`Tolerating undeletable ${subPath} === undefined`,
|
|
305
|
+
);
|
|
297
306
|
// eslint-disable-next-line no-continue
|
|
298
307
|
continue;
|
|
299
308
|
}
|
|
300
309
|
}
|
|
301
|
-
|
|
302
|
-
console.error(`failed to delete ${subPath}`, err);
|
|
310
|
+
inConsoleGroup('error', `failed to delete ${subPath}`, err);
|
|
303
311
|
} else {
|
|
304
|
-
|
|
305
|
-
console.error(`deleting ${subPath} threw`, err);
|
|
312
|
+
inConsoleGroup('error', `deleting ${subPath} threw`, err);
|
|
306
313
|
}
|
|
307
314
|
throw err;
|
|
308
315
|
}
|
|
@@ -310,7 +317,14 @@ export default function whitelistIntrinsics(
|
|
|
310
317
|
}
|
|
311
318
|
}
|
|
312
319
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
320
|
+
try {
|
|
321
|
+
// Start path with 'intrinsics' to clarify that properties are not
|
|
322
|
+
// removed from the global object by the whitelisting operation.
|
|
323
|
+
visitProperties('intrinsics', intrinsics, permitted);
|
|
324
|
+
} finally {
|
|
325
|
+
if (groupStarted) {
|
|
326
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
327
|
+
console.groupEnd();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
316
330
|
}
|
package/src/permits.js
CHANGED
|
@@ -53,6 +53,8 @@ export const universalPropertyNames = {
|
|
|
53
53
|
Boolean: 'Boolean',
|
|
54
54
|
DataView: 'DataView',
|
|
55
55
|
EvalError: 'EvalError',
|
|
56
|
+
// https://github.com/tc39/proposal-float16array
|
|
57
|
+
Float16Array: 'Float16Array',
|
|
56
58
|
Float32Array: 'Float32Array',
|
|
57
59
|
Float64Array: 'Float64Array',
|
|
58
60
|
Int8Array: 'Int8Array',
|
|
@@ -382,6 +384,8 @@ const CommonMath = {
|
|
|
382
384
|
irem: false,
|
|
383
385
|
// See https://github.com/Moddable-OpenSource/moddable/issues/523
|
|
384
386
|
mod: false,
|
|
387
|
+
// See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
|
|
388
|
+
irandom: false,
|
|
385
389
|
};
|
|
386
390
|
|
|
387
391
|
export const permitted = {
|
|
@@ -443,6 +447,8 @@ export const permitted = {
|
|
|
443
447
|
values: fn,
|
|
444
448
|
// https://github.com/tc39/proposal-array-grouping
|
|
445
449
|
groupBy: fn,
|
|
450
|
+
// Seen on QuickJS
|
|
451
|
+
__getClass: false,
|
|
446
452
|
},
|
|
447
453
|
|
|
448
454
|
'%ObjectPrototype%': {
|
|
@@ -489,6 +495,10 @@ export const permitted = {
|
|
|
489
495
|
caller: false,
|
|
490
496
|
// proposed but not yet std. To be removed if there
|
|
491
497
|
arguments: false,
|
|
498
|
+
// Seen on QuickJS. TODO grab getter for use by console
|
|
499
|
+
fileName: false,
|
|
500
|
+
// Seen on QuickJS. TODO grab getter for use by console
|
|
501
|
+
lineNumber: false,
|
|
492
502
|
},
|
|
493
503
|
|
|
494
504
|
Boolean: {
|
|
@@ -528,6 +538,8 @@ export const permitted = {
|
|
|
528
538
|
useSimple: false,
|
|
529
539
|
// Seen at core-js https://github.com/zloirock/core-js#ecmascript-symbol
|
|
530
540
|
useSetter: false,
|
|
541
|
+
// Seen on QuickJS
|
|
542
|
+
operatorSet: false,
|
|
531
543
|
},
|
|
532
544
|
|
|
533
545
|
'%SymbolPrototype%': {
|
|
@@ -638,6 +650,30 @@ export const permitted = {
|
|
|
638
650
|
bitLength: false,
|
|
639
651
|
// See https://github.com/Moddable-OpenSource/moddable/issues/523
|
|
640
652
|
fromArrayBuffer: false,
|
|
653
|
+
// Seen on QuickJS
|
|
654
|
+
tdiv: false,
|
|
655
|
+
// Seen on QuickJS
|
|
656
|
+
fdiv: false,
|
|
657
|
+
// Seen on QuickJS
|
|
658
|
+
cdiv: false,
|
|
659
|
+
// Seen on QuickJS
|
|
660
|
+
ediv: false,
|
|
661
|
+
// Seen on QuickJS
|
|
662
|
+
tdivrem: false,
|
|
663
|
+
// Seen on QuickJS
|
|
664
|
+
fdivrem: false,
|
|
665
|
+
// Seen on QuickJS
|
|
666
|
+
cdivrem: false,
|
|
667
|
+
// Seen on QuickJS
|
|
668
|
+
edivrem: false,
|
|
669
|
+
// Seen on QuickJS
|
|
670
|
+
sqrt: false,
|
|
671
|
+
// Seen on QuickJS
|
|
672
|
+
sqrtrem: false,
|
|
673
|
+
// Seen on QuickJS
|
|
674
|
+
floorLog2: false,
|
|
675
|
+
// Seen on QuickJS
|
|
676
|
+
ctz: false,
|
|
641
677
|
},
|
|
642
678
|
|
|
643
679
|
'%BigIntPrototype%': {
|
|
@@ -806,6 +842,8 @@ export const permitted = {
|
|
|
806
842
|
isWellFormed: fn,
|
|
807
843
|
toWellFormed: fn,
|
|
808
844
|
unicodeSets: fn,
|
|
845
|
+
// Seen on QuickJS
|
|
846
|
+
__quote: false,
|
|
809
847
|
},
|
|
810
848
|
|
|
811
849
|
'%StringIteratorPrototype%': {
|
|
@@ -1045,6 +1083,8 @@ export const permitted = {
|
|
|
1045
1083
|
|
|
1046
1084
|
BigInt64Array: TypedArray('%BigInt64ArrayPrototype%'),
|
|
1047
1085
|
BigUint64Array: TypedArray('%BigUint64ArrayPrototype%'),
|
|
1086
|
+
// https://github.com/tc39/proposal-float16array
|
|
1087
|
+
Float16Array: TypedArray('%Float16ArrayPrototype%'),
|
|
1048
1088
|
Float32Array: TypedArray('%Float32ArrayPrototype%'),
|
|
1049
1089
|
Float64Array: TypedArray('%Float64ArrayPrototype%'),
|
|
1050
1090
|
Int16Array: TypedArray('%Int16ArrayPrototype%'),
|
|
@@ -1057,6 +1097,8 @@ export const permitted = {
|
|
|
1057
1097
|
|
|
1058
1098
|
'%BigInt64ArrayPrototype%': TypedArrayPrototype('BigInt64Array'),
|
|
1059
1099
|
'%BigUint64ArrayPrototype%': TypedArrayPrototype('BigUint64Array'),
|
|
1100
|
+
// https://github.com/tc39/proposal-float16array
|
|
1101
|
+
'%Float16ArrayPrototype%': TypedArrayPrototype('Float16Array'),
|
|
1060
1102
|
'%Float32ArrayPrototype%': TypedArrayPrototype('Float32Array'),
|
|
1061
1103
|
'%Float64ArrayPrototype%': TypedArrayPrototype('Float64Array'),
|
|
1062
1104
|
'%Int16ArrayPrototype%': TypedArrayPrototype('Int16Array'),
|
|
@@ -1106,6 +1148,8 @@ export const permitted = {
|
|
|
1106
1148
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1107
1149
|
prototype: '%SetPrototype%',
|
|
1108
1150
|
'@@species': getter,
|
|
1151
|
+
// Seen on QuickJS
|
|
1152
|
+
groupBy: false,
|
|
1109
1153
|
},
|
|
1110
1154
|
|
|
1111
1155
|
'%SetPrototype%': {
|
|
@@ -1121,6 +1165,20 @@ export const permitted = {
|
|
|
1121
1165
|
values: fn,
|
|
1122
1166
|
'@@iterator': fn,
|
|
1123
1167
|
'@@toStringTag': 'string',
|
|
1168
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1169
|
+
intersection: fn,
|
|
1170
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1171
|
+
union: fn,
|
|
1172
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1173
|
+
difference: fn,
|
|
1174
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1175
|
+
symmetricDifference: fn,
|
|
1176
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1177
|
+
isSubsetOf: fn,
|
|
1178
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1179
|
+
isSupersetOf: fn,
|
|
1180
|
+
// See https://github.com/tc39/proposal-set-methods
|
|
1181
|
+
isDisjointFrom: fn,
|
|
1124
1182
|
},
|
|
1125
1183
|
|
|
1126
1184
|
'%SetIteratorPrototype%': {
|
|
@@ -1208,6 +1266,8 @@ export const permitted = {
|
|
|
1208
1266
|
constructor: 'DataView',
|
|
1209
1267
|
getBigInt64: fn,
|
|
1210
1268
|
getBigUint64: fn,
|
|
1269
|
+
// https://github.com/tc39/proposal-float16array
|
|
1270
|
+
getFloat16: fn,
|
|
1211
1271
|
getFloat32: fn,
|
|
1212
1272
|
getFloat64: fn,
|
|
1213
1273
|
getInt8: fn,
|
|
@@ -1218,6 +1278,8 @@ export const permitted = {
|
|
|
1218
1278
|
getUint32: fn,
|
|
1219
1279
|
setBigInt64: fn,
|
|
1220
1280
|
setBigUint64: fn,
|
|
1281
|
+
// https://github.com/tc39/proposal-float16array
|
|
1282
|
+
setFloat16: fn,
|
|
1221
1283
|
setFloat32: fn,
|
|
1222
1284
|
setFloat64: fn,
|
|
1223
1285
|
setInt8: fn,
|
|
@@ -1270,6 +1332,8 @@ export const permitted = {
|
|
|
1270
1332
|
'@@toStringTag': 'string',
|
|
1271
1333
|
// https://github.com/tc39/proposal-async-iterator-helpers
|
|
1272
1334
|
toAsync: fn,
|
|
1335
|
+
// See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
|
|
1336
|
+
'@@dispose': false,
|
|
1273
1337
|
},
|
|
1274
1338
|
|
|
1275
1339
|
// https://github.com/tc39/proposal-iterator-helpers
|
|
@@ -1312,6 +1376,8 @@ export const permitted = {
|
|
|
1312
1376
|
every: fn,
|
|
1313
1377
|
find: fn,
|
|
1314
1378
|
'@@toStringTag': 'string',
|
|
1379
|
+
// See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
|
|
1380
|
+
'@@asyncDispose': false,
|
|
1315
1381
|
},
|
|
1316
1382
|
|
|
1317
1383
|
// https://github.com/tc39/proposal-async-iterator-helpers
|
|
@@ -1502,12 +1568,11 @@ export const permitted = {
|
|
|
1502
1568
|
evaluate: fn,
|
|
1503
1569
|
globalThis: getter,
|
|
1504
1570
|
name: getter,
|
|
1505
|
-
// Should this be proposed?
|
|
1506
|
-
toString: fn,
|
|
1507
1571
|
import: asyncFn,
|
|
1508
1572
|
load: asyncFn,
|
|
1509
1573
|
importNow: fn,
|
|
1510
1574
|
module: fn,
|
|
1575
|
+
'@@toStringTag': 'string',
|
|
1511
1576
|
},
|
|
1512
1577
|
|
|
1513
1578
|
lockdown: fn,
|
package/src/tame-domains.js
CHANGED
|
@@ -17,12 +17,10 @@ export function tameDomains(domainTaming = 'safe') {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Protect against the hazard presented by Node.js domains.
|
|
20
|
-
|
|
20
|
+
const globalProcess = globalThis.process || undefined;
|
|
21
|
+
if (typeof globalProcess === 'object') {
|
|
21
22
|
// Check whether domains were initialized.
|
|
22
|
-
const domainDescriptor = getOwnPropertyDescriptor(
|
|
23
|
-
globalThis.process,
|
|
24
|
-
'domain',
|
|
25
|
-
);
|
|
23
|
+
const domainDescriptor = getOwnPropertyDescriptor(globalProcess, 'domain');
|
|
26
24
|
if (domainDescriptor !== undefined && domainDescriptor.get !== undefined) {
|
|
27
25
|
// The domain descriptor on Node.js initially has value: null, which
|
|
28
26
|
// becomes a get, set pair after domains initialize.
|
|
@@ -37,7 +35,7 @@ export function tameDomains(domainTaming = 'safe') {
|
|
|
37
35
|
// The domain module merely throws an exception when it attempts to define
|
|
38
36
|
// the domain property of the process global during its initialization.
|
|
39
37
|
// We have no better recourse because Node.js uses defineProperty too.
|
|
40
|
-
defineProperty(
|
|
38
|
+
defineProperty(globalProcess, 'domain', {
|
|
41
39
|
value: null,
|
|
42
40
|
configurable: false,
|
|
43
41
|
writable: false,
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOwnPropertyDescriptor,
|
|
3
|
+
apply,
|
|
4
|
+
defineProperty,
|
|
5
|
+
toStringTagSymbol,
|
|
6
|
+
} from './commons.js';
|
|
7
|
+
|
|
8
|
+
const throws = thunk => {
|
|
9
|
+
try {
|
|
10
|
+
thunk();
|
|
11
|
+
return false;
|
|
12
|
+
} catch (er) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Exported for convenience of unit testing. Harmless, but not expected
|
|
19
|
+
* to be useful by itself.
|
|
20
|
+
*
|
|
21
|
+
* @param {any} obj
|
|
22
|
+
* @param {string|symbol} prop
|
|
23
|
+
* @param {any} expectedValue
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
* Returns whether `tameFauxDataProperty` turned the property in question
|
|
26
|
+
* from an apparent faux data property into the actual data property it
|
|
27
|
+
* seemed to emulate.
|
|
28
|
+
* If this function returns `false`, then we hope no effects happened.
|
|
29
|
+
* However, sniffing out if an accessor property seems to be a faux data
|
|
30
|
+
* property requires invoking the getter and setter functions that might
|
|
31
|
+
* possibly have side effects.
|
|
32
|
+
* `tameFauxDataProperty` is not in a position to tell.
|
|
33
|
+
*/
|
|
34
|
+
export const tameFauxDataProperty = (obj, prop, expectedValue) => {
|
|
35
|
+
if (obj === undefined) {
|
|
36
|
+
// The object does not exist in this version of the platform
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const desc = getOwnPropertyDescriptor(obj, prop);
|
|
40
|
+
if (!desc || 'value' in desc) {
|
|
41
|
+
// The property either doesn't exist, or is already an actual data property.
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const { get, set } = desc;
|
|
45
|
+
if (typeof get !== 'function' || typeof set !== 'function') {
|
|
46
|
+
// A faux data property has both a getter and a setter
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (get() !== expectedValue) {
|
|
50
|
+
// The getter called by itself should produce the expectedValue
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (apply(get, obj, []) !== expectedValue) {
|
|
54
|
+
// The getter called with `this === obj` should also return the
|
|
55
|
+
// expectedValue.
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const testValue = 'Seems to be a setter';
|
|
59
|
+
const subject1 = { __proto__: null };
|
|
60
|
+
apply(set, subject1, [testValue]);
|
|
61
|
+
if (subject1[prop] !== testValue) {
|
|
62
|
+
// The setter called with an unrelated object as `this` should
|
|
63
|
+
// set the property on the object.
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const subject2 = { __proto__: obj };
|
|
67
|
+
apply(set, subject2, [testValue]);
|
|
68
|
+
if (subject2[prop] !== testValue) {
|
|
69
|
+
// The setter called on an object that inherits from `obj` should
|
|
70
|
+
// override the property from `obj` as if by assignment.
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!throws(() => apply(set, obj, [expectedValue]))) {
|
|
74
|
+
// The setter called with `this === obj` should throw without having
|
|
75
|
+
// caused any effect.
|
|
76
|
+
// This is the test that has the greatest danger of leaving behind some
|
|
77
|
+
// persistent side effect. The most obvious one is to emulate a
|
|
78
|
+
// successful assignment to the property. That's why this test
|
|
79
|
+
// uses `expectedValue`, so that case is likely not to actually
|
|
80
|
+
// change anything.
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if ('originalValue' in get) {
|
|
84
|
+
// The ses-shim uniquely, as far as we know, puts an `originalValue`
|
|
85
|
+
// property on the getter, so that reflect property tranversal algorithms,
|
|
86
|
+
// like `harden`, will traverse into the enulated value without
|
|
87
|
+
// calling the getter. That does not happen until `permits-intrinsics.js`
|
|
88
|
+
// which is much later. So if we see one this early, we should
|
|
89
|
+
// not assume we understand what's going on.
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// We assume that this code runs before any untrusted code runs, so
|
|
94
|
+
// we do not need to worry about the above conditions passing because of
|
|
95
|
+
// malicious intent. In fact, it runs even before vetted shims are supposed
|
|
96
|
+
// to run, between repair and hardening. Given that, after all these tests
|
|
97
|
+
// pass, we have adequately validated that the property in question is
|
|
98
|
+
// an accessor function whose purpose is suppressing the override mistake,
|
|
99
|
+
// i.e., enabling a non-writable property to be overridden by assignment.
|
|
100
|
+
// In that case, here we *temporarily* turn it into the data property
|
|
101
|
+
// it seems to emulate, but writable so that it does not trigger the
|
|
102
|
+
// override mistake while in this temporary state.
|
|
103
|
+
|
|
104
|
+
// For those properties that are also listed in `enablements.js`,
|
|
105
|
+
// that phase will re-enable override for these properties, but
|
|
106
|
+
// via accessor functions that SES controls, so we know what they are
|
|
107
|
+
// doing. In addition, the getter functions installed by
|
|
108
|
+
// `enable-property-overrides.js` have an `originalValue` field
|
|
109
|
+
// enabling meta-traversal code like harden to visit the original value
|
|
110
|
+
// without calling the getter.
|
|
111
|
+
|
|
112
|
+
if (desc.configurable === false) {
|
|
113
|
+
// Even though it seems to be a faux data property, we're unable to fix it.
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Many of the `return false;` cases above plausibly should be turned into
|
|
118
|
+
// errors, or an least generate warnings. However, for those, the checks
|
|
119
|
+
// following this phase are likely to signal an error anyway.
|
|
120
|
+
|
|
121
|
+
// At this point, we have passed all our sniff checks for validating that
|
|
122
|
+
// it seems to be a faux data property with the expected value. Turn
|
|
123
|
+
// it into the actual data property it emulates, but writable so there is
|
|
124
|
+
// not yet an override mistake problem.
|
|
125
|
+
|
|
126
|
+
defineProperty(obj, prop, {
|
|
127
|
+
value: expectedValue,
|
|
128
|
+
writable: true,
|
|
129
|
+
enumerable: desc.enumerable,
|
|
130
|
+
configurable: true,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* In JavaScript, the so-called "override mistake" is the inability to
|
|
138
|
+
* override an inherited non-writable data property by assignment. A common
|
|
139
|
+
* workaround is to instead define an accessor property that acts like
|
|
140
|
+
* a non-writable data property, except that it allows an object that
|
|
141
|
+
* inherits this property to override it by assignment. Let's call
|
|
142
|
+
* an access property that acts this way a "faux data property". In this
|
|
143
|
+
* ses-shim, `enable-property-overrides.js` makes the properties listed in
|
|
144
|
+
* `enablements.js` into faux data properties.
|
|
145
|
+
*
|
|
146
|
+
* But the ses-shim is not alone in use of this trick. Starting with the
|
|
147
|
+
* [Iterator Helpers proposal](https://github.com/tc39/proposal-iterator-helpers),
|
|
148
|
+
* some properties are defined as (what we call) faux data properties.
|
|
149
|
+
* Some of these are new properties (`Interator.prototype.constructor`) and
|
|
150
|
+
* some are old data properties converted to accessor properties
|
|
151
|
+
* (`Iterator.prototype[String.toStringTag]`). So the ses-shim needs to be
|
|
152
|
+
* prepared for some enumerated set of properties to already be faux data
|
|
153
|
+
* properties in the platform prior to our initialization.
|
|
154
|
+
*
|
|
155
|
+
* For these possible faux data properties, it is important that
|
|
156
|
+
* `permits.js` describe each as a data property, so that it can further
|
|
157
|
+
* constrain the apparent value (that allegedly would be returned by the
|
|
158
|
+
* getter) according to its own permits.
|
|
159
|
+
*
|
|
160
|
+
* However, at the time of this writing, the precise behavior specified
|
|
161
|
+
* by the iterator-helpers proposal for these faux data properties is
|
|
162
|
+
* novel. We should not be too confident that all further such platform
|
|
163
|
+
* additions do what we would now expect. So, for each of these possible
|
|
164
|
+
* faux data properties, we do some sniffing to see if it behaves as we
|
|
165
|
+
* currently expect a faux data property to act. If not, then
|
|
166
|
+
* `tameFauxDataProperties` tries not to modify it, leaving it to later
|
|
167
|
+
* checks, especially `permits-intrinsics.js`, to error when it sees an
|
|
168
|
+
* unexpected accessor.
|
|
169
|
+
*
|
|
170
|
+
* If one of these enumerated accessor properties does seem to be
|
|
171
|
+
* a faithful faux data property, then `tameFauxDataProperties` itself
|
|
172
|
+
* *tempoarily* turns it into the actual data property that it seems to emulate.
|
|
173
|
+
* This data property starts as writable, so that in this state it will
|
|
174
|
+
* not trigger the override mistake, i.e., assignment to an object inheriting
|
|
175
|
+
* this property is allowed to succeed at overriding this property.
|
|
176
|
+
*
|
|
177
|
+
* For those properties that should be a faux data property rather than an
|
|
178
|
+
* actual one, such as those from the iterator-helpers proposal,
|
|
179
|
+
* they should be listed as such in `enablements.js`, so
|
|
180
|
+
* `enable-property-overrides.js` will turn it back into a faux data property.
|
|
181
|
+
* But one controlled by the ses-shim, whose behavior we understand.
|
|
182
|
+
*
|
|
183
|
+
* `tameFauxDataProperties`, which turns these into actual data properties,
|
|
184
|
+
* happens during the `repairIntrinsics` phase
|
|
185
|
+
* of `lockdown`, before even vetted shim are supposed to run.
|
|
186
|
+
* `enable-property-overrides.js` runs after vetted shims, turning the
|
|
187
|
+
* appropriate ones back into faux data properties. Thus vetted shims
|
|
188
|
+
* can observe the possibly non-conforming state where these are temporarily
|
|
189
|
+
* actual data properties, rather than faux data properties.
|
|
190
|
+
*
|
|
191
|
+
* Coordinate the property enumeration here
|
|
192
|
+
* with `enablements.js`, so the appropriate properties are
|
|
193
|
+
* turned back to faux data properties.
|
|
194
|
+
*
|
|
195
|
+
* @param {Record<any,any>} intrinsics
|
|
196
|
+
*/
|
|
197
|
+
export const tameFauxDataProperties = intrinsics => {
|
|
198
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
199
|
+
tameFauxDataProperty(
|
|
200
|
+
intrinsics['%IteratorPrototype%'],
|
|
201
|
+
'constructor',
|
|
202
|
+
intrinsics.Iterator,
|
|
203
|
+
);
|
|
204
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
205
|
+
tameFauxDataProperty(
|
|
206
|
+
intrinsics['%IteratorPrototype%'],
|
|
207
|
+
toStringTagSymbol,
|
|
208
|
+
'Iterator',
|
|
209
|
+
);
|
|
210
|
+
};
|
package/types.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface ThirdPartyStaticModuleInterface {
|
|
|
62
62
|
* Note that this value does _not_ contain any numeric or symbol property keys, which can theoretically be members of `exports` in a CommonJS module.
|
|
63
63
|
*/
|
|
64
64
|
execute(
|
|
65
|
-
|
|
65
|
+
exportsTarget: Record<string, any>,
|
|
66
66
|
compartment: Compartment,
|
|
67
67
|
resolvedImports: Record<string, string>,
|
|
68
68
|
): void;
|