ses 0.18.3 → 0.18.5
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 +16 -0
- package/README.md +105 -47
- package/dist/lockdown.cjs +6779 -6508
- package/dist/lockdown.mjs +6779 -6508
- package/dist/lockdown.umd.js +6779 -6508
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +6779 -6508
- package/dist/ses.mjs +6779 -6508
- package/dist/ses.umd.js +6779 -6508
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -1
- package/package.json +17 -13
- package/src/commons.js +14 -11
- package/src/compartment-evaluate.js +1 -1
- package/src/compartment-shim.js +10 -14
- package/src/enable-property-overrides.js +4 -4
- package/src/error/assert.js +36 -9
- package/src/error/note-log-args.js +2 -4
- package/src/error/tame-console.js +1 -1
- package/src/error/tame-error-constructor.js +3 -3
- package/src/error/tame-v8-error-constructor.js +1 -1
- package/src/error/types.js +1 -0
- package/src/eval-scope.js +4 -2
- package/src/get-anonymous-intrinsics.js +25 -4
- package/src/global-object.js +2 -2
- package/src/intrinsics.js +14 -11
- package/src/lockdown-shim.js +13 -26
- package/src/make-hardener.js +8 -1
- package/src/make-safe-evaluator.js +6 -5
- package/src/module-instance.js +8 -11
- package/src/module-link.js +2 -2
- package/src/module-load.js +5 -7
- package/src/module-proxy.js +12 -12
- package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +24 -20
- package/src/{whitelist.js → permits.js} +135 -8
- package/src/scope-constants.js +1 -0
- package/src/strict-scope-terminator.js +10 -4
- package/src/tame-date-constructor.js +1 -1
- package/src/tame-domains.js +2 -2
- package/src/tame-function-constructors.js +2 -2
- package/src/tame-function-tostring.js +1 -1
- package/src/tame-harden.js +7 -1
- package/src/tame-locale-methods.js +2 -2
- package/src/tame-math-object.js +1 -1
- package/src/tame-regexp-constructor.js +11 -2
- package/src/tame-symbol-constructor.js +65 -0
- package/src/transforms.js +3 -3
- package/types.d.ts +1 -0
- package/src/environment-options.js +0 -117
package/src/lockdown-shim.js
CHANGED
|
@@ -14,22 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
// @ts-check
|
|
16
16
|
|
|
17
|
+
import { makeEnvironmentCaptor } from '@endo/env-options';
|
|
17
18
|
import {
|
|
18
19
|
FERAL_FUNCTION,
|
|
19
20
|
FERAL_EVAL,
|
|
20
21
|
TypeError,
|
|
21
22
|
arrayFilter,
|
|
22
|
-
arrayMap,
|
|
23
23
|
globalThis,
|
|
24
24
|
is,
|
|
25
25
|
ownKeys,
|
|
26
26
|
stringSplit,
|
|
27
27
|
noEvalEvaluate,
|
|
28
28
|
} from './commons.js';
|
|
29
|
-
import { enJoin } from './error/stringify-utils.js';
|
|
30
29
|
import { makeHardener } from './make-hardener.js';
|
|
31
30
|
import { makeIntrinsicsCollector } from './intrinsics.js';
|
|
32
|
-
import whitelistIntrinsics from './
|
|
31
|
+
import whitelistIntrinsics from './permits-intrinsics.js';
|
|
33
32
|
import tameFunctionConstructors from './tame-function-constructors.js';
|
|
34
33
|
import tameDateConstructor from './tame-date-constructor.js';
|
|
35
34
|
import tameMathObject from './tame-math-object.js';
|
|
@@ -42,17 +41,17 @@ import {
|
|
|
42
41
|
setGlobalObjectEvaluators,
|
|
43
42
|
} from './global-object.js';
|
|
44
43
|
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
45
|
-
import { initialGlobalPropertyNames } from './
|
|
44
|
+
import { initialGlobalPropertyNames } from './permits.js';
|
|
46
45
|
import { tameFunctionToString } from './tame-function-tostring.js';
|
|
47
46
|
import { tameDomains } from './tame-domains.js';
|
|
48
47
|
|
|
49
48
|
import { tameConsole } from './error/tame-console.js';
|
|
50
49
|
import tameErrorConstructor from './error/tame-error-constructor.js';
|
|
51
50
|
import { assert, makeAssert } from './error/assert.js';
|
|
52
|
-
import { makeEnvironmentCaptor } from './environment-options.js';
|
|
53
51
|
import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
|
|
54
52
|
import { makeCompartmentConstructor } from './compartment-shim.js';
|
|
55
53
|
import { tameHarden } from './tame-harden.js';
|
|
54
|
+
import { tameSymbolConstructor } from './tame-symbol-constructor.js';
|
|
56
55
|
|
|
57
56
|
/** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
|
|
58
57
|
|
|
@@ -117,7 +116,7 @@ const assertDirectEvalAvailable = () => {
|
|
|
117
116
|
}
|
|
118
117
|
if (!allowed) {
|
|
119
118
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
|
|
120
|
-
throw
|
|
119
|
+
throw TypeError(
|
|
121
120
|
`SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
|
|
122
121
|
);
|
|
123
122
|
}
|
|
@@ -153,8 +152,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
153
152
|
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
|
|
154
153
|
// for an explanation.
|
|
155
154
|
|
|
156
|
-
const { getEnvironmentOption: getenv
|
|
157
|
-
makeEnvironmentCaptor(globalThis);
|
|
155
|
+
const { getEnvironmentOption: getenv } = makeEnvironmentCaptor(globalThis);
|
|
158
156
|
|
|
159
157
|
const {
|
|
160
158
|
errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
|
|
@@ -181,17 +179,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
181
179
|
...extraOptions
|
|
182
180
|
} = options;
|
|
183
181
|
|
|
184
|
-
const capturedEnvironmentOptionNames = getCapturedEnvironmentOptionNames();
|
|
185
|
-
if (capturedEnvironmentOptionNames.length > 0) {
|
|
186
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
187
|
-
console.warn(
|
|
188
|
-
`SES Lockdown using options from environment variables ${enJoin(
|
|
189
|
-
arrayMap(capturedEnvironmentOptionNames, q),
|
|
190
|
-
'and',
|
|
191
|
-
)}`,
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
182
|
evalTaming === 'unsafeEval' ||
|
|
196
183
|
evalTaming === 'safeEval' ||
|
|
197
184
|
evalTaming === 'noEval' ||
|
|
@@ -210,7 +197,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
210
197
|
TypeError,
|
|
211
198
|
);
|
|
212
199
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
|
|
213
|
-
priorLockdown =
|
|
200
|
+
priorLockdown = TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
214
201
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
215
202
|
// trace retained:
|
|
216
203
|
priorLockdown.stack;
|
|
@@ -252,7 +239,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
252
239
|
|
|
253
240
|
if (seemsToBeLockedDown()) {
|
|
254
241
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_MULTIPLE_INSTANCES.md
|
|
255
|
-
throw
|
|
242
|
+
throw TypeError(
|
|
256
243
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`,
|
|
257
244
|
);
|
|
258
245
|
}
|
|
@@ -263,6 +250,10 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
263
250
|
|
|
264
251
|
tameDomains(domainTaming);
|
|
265
252
|
|
|
253
|
+
// Replace Function.prototype.toString with one that recognizes
|
|
254
|
+
// shimmed functions as honorary native functions.
|
|
255
|
+
const markVirtualizedNativeFunction = tameFunctionToString();
|
|
256
|
+
|
|
266
257
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
267
258
|
makeIntrinsicsCollector();
|
|
268
259
|
|
|
@@ -275,6 +266,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
275
266
|
addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
|
|
276
267
|
addIntrinsics(tameMathObject(mathTaming));
|
|
277
268
|
addIntrinsics(tameRegExpConstructor(regExpTaming));
|
|
269
|
+
addIntrinsics(tameSymbolConstructor());
|
|
278
270
|
|
|
279
271
|
addIntrinsics(getAnonymousIntrinsics());
|
|
280
272
|
|
|
@@ -295,7 +287,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
295
287
|
optGetStackString = intrinsics['%InitialGetStackString%'];
|
|
296
288
|
}
|
|
297
289
|
const consoleRecord = tameConsole(
|
|
298
|
-
// @ts-expect-error tameConsole does its own input validation
|
|
299
290
|
consoleTaming,
|
|
300
291
|
errorTrapping,
|
|
301
292
|
unhandledRejectionTrapping,
|
|
@@ -317,10 +308,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
317
308
|
// Replace *Locale* methods with their non-locale equivalents
|
|
318
309
|
tameLocaleMethods(intrinsics, localeTaming);
|
|
319
310
|
|
|
320
|
-
// Replace Function.prototype.toString with one that recognizes
|
|
321
|
-
// shimmed functions as honorary native functions.
|
|
322
|
-
const markVirtualizedNativeFunction = tameFunctionToString();
|
|
323
|
-
|
|
324
311
|
/**
|
|
325
312
|
* 2. WHITELIST to standardize the environment.
|
|
326
313
|
*/
|
package/src/make-hardener.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
TypeError,
|
|
28
28
|
WeakMap,
|
|
29
29
|
WeakSet,
|
|
30
|
+
globalThis,
|
|
30
31
|
apply,
|
|
31
32
|
arrayForEach,
|
|
32
33
|
defineProperty,
|
|
@@ -127,6 +128,12 @@ const freezeTypedArray = array => {
|
|
|
127
128
|
* @returns {Harden}
|
|
128
129
|
*/
|
|
129
130
|
export const makeHardener = () => {
|
|
131
|
+
// Use a native hardener if possible.
|
|
132
|
+
if (typeof globalThis.harden === 'function') {
|
|
133
|
+
const safeHarden = globalThis.harden;
|
|
134
|
+
return safeHarden;
|
|
135
|
+
}
|
|
136
|
+
|
|
130
137
|
const hardened = new WeakSet();
|
|
131
138
|
|
|
132
139
|
const { harden } = {
|
|
@@ -153,7 +160,7 @@ export const makeHardener = () => {
|
|
|
153
160
|
const type = typeof val;
|
|
154
161
|
if (type !== 'object' && type !== 'function') {
|
|
155
162
|
// future proof: break until someone figures out what it should do
|
|
156
|
-
throw
|
|
163
|
+
throw TypeError(`Unexpected typeof: ${type}`);
|
|
157
164
|
}
|
|
158
165
|
if (weaksetHas(hardened, val) || setHas(toFreeze, val)) {
|
|
159
166
|
// Ignore if this is an exit, or we've already visited it
|
|
@@ -19,15 +19,15 @@ const { Fail } = assert;
|
|
|
19
19
|
* @param {object} options
|
|
20
20
|
* @param {object} options.globalObject
|
|
21
21
|
* @param {object} [options.moduleLexicals]
|
|
22
|
-
* @param {Array<Transform>} [options.globalTransforms]
|
|
23
|
-
* @param {
|
|
22
|
+
* @param {Array<import('./lockdown-shim.js').Transform>} [options.globalTransforms]
|
|
23
|
+
* @param {boolean} [options.sloppyGlobalsMode]
|
|
24
24
|
*/
|
|
25
25
|
export const makeSafeEvaluator = ({
|
|
26
26
|
globalObject,
|
|
27
27
|
moduleLexicals = {},
|
|
28
28
|
globalTransforms = [],
|
|
29
29
|
sloppyGlobalsMode = false,
|
|
30
|
-
}
|
|
30
|
+
}) => {
|
|
31
31
|
const scopeTerminator = sloppyGlobalsMode
|
|
32
32
|
? createSloppyGlobalsScopeTerminator(globalObject)
|
|
33
33
|
: strictScopeTerminator;
|
|
@@ -54,9 +54,10 @@ export const makeSafeEvaluator = ({
|
|
|
54
54
|
/**
|
|
55
55
|
* @param {string} source
|
|
56
56
|
* @param {object} [options]
|
|
57
|
-
* @param {Array<Transform>} [options.localTransforms]
|
|
57
|
+
* @param {Array<import('./lockdown-shim.js').Transform>} [options.localTransforms]
|
|
58
58
|
*/
|
|
59
|
-
const safeEvaluate = (source,
|
|
59
|
+
const safeEvaluate = (source, options) => {
|
|
60
|
+
const { localTransforms = [] } = options || {};
|
|
60
61
|
provideEvaluate();
|
|
61
62
|
|
|
62
63
|
// Execute the mandatory transforms last to ensure that any rewritten code
|
package/src/module-instance.js
CHANGED
|
@@ -46,7 +46,7 @@ export const makeThirdPartyModuleInstance = (
|
|
|
46
46
|
!isArray(staticModuleRecord.exports) ||
|
|
47
47
|
arraySome(staticModuleRecord.exports, name => typeof name !== 'string')
|
|
48
48
|
) {
|
|
49
|
-
throw
|
|
49
|
+
throw TypeError(
|
|
50
50
|
`SES third-party static module record "exports" property must be an array of strings for module ${moduleSpecifier}`,
|
|
51
51
|
);
|
|
52
52
|
}
|
|
@@ -189,14 +189,13 @@ export const makeModuleInstance = (
|
|
|
189
189
|
// fixed binding state
|
|
190
190
|
let value;
|
|
191
191
|
let tdz = true;
|
|
192
|
+
/** @type {null | Array<(value: any) => void>} */
|
|
192
193
|
let optUpdaters = [];
|
|
193
194
|
|
|
194
195
|
// tdz sensitive getter
|
|
195
196
|
const get = () => {
|
|
196
197
|
if (tdz) {
|
|
197
|
-
throw
|
|
198
|
-
`binding ${q(localName)} not yet initialized`,
|
|
199
|
-
);
|
|
198
|
+
throw ReferenceError(`binding ${q(localName)} not yet initialized`);
|
|
200
199
|
}
|
|
201
200
|
return value;
|
|
202
201
|
};
|
|
@@ -206,7 +205,7 @@ export const makeModuleInstance = (
|
|
|
206
205
|
// init with initValue of a declared const binding, and return
|
|
207
206
|
// it.
|
|
208
207
|
if (!tdz) {
|
|
209
|
-
throw
|
|
208
|
+
throw TypeError(
|
|
210
209
|
`Internal: binding ${q(localName)} already initialized`,
|
|
211
210
|
);
|
|
212
211
|
}
|
|
@@ -214,7 +213,7 @@ export const makeModuleInstance = (
|
|
|
214
213
|
const updaters = optUpdaters;
|
|
215
214
|
optUpdaters = null;
|
|
216
215
|
tdz = false;
|
|
217
|
-
for (const updater of updaters) {
|
|
216
|
+
for (const updater of updaters || []) {
|
|
218
217
|
updater(initValue);
|
|
219
218
|
}
|
|
220
219
|
return initValue;
|
|
@@ -228,7 +227,7 @@ export const makeModuleInstance = (
|
|
|
228
227
|
return;
|
|
229
228
|
}
|
|
230
229
|
if (tdz) {
|
|
231
|
-
arrayPush(optUpdaters, updater);
|
|
230
|
+
arrayPush(optUpdaters || [], updater);
|
|
232
231
|
} else {
|
|
233
232
|
updater(value);
|
|
234
233
|
}
|
|
@@ -266,7 +265,7 @@ export const makeModuleInstance = (
|
|
|
266
265
|
// tdz sensitive getter
|
|
267
266
|
const get = () => {
|
|
268
267
|
if (tdz) {
|
|
269
|
-
throw
|
|
268
|
+
throw ReferenceError(
|
|
270
269
|
`binding ${q(liveExportName)} not yet initialized`,
|
|
271
270
|
);
|
|
272
271
|
}
|
|
@@ -293,9 +292,7 @@ export const makeModuleInstance = (
|
|
|
293
292
|
// tdz sensitive setter
|
|
294
293
|
const set = newValue => {
|
|
295
294
|
if (tdz) {
|
|
296
|
-
throw
|
|
297
|
-
`binding ${q(localName)} not yet initialized`,
|
|
298
|
-
);
|
|
295
|
+
throw ReferenceError(`binding ${q(localName)} not yet initialized`);
|
|
299
296
|
}
|
|
300
297
|
value = newValue;
|
|
301
298
|
for (const updater of updaters) {
|
package/src/module-link.js
CHANGED
|
@@ -47,7 +47,7 @@ export const link = (
|
|
|
47
47
|
|
|
48
48
|
const moduleRecord = mapGet(moduleRecords, moduleSpecifier);
|
|
49
49
|
if (moduleRecord === undefined) {
|
|
50
|
-
throw
|
|
50
|
+
throw ReferenceError(
|
|
51
51
|
`Missing link to module ${q(moduleSpecifier)} from compartment ${q(
|
|
52
52
|
compartmentName,
|
|
53
53
|
)}`,
|
|
@@ -152,7 +152,7 @@ export const instantiate = (
|
|
|
152
152
|
resolvedImports,
|
|
153
153
|
);
|
|
154
154
|
} else {
|
|
155
|
-
throw
|
|
155
|
+
throw TypeError(
|
|
156
156
|
`importHook must return a static module record, got ${q(
|
|
157
157
|
staticModuleRecord,
|
|
158
158
|
)}`,
|
package/src/module-load.js
CHANGED
|
@@ -181,7 +181,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
181
181
|
if (staticModuleRecord.record !== undefined) {
|
|
182
182
|
// ensure expected record shape
|
|
183
183
|
if (staticModuleRecord.compartment !== undefined) {
|
|
184
|
-
throw
|
|
184
|
+
throw TypeError(
|
|
185
185
|
'Cannot redirect to an explicit record with a specified compartment',
|
|
186
186
|
);
|
|
187
187
|
}
|
|
@@ -211,7 +211,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
211
211
|
if (staticModuleRecord.compartment !== undefined) {
|
|
212
212
|
// ensure expected record shape
|
|
213
213
|
if (staticModuleRecord.importMeta !== undefined) {
|
|
214
|
-
throw
|
|
214
|
+
throw TypeError(
|
|
215
215
|
'Cannot redirect to an implicit record with a specified importMeta',
|
|
216
216
|
);
|
|
217
217
|
}
|
|
@@ -230,9 +230,7 @@ const loadWithoutErrorAnnotation = async (
|
|
|
230
230
|
return aliasRecord;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
throw
|
|
234
|
-
'Unnexpected RedirectStaticModuleInterface record shape',
|
|
235
|
-
);
|
|
233
|
+
throw TypeError('Unnexpected RedirectStaticModuleInterface record shape');
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
return loadRecord(
|
|
@@ -319,7 +317,7 @@ export const load = async (
|
|
|
319
317
|
|
|
320
318
|
/** @type {Set<Promise<undefined>>} */
|
|
321
319
|
const pendingJobs = new Set();
|
|
322
|
-
/** @type {Map<object, Map<string, Promise<Record
|
|
320
|
+
/** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
|
|
323
321
|
const moduleLoads = new Map();
|
|
324
322
|
/** @type {Array<Error>} */
|
|
325
323
|
const errors = [];
|
|
@@ -351,7 +349,7 @@ export const load = async (
|
|
|
351
349
|
|
|
352
350
|
// Throw an aggregate error if there were any errors.
|
|
353
351
|
if (errors.length > 0) {
|
|
354
|
-
throw
|
|
352
|
+
throw TypeError(
|
|
355
353
|
`Failed to load module ${q(moduleSpecifier)} in package ${q(
|
|
356
354
|
compartmentName,
|
|
357
355
|
)} (${errors.length} underlying failures: ${arrayJoin(
|
package/src/module-proxy.js
CHANGED
|
@@ -60,7 +60,7 @@ export const deferExports = () => {
|
|
|
60
60
|
exportsProxy: new Proxy(proxiedExports, {
|
|
61
61
|
get(_target, name, receiver) {
|
|
62
62
|
if (!active) {
|
|
63
|
-
throw
|
|
63
|
+
throw TypeError(
|
|
64
64
|
`Cannot get property ${q(
|
|
65
65
|
name,
|
|
66
66
|
)} of module exports namespace, the module has not yet begun to execute`,
|
|
@@ -69,13 +69,13 @@ export const deferExports = () => {
|
|
|
69
69
|
return reflectGet(proxiedExports, name, receiver);
|
|
70
70
|
},
|
|
71
71
|
set(_target, name, _value) {
|
|
72
|
-
throw
|
|
72
|
+
throw TypeError(
|
|
73
73
|
`Cannot set property ${q(name)} of module exports namespace`,
|
|
74
74
|
);
|
|
75
75
|
},
|
|
76
76
|
has(_target, name) {
|
|
77
77
|
if (!active) {
|
|
78
|
-
throw
|
|
78
|
+
throw TypeError(
|
|
79
79
|
`Cannot check property ${q(
|
|
80
80
|
name,
|
|
81
81
|
)}, the module has not yet begun to execute`,
|
|
@@ -84,13 +84,13 @@ export const deferExports = () => {
|
|
|
84
84
|
return reflectHas(proxiedExports, name);
|
|
85
85
|
},
|
|
86
86
|
deleteProperty(_target, name) {
|
|
87
|
-
throw
|
|
87
|
+
throw TypeError(
|
|
88
88
|
`Cannot delete property ${q(name)}s of module exports namespace`,
|
|
89
89
|
);
|
|
90
90
|
},
|
|
91
91
|
ownKeys(_target) {
|
|
92
92
|
if (!active) {
|
|
93
|
-
throw
|
|
93
|
+
throw TypeError(
|
|
94
94
|
'Cannot enumerate keys, the module has not yet begun to execute',
|
|
95
95
|
);
|
|
96
96
|
}
|
|
@@ -98,7 +98,7 @@ export const deferExports = () => {
|
|
|
98
98
|
},
|
|
99
99
|
getOwnPropertyDescriptor(_target, name) {
|
|
100
100
|
if (!active) {
|
|
101
|
-
throw
|
|
101
|
+
throw TypeError(
|
|
102
102
|
`Cannot get own property descriptor ${q(
|
|
103
103
|
name,
|
|
104
104
|
)}, the module has not yet begun to execute`,
|
|
@@ -108,7 +108,7 @@ export const deferExports = () => {
|
|
|
108
108
|
},
|
|
109
109
|
preventExtensions(_target) {
|
|
110
110
|
if (!active) {
|
|
111
|
-
throw
|
|
111
|
+
throw TypeError(
|
|
112
112
|
'Cannot prevent extensions of module exports namespace, the module has not yet begun to execute',
|
|
113
113
|
);
|
|
114
114
|
}
|
|
@@ -116,7 +116,7 @@ export const deferExports = () => {
|
|
|
116
116
|
},
|
|
117
117
|
isExtensible() {
|
|
118
118
|
if (!active) {
|
|
119
|
-
throw
|
|
119
|
+
throw TypeError(
|
|
120
120
|
'Cannot check extensibility of module exports namespace, the module has not yet begun to execute',
|
|
121
121
|
);
|
|
122
122
|
}
|
|
@@ -126,20 +126,20 @@ export const deferExports = () => {
|
|
|
126
126
|
return null;
|
|
127
127
|
},
|
|
128
128
|
setPrototypeOf(_target, _proto) {
|
|
129
|
-
throw
|
|
129
|
+
throw TypeError('Cannot set prototype of module exports namespace');
|
|
130
130
|
},
|
|
131
131
|
defineProperty(_target, name, _descriptor) {
|
|
132
|
-
throw
|
|
132
|
+
throw TypeError(
|
|
133
133
|
`Cannot define property ${q(name)} of module exports namespace`,
|
|
134
134
|
);
|
|
135
135
|
},
|
|
136
136
|
apply(_target, _thisArg, _args) {
|
|
137
|
-
throw
|
|
137
|
+
throw TypeError(
|
|
138
138
|
'Cannot call module exports namespace, it is not a function',
|
|
139
139
|
);
|
|
140
140
|
},
|
|
141
141
|
construct(_target, _args) {
|
|
142
|
-
throw
|
|
142
|
+
throw TypeError(
|
|
143
143
|
'Cannot construct module exports namespace, it is not a constructor',
|
|
144
144
|
);
|
|
145
145
|
},
|
|
@@ -43,10 +43,11 @@
|
|
|
43
43
|
// name to the console as a useful diagnostic, possibly provoking an expansion
|
|
44
44
|
// of the whitelist.
|
|
45
45
|
|
|
46
|
-
import {
|
|
46
|
+
import { permitted, FunctionInstance, isAccessorPermit } from './permits.js';
|
|
47
47
|
import {
|
|
48
48
|
Map,
|
|
49
49
|
String,
|
|
50
|
+
Symbol,
|
|
50
51
|
TypeError,
|
|
51
52
|
arrayFilter,
|
|
52
53
|
arrayIncludes,
|
|
@@ -78,15 +79,14 @@ export default function whitelistIntrinsics(
|
|
|
78
79
|
|
|
79
80
|
// These symbols are allowed as well-known symbols
|
|
80
81
|
const wellKnownSymbolNames = new Map(
|
|
81
|
-
|
|
82
|
+
Symbol
|
|
82
83
|
? arrayMap(
|
|
83
84
|
arrayFilter(
|
|
84
|
-
entries(
|
|
85
|
+
entries(permitted['%SharedSymbol%']),
|
|
85
86
|
([name, permit]) =>
|
|
86
|
-
permit === 'symbol' &&
|
|
87
|
-
typeof intrinsics.Symbol[name] === 'symbol',
|
|
87
|
+
permit === 'symbol' && typeof Symbol[name] === 'symbol',
|
|
88
88
|
),
|
|
89
|
-
([name]) => [
|
|
89
|
+
([name]) => [Symbol[name], `@@${name}`],
|
|
90
90
|
)
|
|
91
91
|
: [],
|
|
92
92
|
);
|
|
@@ -117,7 +117,7 @@ export default function whitelistIntrinsics(
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
throw
|
|
120
|
+
throw TypeError(`Unexpected property name type ${path} ${prop}`);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/*
|
|
@@ -126,7 +126,7 @@ export default function whitelistIntrinsics(
|
|
|
126
126
|
*/
|
|
127
127
|
function visitPrototype(path, obj, protoName) {
|
|
128
128
|
if (!isObject(obj)) {
|
|
129
|
-
throw
|
|
129
|
+
throw TypeError(`Object expected: ${path}, ${obj}, ${protoName}`);
|
|
130
130
|
}
|
|
131
131
|
const proto = getPrototypeOf(obj);
|
|
132
132
|
|
|
@@ -137,7 +137,7 @@ export default function whitelistIntrinsics(
|
|
|
137
137
|
|
|
138
138
|
// Assert: protoName, if provided, is a string.
|
|
139
139
|
if (protoName !== undefined && typeof protoName !== 'string') {
|
|
140
|
-
throw
|
|
140
|
+
throw TypeError(`Malformed whitelist permit ${path}.__proto__`);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
// If permit not specified, default to Object.prototype.
|
|
@@ -146,9 +146,7 @@ export default function whitelistIntrinsics(
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
// We can't clean [[prototype]], therefore abort.
|
|
149
|
-
throw
|
|
150
|
-
`Unexpected intrinsic ${path}.__proto__ at ${protoName}`,
|
|
151
|
-
);
|
|
149
|
+
throw TypeError(`Unexpected intrinsic ${path}.__proto__ at ${protoName}`);
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
/*
|
|
@@ -181,7 +179,7 @@ export default function whitelistIntrinsics(
|
|
|
181
179
|
|
|
182
180
|
if (objectHasOwnProperty(intrinsics, permit)) {
|
|
183
181
|
if (value !== intrinsics[permit]) {
|
|
184
|
-
throw
|
|
182
|
+
throw TypeError(`Does not match whitelist ${path}`);
|
|
185
183
|
}
|
|
186
184
|
return true;
|
|
187
185
|
}
|
|
@@ -194,7 +192,7 @@ export default function whitelistIntrinsics(
|
|
|
194
192
|
if (arrayIncludes(primitives, permit)) {
|
|
195
193
|
// eslint-disable-next-line valid-typeof
|
|
196
194
|
if (typeof value !== permit) {
|
|
197
|
-
throw
|
|
195
|
+
throw TypeError(
|
|
198
196
|
`At ${path} expected ${permit} not ${typeof value}`,
|
|
199
197
|
);
|
|
200
198
|
}
|
|
@@ -203,7 +201,7 @@ export default function whitelistIntrinsics(
|
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
203
|
|
|
206
|
-
throw
|
|
204
|
+
throw TypeError(`Unexpected whitelist permit ${permit} at ${path}`);
|
|
207
205
|
}
|
|
208
206
|
|
|
209
207
|
/*
|
|
@@ -212,16 +210,19 @@ export default function whitelistIntrinsics(
|
|
|
212
210
|
*/
|
|
213
211
|
function isAllowedProperty(path, obj, prop, permit) {
|
|
214
212
|
const desc = getOwnPropertyDescriptor(obj, prop);
|
|
213
|
+
if (!desc) {
|
|
214
|
+
throw TypeError(`Property ${prop} not found at ${path}`);
|
|
215
|
+
}
|
|
215
216
|
|
|
216
217
|
// Is this a value property?
|
|
217
218
|
if (objectHasOwnProperty(desc, 'value')) {
|
|
218
219
|
if (isAccessorPermit(permit)) {
|
|
219
|
-
throw
|
|
220
|
+
throw TypeError(`Accessor expected at ${path}`);
|
|
220
221
|
}
|
|
221
222
|
return isAllowedPropertyValue(path, desc.value, prop, permit);
|
|
222
223
|
}
|
|
223
224
|
if (!isAccessorPermit(permit)) {
|
|
224
|
-
throw
|
|
225
|
+
throw TypeError(`Accessor not expected at ${path}`);
|
|
225
226
|
}
|
|
226
227
|
return (
|
|
227
228
|
isAllowedPropertyValue(`${path}<get>`, desc.get, prop, permit.get) &&
|
|
@@ -239,7 +240,6 @@ export default function whitelistIntrinsics(
|
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
if (typeof obj === 'function') {
|
|
242
|
-
markVirtualizedNativeFunction(obj);
|
|
243
243
|
if (objectHasOwnProperty(FunctionInstance, permitProp)) {
|
|
244
244
|
return FunctionInstance[permitProp];
|
|
245
245
|
}
|
|
@@ -253,13 +253,17 @@ export default function whitelistIntrinsics(
|
|
|
253
253
|
* Visit all properties for a permit.
|
|
254
254
|
*/
|
|
255
255
|
function visitProperties(path, obj, permit) {
|
|
256
|
-
if (obj === undefined) {
|
|
256
|
+
if (obj === undefined || obj === null) {
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
const protoName = permit['[[Proto]]'];
|
|
261
261
|
visitPrototype(path, obj, protoName);
|
|
262
262
|
|
|
263
|
+
if (typeof obj === 'function') {
|
|
264
|
+
markVirtualizedNativeFunction(obj);
|
|
265
|
+
}
|
|
266
|
+
|
|
263
267
|
for (const prop of ownKeys(obj)) {
|
|
264
268
|
const propString = asStringPropertyName(path, prop);
|
|
265
269
|
const subPath = `${path}.${propString}`;
|
|
@@ -308,5 +312,5 @@ export default function whitelistIntrinsics(
|
|
|
308
312
|
|
|
309
313
|
// Start path with 'intrinsics' to clarify that properties are not
|
|
310
314
|
// removed from the global object by the whitelisting operation.
|
|
311
|
-
visitProperties('intrinsics', intrinsics,
|
|
315
|
+
visitProperties('intrinsics', intrinsics, permitted);
|
|
312
316
|
}
|