ses 0.18.4 → 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 +12 -0
- package/README.md +105 -47
- package/dist/lockdown.cjs +7697 -7455
- package/dist/lockdown.mjs +7697 -7455
- package/dist/lockdown.umd.js +7697 -7455
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +7697 -7455
- package/dist/ses.mjs +7697 -7455
- package/dist/ses.umd.js +7697 -7455
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -1
- package/package.json +17 -13
- package/src/commons.js +2 -3
- package/src/compartment-evaluate.js +1 -1
- package/src/compartment-shim.js +9 -9
- 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/types.js +1 -0
- package/src/get-anonymous-intrinsics.js +23 -0
- package/src/global-object.js +2 -2
- package/src/intrinsics.js +10 -10
- package/src/lockdown-shim.js +13 -26
- package/src/make-hardener.js +1 -1
- package/src/module-instance.js +5 -9
- package/src/module-link.js +2 -2
- package/src/module-load.js +4 -6
- package/src/module-proxy.js +12 -12
- package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +22 -21
- package/src/{whitelist.js → permits.js} +135 -8
- 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-harden.js +1 -1
- package/src/tame-locale-methods.js +2 -2
- package/src/tame-math-object.js +1 -1
- package/src/tame-regexp-constructor.js +2 -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/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function getThis() {
|
|
|
27
27
|
|
|
28
28
|
if (getThis()) {
|
|
29
29
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_SLOPPY.md
|
|
30
|
-
throw
|
|
30
|
+
throw TypeError(`SES failed to initialize, sloppy mode (SES_NO_SLOPPY)`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const markVirtualizedNativeFunction = tameFunctionToString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -59,23 +59,27 @@
|
|
|
59
59
|
"test": "tsd && ava",
|
|
60
60
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
61
61
|
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@endo/env-options": "^0.1.1"
|
|
64
|
+
},
|
|
62
65
|
"devDependencies": {
|
|
63
|
-
"@endo/compartment-mapper": "^0.8.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
66
|
-
"ava": "^5.
|
|
66
|
+
"@endo/compartment-mapper": "^0.8.5",
|
|
67
|
+
"@endo/static-module-record": "^0.7.20",
|
|
68
|
+
"@endo/test262-runner": "^0.1.32",
|
|
69
|
+
"ava": "^5.3.0",
|
|
67
70
|
"babel-eslint": "^10.0.3",
|
|
68
|
-
"c8": "^7.
|
|
69
|
-
"
|
|
70
|
-
"eslint
|
|
71
|
+
"c8": "^7.14.0",
|
|
72
|
+
"core-js": "^3.31.0",
|
|
73
|
+
"eslint": "^8.44.0",
|
|
74
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
71
75
|
"eslint-config-prettier": "^8.8.0",
|
|
72
76
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
73
77
|
"eslint-plugin-import": "^2.27.5",
|
|
74
|
-
"prettier": "^
|
|
75
|
-
"sinon": "
|
|
78
|
+
"prettier": "^3.0.0",
|
|
79
|
+
"sinon": "^15.1.0",
|
|
76
80
|
"terser": "^5.16.6",
|
|
77
|
-
"tsd": "^0.
|
|
78
|
-
"typescript": "~
|
|
81
|
+
"tsd": "^0.28.1",
|
|
82
|
+
"typescript": "~5.1.3"
|
|
79
83
|
},
|
|
80
84
|
"files": [
|
|
81
85
|
"LICENSE*",
|
|
@@ -175,5 +179,5 @@
|
|
|
175
179
|
],
|
|
176
180
|
"timeout": "2m"
|
|
177
181
|
},
|
|
178
|
-
"gitHead": "
|
|
182
|
+
"gitHead": "106da55b8bcea3067f70c29c357806f3f2e55c52"
|
|
179
183
|
}
|
package/src/commons.js
CHANGED
|
@@ -33,6 +33,7 @@ export const {
|
|
|
33
33
|
RegExp: FERAL_REG_EXP,
|
|
34
34
|
Set,
|
|
35
35
|
String,
|
|
36
|
+
Symbol,
|
|
36
37
|
WeakMap,
|
|
37
38
|
WeakSet,
|
|
38
39
|
} = globalThis;
|
|
@@ -287,7 +288,5 @@ export const FERAL_FUNCTION = Function;
|
|
|
287
288
|
|
|
288
289
|
export const noEvalEvaluate = () => {
|
|
289
290
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
290
|
-
throw
|
|
291
|
-
'Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)',
|
|
292
|
-
);
|
|
291
|
+
throw TypeError('Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
|
|
293
292
|
};
|
|
@@ -61,7 +61,7 @@ export const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
|
61
61
|
// TODO Maybe relax string check and coerce instead:
|
|
62
62
|
// https://github.com/tc39/proposal-dynamic-code-brand-checks
|
|
63
63
|
if (typeof source !== 'string') {
|
|
64
|
-
throw
|
|
64
|
+
throw TypeError('first argument of evaluate() must be a string');
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Extract options, and shallow-clone transforms.
|
package/src/compartment-shim.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
setGlobalObjectMutableProperties,
|
|
21
21
|
setGlobalObjectEvaluators,
|
|
22
22
|
} from './global-object.js';
|
|
23
|
-
import { sharedGlobalPropertyNames } from './
|
|
23
|
+
import { sharedGlobalPropertyNames } from './permits.js';
|
|
24
24
|
import { load } from './module-load.js';
|
|
25
25
|
import { link } from './module-link.js';
|
|
26
26
|
import { getDeferredExports } from './module-proxy.js';
|
|
@@ -48,7 +48,7 @@ const privateFields = new WeakMap();
|
|
|
48
48
|
const assertModuleHooks = compartment => {
|
|
49
49
|
const { importHook, resolveHook } = weakmapGet(privateFields, compartment);
|
|
50
50
|
if (typeof importHook !== 'function' || typeof resolveHook !== 'function') {
|
|
51
|
-
throw
|
|
51
|
+
throw TypeError(
|
|
52
52
|
'Compartment must be constructed with an importHook and a resolveHook for it to be able to load modules',
|
|
53
53
|
);
|
|
54
54
|
}
|
|
@@ -59,7 +59,7 @@ export const InertCompartment = function Compartment(
|
|
|
59
59
|
_modules = {},
|
|
60
60
|
_options = {},
|
|
61
61
|
) {
|
|
62
|
-
throw
|
|
62
|
+
throw TypeError(
|
|
63
63
|
'Compartment.prototype.constructor is not a valid constructor.',
|
|
64
64
|
);
|
|
65
65
|
};
|
|
@@ -111,7 +111,7 @@ export const CompartmentPrototype = {
|
|
|
111
111
|
|
|
112
112
|
module(specifier) {
|
|
113
113
|
if (typeof specifier !== 'string') {
|
|
114
|
-
throw
|
|
114
|
+
throw TypeError('first argument of module() must be a string');
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
assertModuleHooks(this);
|
|
@@ -128,7 +128,7 @@ export const CompartmentPrototype = {
|
|
|
128
128
|
|
|
129
129
|
async import(specifier) {
|
|
130
130
|
if (typeof specifier !== 'string') {
|
|
131
|
-
throw
|
|
131
|
+
throw TypeError('first argument of import() must be a string');
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
assertModuleHooks(this);
|
|
@@ -149,7 +149,7 @@ export const CompartmentPrototype = {
|
|
|
149
149
|
|
|
150
150
|
async load(specifier) {
|
|
151
151
|
if (typeof specifier !== 'string') {
|
|
152
|
-
throw
|
|
152
|
+
throw TypeError('first argument of load() must be a string');
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
assertModuleHooks(this);
|
|
@@ -159,7 +159,7 @@ export const CompartmentPrototype = {
|
|
|
159
159
|
|
|
160
160
|
importNow(specifier) {
|
|
161
161
|
if (typeof specifier !== 'string') {
|
|
162
|
-
throw
|
|
162
|
+
throw TypeError('first argument of importNow() must be a string');
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
assertModuleHooks(this);
|
|
@@ -188,7 +188,7 @@ export const makeCompartmentConstructor = (
|
|
|
188
188
|
) => {
|
|
189
189
|
function Compartment(endowments = {}, moduleMap = {}, options = {}) {
|
|
190
190
|
if (new.target === undefined) {
|
|
191
|
-
throw
|
|
191
|
+
throw TypeError(
|
|
192
192
|
"Class constructor Compartment cannot be invoked without 'new'",
|
|
193
193
|
);
|
|
194
194
|
}
|
|
@@ -220,7 +220,7 @@ export const makeCompartmentConstructor = (
|
|
|
220
220
|
for (const [specifier, aliasNamespace] of entries(moduleMap || {})) {
|
|
221
221
|
if (typeof aliasNamespace === 'string') {
|
|
222
222
|
// TODO implement parent module record retrieval.
|
|
223
|
-
throw
|
|
223
|
+
throw TypeError(
|
|
224
224
|
`Cannot map module ${q(specifier)} to ${q(
|
|
225
225
|
aliasNamespace,
|
|
226
226
|
)} in parent compartment`,
|
|
@@ -102,7 +102,7 @@ export default function enablePropertyOverrides(
|
|
|
102
102
|
|
|
103
103
|
function setter(newValue) {
|
|
104
104
|
if (obj === this) {
|
|
105
|
-
throw
|
|
105
|
+
throw TypeError(
|
|
106
106
|
`Cannot assign to read only property '${String(
|
|
107
107
|
prop,
|
|
108
108
|
)}' of '${path}'`,
|
|
@@ -113,7 +113,7 @@ export default function enablePropertyOverrides(
|
|
|
113
113
|
} else {
|
|
114
114
|
if (isDebug) {
|
|
115
115
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
116
|
-
console.error(
|
|
116
|
+
console.error(TypeError(`Override property ${prop}`));
|
|
117
117
|
}
|
|
118
118
|
defineProperty(this, prop, {
|
|
119
119
|
value: newValue,
|
|
@@ -175,7 +175,7 @@ export default function enablePropertyOverrides(
|
|
|
175
175
|
} else if (isObject(subPlan)) {
|
|
176
176
|
enableProperties(subPath, desc.value, subPlan);
|
|
177
177
|
} else {
|
|
178
|
-
throw
|
|
178
|
+
throw TypeError(`Unexpected override enablement plan ${subPath}`);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -195,7 +195,7 @@ export default function enablePropertyOverrides(
|
|
|
195
195
|
break;
|
|
196
196
|
}
|
|
197
197
|
default: {
|
|
198
|
-
throw
|
|
198
|
+
throw TypeError(`unrecognized overrideTaming ${overrideTaming}`);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
package/src/error/assert.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
globalThis,
|
|
25
25
|
is,
|
|
26
26
|
isError,
|
|
27
|
+
regexpTest,
|
|
27
28
|
stringIndexOf,
|
|
28
29
|
stringReplace,
|
|
29
30
|
stringSlice,
|
|
@@ -56,6 +57,35 @@ const quote = (payload, spaces = undefined) => {
|
|
|
56
57
|
};
|
|
57
58
|
freeze(quote);
|
|
58
59
|
|
|
60
|
+
const canBeBare = freeze(/^[\w:-]( ?[\w:-])*$/);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Embed a string directly into error details without wrapping punctuation.
|
|
64
|
+
* To avoid injection attacks that exploit quoting confusion, this must NEVER
|
|
65
|
+
* be used with data that is possibly attacker-controlled.
|
|
66
|
+
* As a further safeguard, we fall back to quoting any input that is not a
|
|
67
|
+
* string of sufficiently word-like parts separated by isolated spaces (rather
|
|
68
|
+
* than throwing an exception, which could hide the original problem for which
|
|
69
|
+
* explanatory details are being constructed---i.e., ``` assert.details`...` ```
|
|
70
|
+
* should never be the source of a new exception, nor should an attempt to
|
|
71
|
+
* render its output, although we _could_ instead decide to handle the latter
|
|
72
|
+
* by inline replacement similar to that of `bestEffortStringify` for producing
|
|
73
|
+
* rendered messages like `(an object) was tagged "[Unsafe bare string]"`).
|
|
74
|
+
*
|
|
75
|
+
* @type {AssertQuote}
|
|
76
|
+
*/
|
|
77
|
+
const bare = (payload, spaces = undefined) => {
|
|
78
|
+
if (typeof payload !== 'string' || !regexpTest(canBeBare, payload)) {
|
|
79
|
+
return quote(payload, spaces);
|
|
80
|
+
}
|
|
81
|
+
const result = freeze({
|
|
82
|
+
toString: freeze(() => payload),
|
|
83
|
+
});
|
|
84
|
+
weakmapSet(declassifiers, result, payload);
|
|
85
|
+
return result;
|
|
86
|
+
};
|
|
87
|
+
freeze(bare);
|
|
88
|
+
|
|
59
89
|
// /////////////////////////////////////////////////////////////////////////////
|
|
60
90
|
|
|
61
91
|
/**
|
|
@@ -237,7 +267,7 @@ const makeError = (
|
|
|
237
267
|
}
|
|
238
268
|
const hiddenDetails = weakmapGet(hiddenDetailsMap, optDetails);
|
|
239
269
|
if (hiddenDetails === undefined) {
|
|
240
|
-
throw
|
|
270
|
+
throw TypeError(`unrecognized details ${quote(optDetails)}`);
|
|
241
271
|
}
|
|
242
272
|
const messageString = getMessageString(hiddenDetails);
|
|
243
273
|
const error = new ErrorConstructor(messageString);
|
|
@@ -277,7 +307,7 @@ const note = (error, detailsNote) => {
|
|
|
277
307
|
}
|
|
278
308
|
const hiddenDetails = weakmapGet(hiddenDetailsMap, detailsNote);
|
|
279
309
|
if (hiddenDetails === undefined) {
|
|
280
|
-
throw
|
|
310
|
+
throw TypeError(`unrecognized details ${quote(detailsNote)}`);
|
|
281
311
|
}
|
|
282
312
|
const logArgs = getLogArgs(hiddenDetails);
|
|
283
313
|
const callbacks = weakmapGet(hiddenNoteCallbackArrays, error);
|
|
@@ -403,13 +433,9 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
403
433
|
typeof typename === 'string' || Fail`${quote(typename)} must be a string`;
|
|
404
434
|
|
|
405
435
|
if (optDetails === undefined) {
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
// ```
|
|
410
|
-
// except it puts the typename into the literal part of the template
|
|
411
|
-
// so it doesn't get quoted.
|
|
412
|
-
optDetails = details(['', ` must be ${an(typename)}`], specimen);
|
|
436
|
+
// Embed the type phrase without quotes.
|
|
437
|
+
const typeWithDeterminer = an(typename);
|
|
438
|
+
optDetails = details`${specimen} must be ${bare(typeWithDeterminer)}`;
|
|
413
439
|
}
|
|
414
440
|
fail(optDetails, TypeError);
|
|
415
441
|
};
|
|
@@ -431,6 +457,7 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
431
457
|
details,
|
|
432
458
|
Fail,
|
|
433
459
|
quote,
|
|
460
|
+
bare,
|
|
434
461
|
makeAssert,
|
|
435
462
|
});
|
|
436
463
|
return freeze(assert);
|
|
@@ -102,9 +102,7 @@ const spliceOut = cell => {
|
|
|
102
102
|
*/
|
|
103
103
|
export const makeLRUCacheMap = keysBudget => {
|
|
104
104
|
if (!isSafeInteger(keysBudget) || keysBudget < 0) {
|
|
105
|
-
throw
|
|
106
|
-
'keysBudget must be a safe non-negative integer number',
|
|
107
|
-
);
|
|
105
|
+
throw TypeError('keysBudget must be a safe non-negative integer number');
|
|
108
106
|
}
|
|
109
107
|
/** @typedef {DoublyLinkedCell<WeakMap<K, V> | undefined>} LRUCacheCell */
|
|
110
108
|
/** @type {WeakMap<K, LRUCacheCell>} */
|
|
@@ -227,7 +225,7 @@ export const makeNoteLogArgsArrayKit = (
|
|
|
227
225
|
argsPerErrorBudget = defaultArgsPerErrorBudget,
|
|
228
226
|
) => {
|
|
229
227
|
if (!isSafeInteger(argsPerErrorBudget) || argsPerErrorBudget < 1) {
|
|
230
|
-
throw
|
|
228
|
+
throw TypeError(
|
|
231
229
|
'argsPerErrorBudget must be a safe positive integer number',
|
|
232
230
|
);
|
|
233
231
|
}
|
|
@@ -28,7 +28,7 @@ export const tameConsole = (
|
|
|
28
28
|
optGetStackString = undefined,
|
|
29
29
|
) => {
|
|
30
30
|
if (consoleTaming !== 'safe' && consoleTaming !== 'unsafe') {
|
|
31
|
-
throw
|
|
31
|
+
throw TypeError(`unrecognized consoleTaming ${consoleTaming}`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let loggedErrorHandler;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getOwnPropertyDescriptor,
|
|
9
9
|
defineProperty,
|
|
10
10
|
} from '../commons.js';
|
|
11
|
-
import { NativeErrors } from '../
|
|
11
|
+
import { NativeErrors } from '../permits.js';
|
|
12
12
|
import { tameV8ErrorConstructor } from './tame-v8-error-constructor.js';
|
|
13
13
|
|
|
14
14
|
// Present on at least FF and XS. Proposed by Error-proposal. The original
|
|
@@ -35,10 +35,10 @@ export default function tameErrorConstructor(
|
|
|
35
35
|
stackFiltering = 'concise',
|
|
36
36
|
) {
|
|
37
37
|
if (errorTaming !== 'safe' && errorTaming !== 'unsafe') {
|
|
38
|
-
throw
|
|
38
|
+
throw TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
39
39
|
}
|
|
40
40
|
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
41
|
-
throw
|
|
41
|
+
throw TypeError(`unrecognized stackFiltering ${stackFiltering}`);
|
|
42
42
|
}
|
|
43
43
|
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
44
44
|
|
package/src/error/types.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
matchAllRegExp,
|
|
14
14
|
matchAllSymbol,
|
|
15
15
|
regexpPrototype,
|
|
16
|
+
globalThis,
|
|
16
17
|
} from './commons.js';
|
|
17
18
|
import { InertCompartment } from './compartment-shim.js';
|
|
18
19
|
|
|
@@ -134,5 +135,27 @@ export const getAnonymousIntrinsics = () => {
|
|
|
134
135
|
'%InertCompartment%': InertCompartment,
|
|
135
136
|
};
|
|
136
137
|
|
|
138
|
+
if (globalThis.Iterator) {
|
|
139
|
+
intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
|
|
140
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
141
|
+
globalThis.Iterator.from([]).take(0),
|
|
142
|
+
);
|
|
143
|
+
intrinsics['%WrapForValidIteratorPrototype%'] = getPrototypeOf(
|
|
144
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
145
|
+
globalThis.Iterator.from({ next() {} }),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (globalThis.AsyncIterator) {
|
|
150
|
+
intrinsics['%AsyncIteratorHelperPrototype%'] = getPrototypeOf(
|
|
151
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
152
|
+
globalThis.AsyncIterator.from([]).take(0),
|
|
153
|
+
);
|
|
154
|
+
intrinsics['%WrapForValidAsyncIteratorPrototype%'] = getPrototypeOf(
|
|
155
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
156
|
+
globalThis.AsyncIterator.from({ next() {} }),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
137
160
|
return intrinsics;
|
|
138
161
|
};
|
package/src/global-object.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './commons.js';
|
|
11
11
|
import { makeEvalFunction } from './make-eval-function.js';
|
|
12
12
|
import { makeFunctionConstructor } from './make-function-constructor.js';
|
|
13
|
-
import { constantProperties, universalPropertyNames } from './
|
|
13
|
+
import { constantProperties, universalPropertyNames } from './permits.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The host's ordinary global object is not provided by a `with` block, so
|
|
@@ -31,7 +31,7 @@ export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
|
31
31
|
freeze(
|
|
32
32
|
assign(create(null), {
|
|
33
33
|
set: freeze(() => {
|
|
34
|
-
throw
|
|
34
|
+
throw TypeError(
|
|
35
35
|
`Cannot set Symbol.unscopables of a Compartment's globalThis`,
|
|
36
36
|
);
|
|
37
37
|
}),
|
package/src/intrinsics.js
CHANGED
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
constantProperties,
|
|
21
21
|
sharedGlobalPropertyNames,
|
|
22
22
|
universalPropertyNames,
|
|
23
|
-
|
|
24
|
-
} from './
|
|
23
|
+
permitted,
|
|
24
|
+
} from './permits.js';
|
|
25
25
|
|
|
26
26
|
const isFunction = obj => typeof obj === 'function';
|
|
27
27
|
|
|
@@ -43,7 +43,7 @@ function initProperty(obj, name, desc) {
|
|
|
43
43
|
preDesc.enumerable !== desc.enumerable ||
|
|
44
44
|
preDesc.configurable !== desc.configurable
|
|
45
45
|
) {
|
|
46
|
-
throw
|
|
46
|
+
throw TypeError(`Conflicting definitions of ${name}`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
defineProperty(obj, name, desc);
|
|
@@ -94,24 +94,24 @@ export const makeIntrinsicsCollector = () => {
|
|
|
94
94
|
// eslint-disable-next-line no-continue
|
|
95
95
|
continue;
|
|
96
96
|
}
|
|
97
|
-
const permit =
|
|
97
|
+
const permit = permitted[name];
|
|
98
98
|
if (typeof permit !== 'object') {
|
|
99
|
-
throw
|
|
99
|
+
throw TypeError(`Expected permit object at whitelist.${name}`);
|
|
100
100
|
}
|
|
101
101
|
const namePrototype = permit.prototype;
|
|
102
102
|
if (!namePrototype) {
|
|
103
|
-
throw
|
|
103
|
+
throw TypeError(`${name}.prototype property not whitelisted`);
|
|
104
104
|
}
|
|
105
105
|
if (
|
|
106
106
|
typeof namePrototype !== 'string' ||
|
|
107
|
-
!objectHasOwnProperty(
|
|
107
|
+
!objectHasOwnProperty(permitted, namePrototype)
|
|
108
108
|
) {
|
|
109
|
-
throw
|
|
109
|
+
throw TypeError(`Unrecognized ${name}.prototype whitelist entry`);
|
|
110
110
|
}
|
|
111
111
|
const intrinsicPrototype = intrinsic.prototype;
|
|
112
112
|
if (objectHasOwnProperty(intrinsics, namePrototype)) {
|
|
113
113
|
if (intrinsics[namePrototype] !== intrinsicPrototype) {
|
|
114
|
-
throw
|
|
114
|
+
throw TypeError(`Conflicting bindings of ${namePrototype}`);
|
|
115
115
|
}
|
|
116
116
|
// eslint-disable-next-line no-continue
|
|
117
117
|
continue;
|
|
@@ -130,7 +130,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
130
130
|
|
|
131
131
|
const isPseudoNative = obj => {
|
|
132
132
|
if (!pseudoNatives) {
|
|
133
|
-
throw
|
|
133
|
+
throw TypeError(
|
|
134
134
|
'isPseudoNative can only be called after finalIntrinsics',
|
|
135
135
|
);
|
|
136
136
|
}
|
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
|
@@ -160,7 +160,7 @@ export const makeHardener = () => {
|
|
|
160
160
|
const type = typeof val;
|
|
161
161
|
if (type !== 'object' && type !== 'function') {
|
|
162
162
|
// future proof: break until someone figures out what it should do
|
|
163
|
-
throw
|
|
163
|
+
throw TypeError(`Unexpected typeof: ${type}`);
|
|
164
164
|
}
|
|
165
165
|
if (weaksetHas(hardened, val) || setHas(toFreeze, val)) {
|
|
166
166
|
// Ignore if this is an exit, or we've already visited it
|
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
|
}
|
|
@@ -195,9 +195,7 @@ export const makeModuleInstance = (
|
|
|
195
195
|
// tdz sensitive getter
|
|
196
196
|
const get = () => {
|
|
197
197
|
if (tdz) {
|
|
198
|
-
throw
|
|
199
|
-
`binding ${q(localName)} not yet initialized`,
|
|
200
|
-
);
|
|
198
|
+
throw ReferenceError(`binding ${q(localName)} not yet initialized`);
|
|
201
199
|
}
|
|
202
200
|
return value;
|
|
203
201
|
};
|
|
@@ -207,7 +205,7 @@ export const makeModuleInstance = (
|
|
|
207
205
|
// init with initValue of a declared const binding, and return
|
|
208
206
|
// it.
|
|
209
207
|
if (!tdz) {
|
|
210
|
-
throw
|
|
208
|
+
throw TypeError(
|
|
211
209
|
`Internal: binding ${q(localName)} already initialized`,
|
|
212
210
|
);
|
|
213
211
|
}
|
|
@@ -267,7 +265,7 @@ export const makeModuleInstance = (
|
|
|
267
265
|
// tdz sensitive getter
|
|
268
266
|
const get = () => {
|
|
269
267
|
if (tdz) {
|
|
270
|
-
throw
|
|
268
|
+
throw ReferenceError(
|
|
271
269
|
`binding ${q(liveExportName)} not yet initialized`,
|
|
272
270
|
);
|
|
273
271
|
}
|
|
@@ -294,9 +292,7 @@ export const makeModuleInstance = (
|
|
|
294
292
|
// tdz sensitive setter
|
|
295
293
|
const set = newValue => {
|
|
296
294
|
if (tdz) {
|
|
297
|
-
throw
|
|
298
|
-
`binding ${q(localName)} not yet initialized`,
|
|
299
|
-
);
|
|
295
|
+
throw ReferenceError(`binding ${q(localName)} not yet initialized`);
|
|
300
296
|
}
|
|
301
297
|
value = newValue;
|
|
302
298
|
for (const updater of updaters) {
|