ses 2.0.0 → 2.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/dist/lockdown.cjs +1008 -322
- package/dist/lockdown.mjs +1008 -322
- package/dist/lockdown.umd.js +1008 -322
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +1008 -322
- package/dist/ses.cjs +1008 -322
- package/dist/ses.mjs +1008 -322
- package/dist/ses.umd.js +1008 -322
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +4 -0
- package/package.json +5 -39
- package/src/assert-sloppy-mode.js +2 -1
- package/src/cauterize-property.js +3 -2
- package/src/commons.js +62 -9
- package/src/compartment.js +7 -5
- package/src/error/assert.js +16 -21
- package/src/error/tame-error-constructor.js +6 -0
- package/src/error/tame-v8-error-constructor.js +24 -10
- package/src/get-anonymous-intrinsics.js +1 -1
- package/src/get-source-url.js +11 -4
- package/src/lockdown.js +2 -0
- package/src/permits-intrinsics.js +18 -26
- package/src/permits.js +349 -1
- package/src/scope-constants.js +4 -3
- package/src/tame-locale-methods.js +2 -1
- package/src/tame-nan-sidechannel.js +184 -34
- package/src/tame-temporal-object.js +75 -0
- package/src/transforms.js +5 -5
- package/src-xs/commons.js +29 -0
- package/src-xs/compartment-shim.js +134 -0
- package/src-xs/compartment.js +318 -0
- package/src-xs/index.js +27 -0
- package/src-xs/lockdown-shim.js +29 -0
- package/types.d.ts +4 -0
package/dist/types.d.cts
CHANGED
|
@@ -132,6 +132,10 @@ export type ModuleDescriptor =
|
|
|
132
132
|
| PrecompiledModuleSource
|
|
133
133
|
| string;
|
|
134
134
|
|
|
135
|
+
export type StrictModuleDescriptor =
|
|
136
|
+
| SourceModuleDescriptor
|
|
137
|
+
| NamespaceModuleDescriptor;
|
|
138
|
+
|
|
135
139
|
// Deprecated type aliases:
|
|
136
140
|
export type PrecompiledStaticModuleInterface = PrecompiledModuleSource;
|
|
137
141
|
export type ThirdPartyStaticModuleInterface = VirtualModuleSource;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"supply-chain attack",
|
|
19
19
|
"plugin"
|
|
20
20
|
],
|
|
21
|
-
"author": "
|
|
21
|
+
"author": "Endo contributors",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"homepage": "https://github.com/Agoric/SES-shim/tree/master/packages/ses#readme",
|
|
24
24
|
"repository": {
|
|
@@ -75,47 +75,13 @@
|
|
|
75
75
|
"./console-shim.js": "./console-shim.js",
|
|
76
76
|
"./package.json": "./package.json"
|
|
77
77
|
},
|
|
78
|
-
"scripts": {
|
|
79
|
-
"build:vanilla": "node scripts/bundle.js",
|
|
80
|
-
"build:hermes": "node scripts/bundle.js hermes",
|
|
81
|
-
"build": "yarn build:vanilla && yarn build:hermes",
|
|
82
|
-
"clean": "rm -rf dist",
|
|
83
|
-
"cover": "c8 ava --config test/_ava-ses.config.js",
|
|
84
|
-
"demo": "python3 -m http.server",
|
|
85
|
-
"lint": "yarn lint:types && yarn lint:eslint",
|
|
86
|
-
"lint-fix": "eslint --fix .",
|
|
87
|
-
"lint:eslint": "eslint .",
|
|
88
|
-
"lint:types": "tsc",
|
|
89
|
-
"prepare": "npm run clean && npm run build",
|
|
90
|
-
"qt": "ava",
|
|
91
|
-
"test": "tsd && ava",
|
|
92
|
-
"test:hermes": "./scripts/hermes-test.sh",
|
|
93
|
-
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp",
|
|
94
|
-
"postpack": "git clean -fX -e node_modules/"
|
|
95
|
-
},
|
|
96
78
|
"dependencies": {
|
|
97
79
|
"@endo/cache-map": "^1.1.0",
|
|
98
80
|
"@endo/env-options": "^1.1.11",
|
|
99
81
|
"@endo/immutable-arraybuffer": "^1.1.2"
|
|
100
82
|
},
|
|
101
|
-
"devDependencies": {
|
|
102
|
-
"@babel/generator": "^7.28.3",
|
|
103
|
-
"@babel/parser": "~7.28.3",
|
|
104
|
-
"@babel/traverse": "~7.28.3",
|
|
105
|
-
"@babel/types": "~7.28.2",
|
|
106
|
-
"@endo/compartment-mapper": "^2.1.0",
|
|
107
|
-
"@endo/module-source": "^1.4.1",
|
|
108
|
-
"@endo/test262-runner": "^0.1.50",
|
|
109
|
-
"ava": "catalog:dev",
|
|
110
|
-
"c8": "catalog:dev",
|
|
111
|
-
"core-js": "^3.31.0",
|
|
112
|
-
"eslint": "catalog:dev",
|
|
113
|
-
"hermes-engine-cli": "^0.12.0",
|
|
114
|
-
"terser": "^5.16.6",
|
|
115
|
-
"tsd": "catalog:dev",
|
|
116
|
-
"typescript": "catalog:dev"
|
|
117
|
-
},
|
|
118
83
|
"files": [
|
|
84
|
+
"./*.d.js",
|
|
119
85
|
"./*.d.ts",
|
|
120
86
|
"./*.js",
|
|
121
87
|
"./*.map",
|
|
@@ -124,6 +90,7 @@
|
|
|
124
90
|
"dist",
|
|
125
91
|
"lib",
|
|
126
92
|
"src",
|
|
93
|
+
"src-xs",
|
|
127
94
|
"tools"
|
|
128
95
|
],
|
|
129
96
|
"publishConfig": {
|
|
@@ -142,6 +109,5 @@
|
|
|
142
109
|
},
|
|
143
110
|
"typeCoverage": {
|
|
144
111
|
"atLeast": 81.17
|
|
145
|
-
}
|
|
146
|
-
"gitHead": "c3616c39c35f2d052f7083aba31054910951beb4"
|
|
112
|
+
}
|
|
147
113
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TypeError } from './commons.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/** @this {unknown} */
|
|
4
|
+
// getThis returns globalThis in sloppy mode or undefined in strict mode.
|
|
4
5
|
function getThis() {
|
|
5
6
|
return this;
|
|
6
7
|
}
|
|
@@ -52,6 +52,7 @@ export const cauterizeProperty = (
|
|
|
52
52
|
try {
|
|
53
53
|
delete obj[prop];
|
|
54
54
|
} catch (err) {
|
|
55
|
+
const reason = /** @type {string | object} */ (err);
|
|
55
56
|
if (hasOwn(obj, prop)) {
|
|
56
57
|
if (typeof obj === 'function' && prop === 'prototype') {
|
|
57
58
|
obj.prototype = undefined;
|
|
@@ -60,9 +61,9 @@ export const cauterizeProperty = (
|
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
error(`failed to delete ${subPath}`,
|
|
64
|
+
error(`failed to delete ${subPath}`, reason);
|
|
64
65
|
} else {
|
|
65
|
-
error(`deleting ${subPath} threw`,
|
|
66
|
+
error(`deleting ${subPath} threw`, reason);
|
|
66
67
|
}
|
|
67
68
|
throw err;
|
|
68
69
|
}
|
package/src/commons.js
CHANGED
|
@@ -45,6 +45,7 @@ export const {
|
|
|
45
45
|
Uint8Array,
|
|
46
46
|
WeakMap,
|
|
47
47
|
WeakSet,
|
|
48
|
+
Temporal, // may be undefined on old JS engines
|
|
48
49
|
} = globalThis;
|
|
49
50
|
|
|
50
51
|
export const {
|
|
@@ -64,7 +65,6 @@ export const {
|
|
|
64
65
|
create,
|
|
65
66
|
defineProperties,
|
|
66
67
|
entries,
|
|
67
|
-
freeze,
|
|
68
68
|
getOwnPropertyDescriptor,
|
|
69
69
|
getOwnPropertyDescriptors,
|
|
70
70
|
getOwnPropertyNames,
|
|
@@ -82,18 +82,32 @@ export const {
|
|
|
82
82
|
fromEntries,
|
|
83
83
|
} = Object;
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* For use with any value except a regular expression (@see {@link sealRegexp}
|
|
87
|
+
* and {@link freezeRegexp}).
|
|
88
|
+
*
|
|
89
|
+
* @type { &
|
|
90
|
+
* ((obj: RegExp) => void) &
|
|
91
|
+
* typeof Object.freeze
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
export const freeze = /** @type {any} */ (Object.freeze);
|
|
95
|
+
|
|
85
96
|
export const {
|
|
86
97
|
species: speciesSymbol,
|
|
87
98
|
toStringTag: toStringTagSymbol,
|
|
88
99
|
iterator: iteratorSymbol,
|
|
89
100
|
matchAll: matchAllSymbol,
|
|
90
101
|
replace: replaceSymbol,
|
|
102
|
+
search: searchSymbol,
|
|
91
103
|
unscopables: unscopablesSymbol,
|
|
92
104
|
keyFor: symbolKeyFor,
|
|
93
105
|
for: symbolFor,
|
|
94
106
|
} = Symbol;
|
|
95
107
|
|
|
96
|
-
export const {
|
|
108
|
+
export const { max, min, trunc } = Math;
|
|
109
|
+
|
|
110
|
+
export const { MAX_SAFE_INTEGER, isInteger } = Number;
|
|
97
111
|
|
|
98
112
|
export const { stringify: stringifyJson } = JSON;
|
|
99
113
|
|
|
@@ -135,6 +149,7 @@ export const {
|
|
|
135
149
|
|
|
136
150
|
export const { isArray, prototype: arrayPrototype } = Array;
|
|
137
151
|
export const { prototype: arrayBufferPrototype } = ArrayBuffer;
|
|
152
|
+
export const { prototype: dataViewPrototype } = DataView;
|
|
138
153
|
export const { prototype: mapPrototype } = Map;
|
|
139
154
|
export const { revocable: proxyRevocable } = Proxy;
|
|
140
155
|
export const { prototype: regexpPrototype } = RegExp;
|
|
@@ -236,6 +251,7 @@ export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
|
|
|
236
251
|
* vulnerable to RegExp.prototype poisoning.
|
|
237
252
|
*/
|
|
238
253
|
export const regexpExec = uncurryThis(regexpPrototype.exec);
|
|
254
|
+
|
|
239
255
|
/**
|
|
240
256
|
* @type { &
|
|
241
257
|
* ((thisArg: RegExp, string: string, replaceValue: string) => string) &
|
|
@@ -245,21 +261,57 @@ export const regexpExec = uncurryThis(regexpPrototype.exec);
|
|
|
245
261
|
export const regexpReplace = /** @type {any} */ (
|
|
246
262
|
uncurryThis(regexpPrototype[replaceSymbol])
|
|
247
263
|
);
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* `regexpSearch` can be used with a frozen non-global non-sticky RegExp.
|
|
267
|
+
*
|
|
268
|
+
* @type {(thisArg: RegExp, string: string) => number}
|
|
269
|
+
*/
|
|
270
|
+
export const regexpSearch = uncurryThis(regexpPrototype[searchSymbol]);
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* `matchAll` internally creates a new RegExp vulnerable to prototype poisoning,
|
|
274
|
+
* but this function is still needed to reach %RegExpStringIteratorPrototype%.
|
|
275
|
+
* @private
|
|
276
|
+
*/
|
|
248
277
|
export const matchAllRegExp = uncurryThis(regexpPrototype[matchAllSymbol]);
|
|
249
|
-
|
|
250
|
-
|
|
278
|
+
|
|
279
|
+
const regexpDescriptors = getOwnPropertyDescriptors(regexpPrototype);
|
|
251
280
|
arrayForEach(ownKeys(regexpDescriptors), key => {
|
|
252
281
|
const desc = regexpDescriptors[/** @type {any} */ (key)];
|
|
253
282
|
desc.configurable = false;
|
|
254
283
|
if (desc.writable) desc.writable = false;
|
|
255
284
|
});
|
|
285
|
+
// Don't follow Symbol.species
|
|
286
|
+
// https://tc39.es/ecma262/multipage/abstract-operations.html#sec-speciesconstructor
|
|
287
|
+
defineProperty(regexpDescriptors, 'constructor', {
|
|
288
|
+
value: undefined,
|
|
289
|
+
enumerable: false,
|
|
290
|
+
configurable: false,
|
|
291
|
+
writable: false,
|
|
292
|
+
});
|
|
293
|
+
|
|
256
294
|
/**
|
|
257
295
|
* Protect a RegExp instance against RegExp.prototype poisoning ("exec",
|
|
258
|
-
* "flags", Symbol.replace, etc.)
|
|
296
|
+
* "flags", Symbol.replace, etc.) while still maintaining mutability of its
|
|
297
|
+
* "lastIndex" property (which is necessary with flags "g" and/or "y" for some
|
|
298
|
+
* operations, most notably {@link regexpReplace}).
|
|
299
|
+
*
|
|
259
300
|
* @type {<T extends RegExp>(regexp: T) => T}
|
|
260
301
|
*/
|
|
261
302
|
export const sealRegexp = regexp =>
|
|
262
303
|
seal(defineProperties(regexp, regexpDescriptors));
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Protect a RegExp instance against RegExp.prototype poisoning ("exec",
|
|
307
|
+
* "flags", Symbol.replace, etc.) and freeze its "lastIndex" property, rendering
|
|
308
|
+
* it fully inert but (absent flags "g" and/or "y") still usable by
|
|
309
|
+
* {@link regexpExec} and {@link regexpSearch}.
|
|
310
|
+
*
|
|
311
|
+
* @type {<T extends RegExp>(regexp: T) => T}
|
|
312
|
+
*/
|
|
313
|
+
export const freezeRegexp = regexp =>
|
|
314
|
+
freeze(/** @type {any} */ (defineProperties(regexp, regexpDescriptors)));
|
|
263
315
|
//
|
|
264
316
|
export const stringEndsWith = uncurryThis(stringPrototype.endsWith);
|
|
265
317
|
export const stringIncludes = uncurryThis(stringPrototype.includes);
|
|
@@ -386,7 +438,7 @@ const makeTypeError = () => {
|
|
|
386
438
|
null.null;
|
|
387
439
|
throw TypeError('obligatory'); // To convince the type flow inferrence.
|
|
388
440
|
} catch (error) {
|
|
389
|
-
return error;
|
|
441
|
+
return /** @type {TypeError} */ (error);
|
|
390
442
|
}
|
|
391
443
|
};
|
|
392
444
|
|
|
@@ -459,9 +511,10 @@ const getAsyncGeneratorFunctionInstance = () => {
|
|
|
459
511
|
'return (async function* AsyncGeneratorFunctionInstance() {})',
|
|
460
512
|
)();
|
|
461
513
|
} catch (error) {
|
|
514
|
+
const err = /** @type {Error} */ (error);
|
|
462
515
|
// Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
|
|
463
516
|
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
|
|
464
|
-
if (
|
|
517
|
+
if (err.name === 'SyntaxError') {
|
|
465
518
|
// Swallows Hermes error `async generators are unsupported` at runtime.
|
|
466
519
|
// Note: `console` is not a JS built-in, so Hermes engine throws:
|
|
467
520
|
// Uncaught ReferenceError: Property 'console' doesn't exist
|
|
@@ -469,11 +522,11 @@ const getAsyncGeneratorFunctionInstance = () => {
|
|
|
469
522
|
// However React Native provides a `console` implementation when setting up error handling:
|
|
470
523
|
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
|
|
471
524
|
return undefined;
|
|
472
|
-
} else if (
|
|
525
|
+
} else if (err.name === 'EvalError') {
|
|
473
526
|
// eslint-disable-next-line no-empty-function
|
|
474
527
|
return async function* AsyncGeneratorFunctionInstance() {};
|
|
475
528
|
} else {
|
|
476
|
-
throw
|
|
529
|
+
throw err;
|
|
477
530
|
}
|
|
478
531
|
}
|
|
479
532
|
};
|
package/src/compartment.js
CHANGED
|
@@ -335,7 +335,7 @@ export const makeCompartmentConstructor = (
|
|
|
335
335
|
{ parentCompartment = undefined, enforceNew = false } = {},
|
|
336
336
|
) => {
|
|
337
337
|
/**
|
|
338
|
-
*
|
|
338
|
+
* @this {Compartment}
|
|
339
339
|
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
340
340
|
*/
|
|
341
341
|
function Compartment(...args) {
|
|
@@ -359,7 +359,9 @@ export const makeCompartmentConstructor = (
|
|
|
359
359
|
importMetaHook,
|
|
360
360
|
__noNamespaceBox__: noNamespaceBox = false,
|
|
361
361
|
noAggregateLoadErrors = false,
|
|
362
|
-
} = compartmentOptions(
|
|
362
|
+
} = compartmentOptions(
|
|
363
|
+
.../** @type {Parameters<typeof compartmentOptions>} */ (args),
|
|
364
|
+
);
|
|
363
365
|
const globalTransforms = arrayFlatMap(
|
|
364
366
|
[transforms, __shimTransforms__],
|
|
365
367
|
identity,
|
|
@@ -376,7 +378,7 @@ export const makeCompartmentConstructor = (
|
|
|
376
378
|
|
|
377
379
|
const globalObject = {};
|
|
378
380
|
|
|
379
|
-
const compartment = this;
|
|
381
|
+
const compartment = /** @type {Compartment} */ (this);
|
|
380
382
|
|
|
381
383
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
382
384
|
|
|
@@ -397,7 +399,7 @@ export const makeCompartmentConstructor = (
|
|
|
397
399
|
intrinsics,
|
|
398
400
|
newGlobalPropertyNames: sharedGlobalPropertyNames,
|
|
399
401
|
makeCompartmentConstructor: targetMakeCompartmentConstructor,
|
|
400
|
-
parentCompartment:
|
|
402
|
+
parentCompartment: compartment,
|
|
401
403
|
markVirtualizedNativeFunction,
|
|
402
404
|
});
|
|
403
405
|
|
|
@@ -449,7 +451,7 @@ export const makeCompartmentConstructor = (
|
|
|
449
451
|
return exportsProxy;
|
|
450
452
|
};
|
|
451
453
|
|
|
452
|
-
weakmapSet(privateFields,
|
|
454
|
+
weakmapSet(privateFields, compartment, {
|
|
453
455
|
name: `${name}`,
|
|
454
456
|
globalTransforms,
|
|
455
457
|
globalObject,
|
package/src/error/assert.js
CHANGED
|
@@ -22,12 +22,12 @@ import {
|
|
|
22
22
|
assign,
|
|
23
23
|
freeze,
|
|
24
24
|
defineProperty,
|
|
25
|
+
freezeRegexp,
|
|
25
26
|
globalThis,
|
|
26
27
|
is,
|
|
27
28
|
isError,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
sealRegexp,
|
|
29
|
+
regexpSearch,
|
|
30
|
+
stringEndsWith,
|
|
31
31
|
stringIndexOf,
|
|
32
32
|
stringSlice,
|
|
33
33
|
stringStartsWith,
|
|
@@ -74,13 +74,13 @@ const quote = (value, spaces = undefined) => {
|
|
|
74
74
|
};
|
|
75
75
|
freeze(quote);
|
|
76
76
|
|
|
77
|
-
const canBeBare =
|
|
77
|
+
const canBeBare = freezeRegexp(/^[\w:-]( ?[\w:-])*$/);
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @type {AssertionUtilities['bare']}
|
|
81
81
|
*/
|
|
82
82
|
const bare = (text, spaces = undefined) => {
|
|
83
|
-
if (typeof text !== 'string' ||
|
|
83
|
+
if (typeof text !== 'string' || regexpSearch(canBeBare, text) === -1) {
|
|
84
84
|
return quote(text, spaces);
|
|
85
85
|
}
|
|
86
86
|
const result = freeze({
|
|
@@ -201,9 +201,6 @@ const unredactedDetails = (template, ...args) => {
|
|
|
201
201
|
freeze(unredactedDetails);
|
|
202
202
|
export { unredactedDetails };
|
|
203
203
|
|
|
204
|
-
const leadingSpacePattern = sealRegexp(/^ /);
|
|
205
|
-
const trailingSpacePattern = sealRegexp(/ $/);
|
|
206
|
-
|
|
207
204
|
/**
|
|
208
205
|
* Get arguments suitable for a console logger function (e.g., `console.error`)
|
|
209
206
|
* from `details` template literal contents, unquoting quoted substitution
|
|
@@ -221,20 +218,18 @@ const getLogArgs = ({ template, args }) => {
|
|
|
221
218
|
}
|
|
222
219
|
// Remove substitution-adjacent spaces from template fixed-string parts
|
|
223
220
|
// (since console logging inserts its own argument-separating spaces).
|
|
224
|
-
const prevLiteralPart =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
arrayPush(logArgs, prevLiteralPart);
|
|
221
|
+
const prevLiteralPart = arrayPop(logArgs) || '';
|
|
222
|
+
const trimmedPrev = stringEndsWith(prevLiteralPart, ' ')
|
|
223
|
+
? stringSlice(prevLiteralPart, 0, -1)
|
|
224
|
+
: prevLiteralPart;
|
|
225
|
+
if (trimmedPrev !== '') {
|
|
226
|
+
arrayPush(logArgs, trimmedPrev);
|
|
231
227
|
}
|
|
232
|
-
const nextLiteralPart =
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
);
|
|
237
|
-
arrayPush(logArgs, arg, nextLiteralPart);
|
|
228
|
+
const nextLiteralPart = template[i + 1];
|
|
229
|
+
const trimmedNext = stringStartsWith(nextLiteralPart, ' ')
|
|
230
|
+
? stringSlice(nextLiteralPart, 1)
|
|
231
|
+
: nextLiteralPart;
|
|
232
|
+
arrayPush(logArgs, arg, trimmedNext);
|
|
238
233
|
}
|
|
239
234
|
if (logArgs[logArgs.length - 1] === '') {
|
|
240
235
|
arrayPop(logArgs);
|
|
@@ -42,10 +42,16 @@ export default function tameErrorConstructor(
|
|
|
42
42
|
typeof originalCaptureStackTrace === 'function' ? 'v8' : 'unknown';
|
|
43
43
|
|
|
44
44
|
const makeErrorConstructor = (_ = {}) => {
|
|
45
|
+
/**
|
|
46
|
+
* @this {ErrorConstructor}
|
|
47
|
+
* @param {...any} rest
|
|
48
|
+
*/
|
|
45
49
|
// eslint-disable-next-line no-shadow
|
|
46
50
|
const ResultError = function Error(...rest) {
|
|
47
51
|
let error;
|
|
48
52
|
if (new.target === undefined) {
|
|
53
|
+
// Forward caller's `this` to FERAL_ERROR to keep the shim transparent.
|
|
54
|
+
// Error() as a function ignores `this` per spec, but do not narrow it.
|
|
49
55
|
error = apply(FERAL_ERROR, this, rest);
|
|
50
56
|
} else {
|
|
51
57
|
error = construct(FERAL_ERROR, rest, new.target);
|
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
arraySlice,
|
|
9
9
|
create,
|
|
10
10
|
defineProperties,
|
|
11
|
+
freezeRegexp,
|
|
11
12
|
fromEntries,
|
|
12
13
|
reflectSet,
|
|
13
14
|
regexpExec,
|
|
15
|
+
regexpSearch,
|
|
14
16
|
weakmapGet,
|
|
15
17
|
weakmapSet,
|
|
16
18
|
weaksetAdd,
|
|
@@ -63,27 +65,33 @@ const safeV8SST = sst => arrayMap(sst, safeV8CallSiteFacet);
|
|
|
63
65
|
// If it has `/node_modules/` anywhere in it, on Node it is likely
|
|
64
66
|
// to be a dependent package of the current package, and so to
|
|
65
67
|
// be an infrastructure frame to be dropped from concise stack traces.
|
|
66
|
-
const FILENAME_NODE_DEPENDENTS_CENSOR = /\/node_modules
|
|
68
|
+
const FILENAME_NODE_DEPENDENTS_CENSOR = freezeRegexp(/\/node_modules\//);
|
|
67
69
|
|
|
68
70
|
// If it begins with `internal/` or `node:internal` then it is likely
|
|
69
71
|
// part of the node infrustructre itself, to be dropped from concise
|
|
70
72
|
// stack traces.
|
|
71
|
-
const FILENAME_NODE_INTERNALS_CENSOR = /^(?:node:)?internal
|
|
73
|
+
const FILENAME_NODE_INTERNALS_CENSOR = freezeRegexp(/^(?:node:)?internal\//);
|
|
72
74
|
|
|
73
75
|
// Frames within SES `assert.js` should be dropped from concise stack traces, as
|
|
74
76
|
// these are just steps towards creating the error object in question.
|
|
75
|
-
const FILENAME_ASSERT_CENSOR =
|
|
77
|
+
const FILENAME_ASSERT_CENSOR = freezeRegexp(
|
|
78
|
+
/\/packages\/ses\/src\/error\/assert\.js$/,
|
|
79
|
+
);
|
|
76
80
|
|
|
77
81
|
// Frames within the `eventual-send` shim should be dropped so that concise
|
|
78
82
|
// deep stacks omit the internals of the eventual-sending mechanism causing
|
|
79
83
|
// asynchronous messages to be sent.
|
|
80
84
|
// Note that the eventual-send package will move from agoric-sdk to
|
|
81
85
|
// Endo, so this rule will be of general interest.
|
|
82
|
-
const FILENAME_EVENTUAL_SEND_CENSOR =
|
|
86
|
+
const FILENAME_EVENTUAL_SEND_CENSOR = freezeRegexp(
|
|
87
|
+
/\/packages\/eventual-send\/src\//,
|
|
88
|
+
);
|
|
83
89
|
|
|
84
90
|
// Frames within the `ses-ava` package should be dropped from concise stack
|
|
85
91
|
// traces, as they just support exposing error details to AVA.
|
|
86
|
-
const FILENAME_SES_AVA_CENSOR =
|
|
92
|
+
const FILENAME_SES_AVA_CENSOR = freezeRegexp(
|
|
93
|
+
/\/packages\/ses-ava\/src\/ses-ava-test\.js$/,
|
|
94
|
+
);
|
|
87
95
|
|
|
88
96
|
// Any stack frame whose `fileName` matches any of these censor patterns
|
|
89
97
|
// will be omitted from concise stacks.
|
|
@@ -106,7 +114,7 @@ export const filterFileName = fileName => {
|
|
|
106
114
|
return false;
|
|
107
115
|
}
|
|
108
116
|
for (const filter of FILENAME_CENSORS) {
|
|
109
|
-
if (
|
|
117
|
+
if (regexpSearch(filter, fileName) !== -1) {
|
|
110
118
|
return false;
|
|
111
119
|
}
|
|
112
120
|
}
|
|
@@ -123,7 +131,9 @@ export const filterFileName = fileName => {
|
|
|
123
131
|
//
|
|
124
132
|
// See thread starting at
|
|
125
133
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
126
|
-
const CALLSITE_ELLIPSIS_PATTERN1 =
|
|
134
|
+
const CALLSITE_ELLIPSIS_PATTERN1 = freezeRegexp(
|
|
135
|
+
/^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/,
|
|
136
|
+
);
|
|
127
137
|
|
|
128
138
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
129
139
|
// likely url-path prefix consisting of `.../` should get dropped.
|
|
@@ -135,7 +145,7 @@ const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
|
|
|
135
145
|
//
|
|
136
146
|
// See thread starting at
|
|
137
147
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
138
|
-
const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)
|
|
148
|
+
const CALLSITE_ELLIPSIS_PATTERN2 = freezeRegexp(/^((?:.*[( ])?)\.\.\.\/(.+)$/);
|
|
139
149
|
|
|
140
150
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
141
151
|
// likely url-path prefix, ending in a `/` and prior to `package/` should get
|
|
@@ -147,7 +157,9 @@ const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
|
|
|
147
157
|
// `'Object.bar (packages/errors/test/deep-send.test.js:13:21)'`.
|
|
148
158
|
// Note that `/packages/` is a convention for monorepos encouraged by
|
|
149
159
|
// lerna.
|
|
150
|
-
const CALLSITE_PACKAGES_PATTERN =
|
|
160
|
+
const CALLSITE_PACKAGES_PATTERN = freezeRegexp(
|
|
161
|
+
/^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/,
|
|
162
|
+
);
|
|
151
163
|
|
|
152
164
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
153
165
|
// likely url-path prefix of the form `file://` but not `file:///` gets
|
|
@@ -163,7 +175,9 @@ const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
|
|
|
163
175
|
// clickable without removing the `file:///`, whereas `file://` usually precedes
|
|
164
176
|
// a relative path which, for whatever vscode reason, is not clickable until the
|
|
165
177
|
// `file://` is removed.
|
|
166
|
-
const CALLSITE_FILE_2SLASH_PATTERN =
|
|
178
|
+
const CALLSITE_FILE_2SLASH_PATTERN = freezeRegexp(
|
|
179
|
+
/^((?:.*[( ])?)file:\/\/([^/].*)$/,
|
|
180
|
+
);
|
|
167
181
|
|
|
168
182
|
// The use of these callSite patterns below assumes that any match will bind
|
|
169
183
|
// capture groups containing the parts of the original string we want
|
|
@@ -60,7 +60,7 @@ export const getAnonymousIntrinsics = () => {
|
|
|
60
60
|
|
|
61
61
|
// 21.2.7.1 The %RegExpStringIteratorPrototype% Object
|
|
62
62
|
const RegExpStringIterator =
|
|
63
|
-
regexpPrototype[matchAllSymbol] && matchAllRegExp(
|
|
63
|
+
regexpPrototype[matchAllSymbol] && matchAllRegExp(/./, '');
|
|
64
64
|
const RegExpStringIteratorPrototype =
|
|
65
65
|
RegExpStringIterator && getPrototypeOf(RegExpStringIterator);
|
|
66
66
|
|
package/src/get-source-url.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FERAL_REG_EXP,
|
|
3
|
+
freezeRegexp,
|
|
4
|
+
regexpExec,
|
|
5
|
+
stringSlice,
|
|
6
|
+
} from './commons.js';
|
|
2
7
|
|
|
3
8
|
// Captures a key and value of the form #key=value or @key=value
|
|
4
9
|
const sourceMetaEntryRegExp =
|
|
@@ -9,8 +14,10 @@ const sourceMetaEntryRegExp =
|
|
|
9
14
|
// On account of the mechanics of regular expressions, scanning from the end
|
|
10
15
|
// does not allow us to capture every pair, so getSourceURL must capture and
|
|
11
16
|
// trim until there are no matching comments.
|
|
12
|
-
const sourceMetaEntriesRegExp =
|
|
13
|
-
|
|
17
|
+
const sourceMetaEntriesRegExp = freezeRegexp(
|
|
18
|
+
new FERAL_REG_EXP(
|
|
19
|
+
`(?:\\s*//${sourceMetaEntryRegExp}|/\\*${sourceMetaEntryRegExp}\\s*\\*/)\\s*$`,
|
|
20
|
+
),
|
|
14
21
|
);
|
|
15
22
|
|
|
16
23
|
/**
|
|
@@ -31,7 +38,7 @@ export const getSourceURL = src => {
|
|
|
31
38
|
if (match === null) {
|
|
32
39
|
break;
|
|
33
40
|
}
|
|
34
|
-
src = stringSlice(src, 0,
|
|
41
|
+
src = stringSlice(src, 0, -match[0].length);
|
|
35
42
|
|
|
36
43
|
// We skip $0 since it contains the entire match.
|
|
37
44
|
// The match contains four capture groups,
|
package/src/lockdown.js
CHANGED
|
@@ -36,6 +36,7 @@ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
|
|
|
36
36
|
import tameFunctionConstructors from './tame-function-constructors.js';
|
|
37
37
|
import tameDateConstructor from './tame-date-constructor.js';
|
|
38
38
|
import tameMathObject from './tame-math-object.js';
|
|
39
|
+
import tameTemporalObject from './tame-temporal-object.js';
|
|
39
40
|
import { tameNaNSideChannel } from './tame-nan-sidechannel.js';
|
|
40
41
|
import tameRegExpConstructor from './tame-regexp-constructor.js';
|
|
41
42
|
import enablePropertyOverrides from './enable-property-overrides.js';
|
|
@@ -354,6 +355,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
354
355
|
addIntrinsics(tameDateConstructor());
|
|
355
356
|
addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
|
|
356
357
|
addIntrinsics(tameMathObject());
|
|
358
|
+
addIntrinsics(tameTemporalObject());
|
|
357
359
|
tameNaNSideChannel();
|
|
358
360
|
addIntrinsics(tameRegExpConstructor(regExpTaming));
|
|
359
361
|
addIntrinsics(tameSymbolConstructor());
|
|
@@ -178,34 +178,26 @@ export default function removeUnpermittedIntrinsics(
|
|
|
178
178
|
if (typeof permit === 'string') {
|
|
179
179
|
// A string permit can have one of two meanings:
|
|
180
180
|
|
|
181
|
-
if (
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
// Assert: the property value is equal to that intrinsic.
|
|
187
|
-
|
|
188
|
-
if (hasOwn(intrinsics, permit)) {
|
|
189
|
-
if (value !== intrinsics[permit]) {
|
|
190
|
-
throw TypeError(`Does not match permit for ${path}`);
|
|
191
|
-
}
|
|
192
|
-
return true;
|
|
181
|
+
if (arrayIncludes(primitives, permit)) {
|
|
182
|
+
// The permit is the name of a primitive.
|
|
183
|
+
|
|
184
|
+
if (prop === 'prototype' || prop === 'constructor') {
|
|
185
|
+
throw new TypeError(`At ${path} expected intrinsic, not ${permit}`);
|
|
193
186
|
}
|
|
194
|
-
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
return true;
|
|
187
|
+
// eslint wants to compare typeof only to string literals
|
|
188
|
+
// eslint-disable-next-line valid-typeof
|
|
189
|
+
if (typeof value !== permit) {
|
|
190
|
+
throw TypeError(`At ${path} expected ${permit} not ${typeof value}`);
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (hasOwn(intrinsics, permit)) {
|
|
196
|
+
// the permit is the name of an intrinsic.
|
|
197
|
+
if (value !== intrinsics[permit]) {
|
|
198
|
+
throw TypeError(`Does not match permit for ${path}`);
|
|
208
199
|
}
|
|
200
|
+
return true;
|
|
209
201
|
}
|
|
210
202
|
}
|
|
211
203
|
|