ses 0.17.0 → 0.18.1
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 +22 -0
- package/README.md +4 -7
- package/dist/lockdown.cjs +307 -262
- package/dist/lockdown.mjs +307 -262
- package/dist/lockdown.umd.js +307 -262
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +307 -262
- package/dist/ses.mjs +307 -262
- package/dist/ses.umd.js +307 -262
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +3 -2
- package/package.json +11 -10
- package/src/compartment-evaluate.js +7 -11
- package/src/compartment-shim.js +0 -30
- package/src/environment-options.js +4 -7
- package/src/error/assert.js +4 -0
- package/src/error/console.js +2 -6
- package/src/error/types.js +84 -11
- package/src/eval-scope.js +2 -5
- package/src/get-anonymous-intrinsics.js +4 -2
- package/src/lockdown-shim.js +17 -27
- package/src/make-evaluate.js +10 -10
- package/src/make-function-constructor.js +6 -8
- package/src/make-safe-evaluator.js +5 -6
- package/src/module-instance.js +24 -14
- package/src/module-link.js +24 -42
- package/src/module-load.js +61 -27
- package/src/scope-constants.js +8 -8
- package/src/strict-scope-terminator.js +2 -5
- package/src/tame-function-constructors.js +3 -2
- package/src/tame-locale-methods.js +6 -10
- package/src/tame-math-object.js +2 -3
- package/CHANGELOG.md +0 -577
package/index.d.ts
CHANGED
|
@@ -64,9 +64,10 @@ export type FinalStaticModuleType =
|
|
|
64
64
|
| ThirdPartyStaticModuleInterface;
|
|
65
65
|
|
|
66
66
|
export interface RedirectStaticModuleInterface {
|
|
67
|
-
record: FinalStaticModuleType;
|
|
68
67
|
specifier: string;
|
|
68
|
+
record?: FinalStaticModuleType;
|
|
69
69
|
importMeta?: any;
|
|
70
|
+
compartment?: Compartment;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export type StaticModuleType =
|
|
@@ -89,7 +90,6 @@ export type ImportHook = (moduleSpecifier: string) => Promise<StaticModuleType>;
|
|
|
89
90
|
export interface CompartmentOptions {
|
|
90
91
|
name?: string;
|
|
91
92
|
transforms?: Array<Transform>;
|
|
92
|
-
globalLexicals?: Record<string, any>;
|
|
93
93
|
moduleMapHook?: ModuleMapHook;
|
|
94
94
|
importHook?: ImportHook;
|
|
95
95
|
resolveHook?: ResolveHook;
|
|
@@ -196,6 +196,7 @@ export interface Assert {
|
|
|
196
196
|
template: TemplateStringsArray | string[],
|
|
197
197
|
...args: any
|
|
198
198
|
): DetailsToken;
|
|
199
|
+
Fail(template: TemplateStringsArray | string[], ...args: any): never;
|
|
199
200
|
quote(payload: any, spaces?: string | number): ToStringable;
|
|
200
201
|
makeAssert: MakeAssert;
|
|
201
202
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.
|
|
63
|
-
"@endo/eslint-config": "^0.5.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
66
|
-
"ava": "^
|
|
62
|
+
"@endo/compartment-mapper": "^0.8.1",
|
|
63
|
+
"@endo/eslint-config": "^0.5.2",
|
|
64
|
+
"@endo/static-module-record": "^0.7.16",
|
|
65
|
+
"@endo/test262-runner": "^0.1.29",
|
|
66
|
+
"ava": "^5.1.0",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
68
68
|
"c8": "^7.7.3",
|
|
69
69
|
"eslint": "^7.32.0",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
73
73
|
"eslint-plugin-import": "^2.26.0",
|
|
74
74
|
"eslint-plugin-prettier": "^3.4.1",
|
|
75
|
-
"prettier": "^
|
|
75
|
+
"prettier": "^2.8.0",
|
|
76
76
|
"sinon": "8.0.4",
|
|
77
77
|
"terser": "^4.8.0",
|
|
78
|
-
"tsd": "^0.
|
|
79
|
-
"typescript": "~4.
|
|
78
|
+
"tsd": "^0.24.1",
|
|
79
|
+
"typescript": "~4.8.4"
|
|
80
80
|
},
|
|
81
81
|
"files": [
|
|
82
82
|
"LICENSE*",
|
|
@@ -170,6 +170,7 @@
|
|
|
170
170
|
]
|
|
171
171
|
},
|
|
172
172
|
"prettier": {
|
|
173
|
+
"arrowParens": "avoid",
|
|
173
174
|
"trailingComma": "all",
|
|
174
175
|
"singleQuote": true
|
|
175
176
|
},
|
|
@@ -179,5 +180,5 @@
|
|
|
179
180
|
],
|
|
180
181
|
"timeout": "2m"
|
|
181
182
|
},
|
|
182
|
-
"gitHead": "
|
|
183
|
+
"gitHead": "ab8d64ae6fc9c628a2d1c02d16bf9ef249f5c8dc"
|
|
183
184
|
}
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
TypeError,
|
|
4
4
|
arrayPush,
|
|
5
5
|
create,
|
|
6
|
-
defineProperties,
|
|
7
6
|
getOwnPropertyDescriptors,
|
|
8
7
|
} from './commons.js';
|
|
9
8
|
import {
|
|
@@ -14,10 +13,8 @@ import {
|
|
|
14
13
|
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
15
14
|
|
|
16
15
|
export const provideCompartmentEvaluator = (compartmentFields, options) => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
__moduleShimLexicals__ = undefined,
|
|
20
|
-
} = options;
|
|
16
|
+
const { sloppyGlobalsMode = false, __moduleShimLexicals__ = undefined } =
|
|
17
|
+
options;
|
|
21
18
|
|
|
22
19
|
let safeEvaluate;
|
|
23
20
|
|
|
@@ -28,9 +25,9 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
|
|
|
28
25
|
// shared evaluator so we need to build a new one
|
|
29
26
|
|
|
30
27
|
let { globalTransforms } = compartmentFields;
|
|
31
|
-
const { globalObject
|
|
28
|
+
const { globalObject } = compartmentFields;
|
|
32
29
|
|
|
33
|
-
let
|
|
30
|
+
let moduleLexicals;
|
|
34
31
|
if (__moduleShimLexicals__ !== undefined) {
|
|
35
32
|
// When using `evaluate` for ESM modules, as should only occur from the
|
|
36
33
|
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
@@ -42,16 +39,15 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
|
|
|
42
39
|
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
43
40
|
globalTransforms = undefined;
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
localObject,
|
|
42
|
+
moduleLexicals = create(
|
|
43
|
+
null,
|
|
48
44
|
getOwnPropertyDescriptors(__moduleShimLexicals__),
|
|
49
45
|
);
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
({ safeEvaluate } = makeSafeEvaluator({
|
|
53
49
|
globalObject,
|
|
54
|
-
|
|
50
|
+
moduleLexicals,
|
|
55
51
|
globalTransforms,
|
|
56
52
|
sloppyGlobalsMode,
|
|
57
53
|
}));
|
package/src/compartment-shim.js
CHANGED
|
@@ -7,13 +7,9 @@ import {
|
|
|
7
7
|
ReferenceError,
|
|
8
8
|
TypeError,
|
|
9
9
|
WeakMap,
|
|
10
|
-
arrayFilter,
|
|
11
|
-
arrayJoin,
|
|
12
10
|
assign,
|
|
13
11
|
defineProperties,
|
|
14
12
|
entries,
|
|
15
|
-
freeze,
|
|
16
|
-
getOwnPropertyNames,
|
|
17
13
|
promiseThen,
|
|
18
14
|
weakmapGet,
|
|
19
15
|
weakmapSet,
|
|
@@ -24,7 +20,6 @@ import {
|
|
|
24
20
|
setGlobalObjectMutableProperties,
|
|
25
21
|
setGlobalObjectEvaluators,
|
|
26
22
|
} from './global-object.js';
|
|
27
|
-
import { isValidIdentifierName } from './scope-constants.js';
|
|
28
23
|
import { sharedGlobalPropertyNames } from './whitelist.js';
|
|
29
24
|
import { load } from './module-load.js';
|
|
30
25
|
import { link } from './module-link.js';
|
|
@@ -207,7 +202,6 @@ export const makeCompartmentConstructor = (
|
|
|
207
202
|
name = '<unknown>',
|
|
208
203
|
transforms = [],
|
|
209
204
|
__shimTransforms__ = [],
|
|
210
|
-
globalLexicals: globalLexicalsOption = {},
|
|
211
205
|
resolveHook,
|
|
212
206
|
importHook,
|
|
213
207
|
moduleMapHook,
|
|
@@ -246,28 +240,6 @@ export const makeCompartmentConstructor = (
|
|
|
246
240
|
}
|
|
247
241
|
}
|
|
248
242
|
|
|
249
|
-
const invalidNames = arrayFilter(
|
|
250
|
-
getOwnPropertyNames(globalLexicalsOption),
|
|
251
|
-
identifier => !isValidIdentifierName(identifier),
|
|
252
|
-
);
|
|
253
|
-
if (invalidNames.length) {
|
|
254
|
-
throw new TypeError(
|
|
255
|
-
`Cannot create compartment with invalid names for global lexicals: ${arrayJoin(
|
|
256
|
-
invalidNames,
|
|
257
|
-
', ',
|
|
258
|
-
)}; these names would not be lexically mentionable`,
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
// The caller continues to own the globalLexicals object they passed to
|
|
262
|
-
// the compartment constructor, but the compartment only respects the
|
|
263
|
-
// original values and they are constants in the scope of evaluated
|
|
264
|
-
// programs and executed modules.
|
|
265
|
-
// This shallow copy captures only the values of enumerable own
|
|
266
|
-
// properties, erasing accessors.
|
|
267
|
-
// The snapshot is frozen to ensure that the properties are immutable
|
|
268
|
-
// when transferred-by-property-descriptor onto local scope objects.
|
|
269
|
-
const globalLexicals = freeze({ ...globalLexicalsOption });
|
|
270
|
-
|
|
271
243
|
const globalObject = {};
|
|
272
244
|
|
|
273
245
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
@@ -281,7 +253,6 @@ export const makeCompartmentConstructor = (
|
|
|
281
253
|
|
|
282
254
|
const { safeEvaluate } = makeSafeEvaluator({
|
|
283
255
|
globalObject,
|
|
284
|
-
globalLexicals,
|
|
285
256
|
globalTransforms,
|
|
286
257
|
sloppyGlobalsMode: false,
|
|
287
258
|
});
|
|
@@ -306,7 +277,6 @@ export const makeCompartmentConstructor = (
|
|
|
306
277
|
name: `${name}`,
|
|
307
278
|
globalTransforms,
|
|
308
279
|
globalObject,
|
|
309
|
-
globalLexicals,
|
|
310
280
|
safeEvaluate,
|
|
311
281
|
resolveHook,
|
|
312
282
|
importHook,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { arrayPush, freeze } from './commons.js';
|
|
6
6
|
import { assert } from './error/assert.js';
|
|
7
7
|
|
|
8
|
-
const { details: X, quote: q } = assert;
|
|
8
|
+
const { details: X, Fail, quote: q } = assert;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* JavaScript module semantics resists attempts to parameterize a module's
|
|
@@ -109,12 +109,9 @@ export const makeEnvironmentCaptor = aGlobal => {
|
|
|
109
109
|
}
|
|
110
110
|
setting === undefined ||
|
|
111
111
|
typeof setting === 'string' ||
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
setting,
|
|
116
|
-
)}, if present, must be a string.`,
|
|
117
|
-
);
|
|
112
|
+
Fail`Environment option value ${q(
|
|
113
|
+
setting,
|
|
114
|
+
)}, if present, must be a string.`;
|
|
118
115
|
return setting;
|
|
119
116
|
};
|
|
120
117
|
freeze(getEnvironmentOption);
|
package/src/error/assert.js
CHANGED
|
@@ -375,6 +375,9 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
375
375
|
};
|
|
376
376
|
freeze(fail);
|
|
377
377
|
|
|
378
|
+
/** @type {FailTag} */
|
|
379
|
+
const Fail = (template, ...args) => fail(details(template, ...args));
|
|
380
|
+
|
|
378
381
|
// Don't freeze or export `baseAssert` until we add methods.
|
|
379
382
|
// TODO If I change this from a `function` function to an arrow
|
|
380
383
|
// function, I seem to get type errors from TypeScript. Why?
|
|
@@ -433,6 +436,7 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
433
436
|
string: assertString,
|
|
434
437
|
note,
|
|
435
438
|
details,
|
|
439
|
+
Fail,
|
|
436
440
|
quote,
|
|
437
441
|
makeAssert,
|
|
438
442
|
});
|
package/src/error/console.js
CHANGED
|
@@ -174,12 +174,8 @@ freeze(ErrorInfo);
|
|
|
174
174
|
|
|
175
175
|
/** @type {MakeCausalConsole} */
|
|
176
176
|
const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
177
|
-
const {
|
|
178
|
-
|
|
179
|
-
tagError,
|
|
180
|
-
takeMessageLogArgs,
|
|
181
|
-
takeNoteLogArgsArray,
|
|
182
|
-
} = loggedErrorHandler;
|
|
177
|
+
const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray } =
|
|
178
|
+
loggedErrorHandler;
|
|
183
179
|
|
|
184
180
|
/**
|
|
185
181
|
* @param {ReadonlyArray<any>} logArgs
|
package/src/error/types.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @typedef {
|
|
15
|
+
* @typedef {object} AssertMakeErrorOptions
|
|
16
16
|
* @property {string=} errorName
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -59,51 +59,65 @@
|
|
|
59
59
|
*/
|
|
60
60
|
|
|
61
61
|
// Type all the overloads of the assertTypeof function.
|
|
62
|
-
// There may eventually be a better way to do this, but
|
|
63
|
-
// Typescript 4.0.
|
|
62
|
+
// There may eventually be a better way to do this, but
|
|
63
|
+
// thems the breaks with Typescript 4.0.
|
|
64
64
|
/**
|
|
65
65
|
* @callback AssertTypeofBigint
|
|
66
66
|
* @param {any} specimen
|
|
67
67
|
* @param {'bigint'} typename
|
|
68
68
|
* @param {Details=} optDetails
|
|
69
69
|
* @returns {asserts specimen is bigint}
|
|
70
|
-
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
71
73
|
* @callback AssertTypeofBoolean
|
|
72
74
|
* @param {any} specimen
|
|
73
75
|
* @param {'boolean'} typename
|
|
74
76
|
* @param {Details=} optDetails
|
|
75
77
|
* @returns {asserts specimen is boolean}
|
|
76
|
-
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
77
81
|
* @callback AssertTypeofFunction
|
|
78
82
|
* @param {any} specimen
|
|
79
83
|
* @param {'function'} typename
|
|
80
84
|
* @param {Details=} optDetails
|
|
81
85
|
* @returns {asserts specimen is Function}
|
|
82
|
-
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
83
89
|
* @callback AssertTypeofNumber
|
|
84
90
|
* @param {any} specimen
|
|
85
91
|
* @param {'number'} typename
|
|
86
92
|
* @param {Details=} optDetails
|
|
87
93
|
* @returns {asserts specimen is number}
|
|
88
|
-
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
/**
|
|
89
97
|
* @callback AssertTypeofObject
|
|
90
98
|
* @param {any} specimen
|
|
91
99
|
* @param {'object'} typename
|
|
92
100
|
* @param {Details=} optDetails
|
|
93
101
|
* @returns {asserts specimen is Record<any, any> | null}
|
|
94
|
-
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
95
105
|
* @callback AssertTypeofString
|
|
96
106
|
* @param {any} specimen
|
|
97
107
|
* @param {'string'} typename
|
|
98
108
|
* @param {Details=} optDetails
|
|
99
109
|
* @returns {asserts specimen is string}
|
|
100
|
-
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
101
113
|
* @callback AssertTypeofSymbol
|
|
102
114
|
* @param {any} specimen
|
|
103
115
|
* @param {'symbol'} typename
|
|
104
116
|
* @param {Details=} optDetails
|
|
105
117
|
* @returns {asserts specimen is symbol}
|
|
106
|
-
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
107
121
|
* @callback AssertTypeofUndefined
|
|
108
122
|
* @param {any} specimen
|
|
109
123
|
* @param {'undefined'} typename
|
|
@@ -157,7 +171,7 @@
|
|
|
157
171
|
*/
|
|
158
172
|
|
|
159
173
|
/**
|
|
160
|
-
* @typedef {
|
|
174
|
+
* @typedef {object} StringablePayload
|
|
161
175
|
* Holds the payload passed to quote so that its printed form is visible.
|
|
162
176
|
* @property {() => string} toString How to print the payload
|
|
163
177
|
*/
|
|
@@ -260,6 +274,64 @@
|
|
|
260
274
|
* `string[]` can also be used as a template.
|
|
261
275
|
*/
|
|
262
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
|
|
279
|
+
* The `Fail` tamplate tag supports replacing patterns like
|
|
280
|
+
* ```js
|
|
281
|
+
* assert(cond, X`...complaint...`);
|
|
282
|
+
* ```
|
|
283
|
+
* or
|
|
284
|
+
* ```js
|
|
285
|
+
* cond || assert.fail(X`...complaint...`);
|
|
286
|
+
* ```
|
|
287
|
+
* with patterns like
|
|
288
|
+
* ```js
|
|
289
|
+
* cond || Fail`...complaint...`;
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* However, due to [weakness in current
|
|
293
|
+
* TypeScript](https://github.com/microsoft/TypeScript/issues/51426), the `||`
|
|
294
|
+
* patterns are not as powerful as the `assert(...)` call at enabling static
|
|
295
|
+
* reasoning. Of the `||`, again due to weaknesses in current TypeScript,
|
|
296
|
+
* the
|
|
297
|
+
* ```js
|
|
298
|
+
* cond || Fail`...complaint...`
|
|
299
|
+
* ```
|
|
300
|
+
* pattern is not as powerful as the
|
|
301
|
+
* ```js
|
|
302
|
+
* cond || assert.fail(X`...complaint...`);
|
|
303
|
+
* ```
|
|
304
|
+
* at enabling static resoning. Despite these problems, we do not want to
|
|
305
|
+
* return to the
|
|
306
|
+
* ```js
|
|
307
|
+
* assert(cond, X`...complaint...`)
|
|
308
|
+
* ```
|
|
309
|
+
* style because of the substantial overhead in
|
|
310
|
+
* evaluating the `X` template in the typical `true` case where it is not
|
|
311
|
+
* needed. And we do not want to return to the
|
|
312
|
+
* ```js
|
|
313
|
+
* assert.fail(X`...complaint...`)`
|
|
314
|
+
* ```
|
|
315
|
+
* because of the verbosity and loss of readability. Instead, until/unless
|
|
316
|
+
* https://github.com/microsoft/TypeScript/issues/51426 is fixed, for those
|
|
317
|
+
* new-style assertions where this loss of static reasoning is a problem,
|
|
318
|
+
* instead express the assertion as
|
|
319
|
+
* ```js
|
|
320
|
+
* if (!cond) {
|
|
321
|
+
* Fail`...complaint...`;
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
* or, if needed,
|
|
325
|
+
* ```js
|
|
326
|
+
* if (!cond) {
|
|
327
|
+
* // `throw` is noop since `Fail` throws. But linter confused
|
|
328
|
+
* throw Fail`...complaint...`;
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
331
|
+
* This avoid the TypeScript bugs that cause the loss of static reasoning,
|
|
332
|
+
* but with no loss of efficiency and little loss of readability.
|
|
333
|
+
*/
|
|
334
|
+
|
|
263
335
|
/**
|
|
264
336
|
* assert that expr is truthy, with an optional details to describe
|
|
265
337
|
* the assertion. It is a tagged template literal like
|
|
@@ -286,6 +358,7 @@
|
|
|
286
358
|
* string: AssertString,
|
|
287
359
|
* note: AssertNote,
|
|
288
360
|
* details: DetailsTag,
|
|
361
|
+
* Fail: FailTag,
|
|
289
362
|
* quote: AssertQuote,
|
|
290
363
|
* makeAssert: MakeAssert,
|
|
291
364
|
* } } Assert
|
package/src/eval-scope.js
CHANGED
|
@@ -2,7 +2,7 @@ import { FERAL_EVAL, create, defineProperties, freeze } from './commons.js';
|
|
|
2
2
|
|
|
3
3
|
import { assert } from './error/assert.js';
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { Fail } = assert;
|
|
6
6
|
|
|
7
7
|
// We attempt to frustrate stack bumping attacks on the safe evaluator
|
|
8
8
|
// (`make-safe-evaluator.js`).
|
|
@@ -73,10 +73,7 @@ export const makeEvalScopeKit = () => {
|
|
|
73
73
|
evalScope,
|
|
74
74
|
allowNextEvalToBeUnsafe() {
|
|
75
75
|
if (evalScopeKit.revoked !== null) {
|
|
76
|
-
|
|
77
|
-
assert.fail(
|
|
78
|
-
d`a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`,
|
|
79
|
-
);
|
|
76
|
+
Fail`a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`;
|
|
80
77
|
}
|
|
81
78
|
// Allow next reference to eval produce the unsafe FERAL_EVAL.
|
|
82
79
|
// We avoid defineProperty because it consumes an extra stack frame taming
|
|
@@ -45,8 +45,10 @@ export const getAnonymousIntrinsics = () => {
|
|
|
45
45
|
|
|
46
46
|
// 9.2.4.1 %ThrowTypeError%
|
|
47
47
|
|
|
48
|
-
const ThrowTypeError = getOwnPropertyDescriptor(
|
|
49
|
-
|
|
48
|
+
const ThrowTypeError = getOwnPropertyDescriptor(
|
|
49
|
+
makeArguments(),
|
|
50
|
+
'callee',
|
|
51
|
+
).get;
|
|
50
52
|
|
|
51
53
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
52
54
|
|
package/src/lockdown-shim.js
CHANGED
|
@@ -55,7 +55,7 @@ import { makeCompartmentConstructor } from './compartment-shim.js';
|
|
|
55
55
|
|
|
56
56
|
/** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
|
|
57
57
|
|
|
58
|
-
const { details: d, quote: q } = assert;
|
|
58
|
+
const { Fail, details: d, quote: q } = assert;
|
|
59
59
|
|
|
60
60
|
/** @type {Error=} */
|
|
61
61
|
let priorLockdown;
|
|
@@ -82,7 +82,6 @@ const harden = makeHardener();
|
|
|
82
82
|
* @param {Object} [options]
|
|
83
83
|
* @param {Array<Transform>} [options.transforms]
|
|
84
84
|
* @param {Array<Transform>} [options.__shimTransforms__]
|
|
85
|
-
* @param {Object} [options.globalLexicals]
|
|
86
85
|
*/
|
|
87
86
|
|
|
88
87
|
// TODO https://github.com/endojs/endo/issues/814
|
|
@@ -152,10 +151,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
152
151
|
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
|
|
153
152
|
// for an explanation.
|
|
154
153
|
|
|
155
|
-
const {
|
|
156
|
-
|
|
157
|
-
getCapturedEnvironmentOptionNames,
|
|
158
|
-
} = makeEnvironmentCaptor(globalThis);
|
|
154
|
+
const { getEnvironmentOption: getenv, getCapturedEnvironmentOptionNames } =
|
|
155
|
+
makeEnvironmentCaptor(globalThis);
|
|
159
156
|
|
|
160
157
|
const {
|
|
161
158
|
errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
|
|
@@ -192,26 +189,23 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
192
189
|
);
|
|
193
190
|
}
|
|
194
191
|
|
|
195
|
-
|
|
196
|
-
evalTaming === '
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
d`lockdown(): non supported option evalTaming: ${q(evalTaming)}`,
|
|
200
|
-
);
|
|
192
|
+
evalTaming === 'unsafeEval' ||
|
|
193
|
+
evalTaming === 'safeEval' ||
|
|
194
|
+
evalTaming === 'noEval' ||
|
|
195
|
+
Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
|
|
201
196
|
|
|
202
197
|
// Assert that only supported options were passed.
|
|
203
198
|
// Use Reflect.ownKeys to reject symbol-named properties as well.
|
|
204
199
|
const extraOptionsNames = ownKeys(extraOptions);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
d`lockdown(): non supported option ${q(extraOptionsNames)}`,
|
|
208
|
-
);
|
|
200
|
+
extraOptionsNames.length === 0 ||
|
|
201
|
+
Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;
|
|
209
202
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
203
|
+
priorLockdown === undefined ||
|
|
204
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
205
|
+
assert.fail(
|
|
206
|
+
d`Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
|
|
207
|
+
TypeError,
|
|
208
|
+
);
|
|
215
209
|
priorLockdown = new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
216
210
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
217
211
|
// trace retained:
|
|
@@ -253,7 +247,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
253
247
|
};
|
|
254
248
|
|
|
255
249
|
if (seemsToBeLockedDown()) {
|
|
256
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
257
250
|
throw new TypeError(
|
|
258
251
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`,
|
|
259
252
|
);
|
|
@@ -265,11 +258,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
265
258
|
|
|
266
259
|
tameDomains(domainTaming);
|
|
267
260
|
|
|
268
|
-
const {
|
|
269
|
-
|
|
270
|
-
completePrototypes,
|
|
271
|
-
finalIntrinsics,
|
|
272
|
-
} = makeIntrinsicsCollector();
|
|
261
|
+
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
262
|
+
makeIntrinsicsCollector();
|
|
273
263
|
|
|
274
264
|
addIntrinsics({ harden });
|
|
275
265
|
|
package/src/make-evaluate.js
CHANGED
|
@@ -26,22 +26,22 @@ function buildOptimizer(constants, name) {
|
|
|
26
26
|
*
|
|
27
27
|
* @param {object} context
|
|
28
28
|
* @param {object} context.evalScope
|
|
29
|
-
* @param {object} context.
|
|
29
|
+
* @param {object} context.moduleLexicals
|
|
30
30
|
* @param {object} context.globalObject
|
|
31
31
|
* @param {object} context.scopeTerminator
|
|
32
32
|
*/
|
|
33
33
|
export const makeEvaluate = context => {
|
|
34
|
-
const { globalObjectConstants,
|
|
34
|
+
const { globalObjectConstants, moduleLexicalConstants } = getScopeConstants(
|
|
35
35
|
context.globalObject,
|
|
36
|
-
context.
|
|
36
|
+
context.moduleLexicals,
|
|
37
37
|
);
|
|
38
38
|
const globalObjectOptimizer = buildOptimizer(
|
|
39
39
|
globalObjectConstants,
|
|
40
40
|
'globalObject',
|
|
41
41
|
);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
'
|
|
42
|
+
const moduleLexicalOptimizer = buildOptimizer(
|
|
43
|
+
moduleLexicalConstants,
|
|
44
|
+
'moduleLexicals',
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
// Create a function in sloppy mode, so that we can use 'with'. It returns
|
|
@@ -57,7 +57,7 @@ export const makeEvaluate = context => {
|
|
|
57
57
|
// trigger direct eval. The direct eval semantics is what allows the
|
|
58
58
|
// evaluated code to lookup free variable names on the other scope
|
|
59
59
|
// objects and not in global scope.
|
|
60
|
-
// b) `
|
|
60
|
+
// b) `moduleLexicals` which provide a way to introduce free variables
|
|
61
61
|
// that are not available on the globalObject.
|
|
62
62
|
// c) `globalObject` is the global scope object of the evaluator, aka the
|
|
63
63
|
// Compartment's `globalThis`.
|
|
@@ -71,7 +71,7 @@ export const makeEvaluate = context => {
|
|
|
71
71
|
|
|
72
72
|
// Notes:
|
|
73
73
|
// - The `optimizer` strings only lookup values on the `globalObject` and
|
|
74
|
-
// `
|
|
74
|
+
// `moduleLexicals` objects by construct. Keywords like 'function' are
|
|
75
75
|
// reserved and cannot be used as a variable, so they are excluded from the
|
|
76
76
|
// optimizer. Furthermore to prevent shadowing 'eval', while a valid
|
|
77
77
|
// identifier, that name is also explicitly excluded.
|
|
@@ -92,10 +92,10 @@ export const makeEvaluate = context => {
|
|
|
92
92
|
const evaluateFactory = FERAL_FUNCTION(`
|
|
93
93
|
with (this.scopeTerminator) {
|
|
94
94
|
with (this.globalObject) {
|
|
95
|
-
with (this.
|
|
95
|
+
with (this.moduleLexicals) {
|
|
96
96
|
with (this.evalScope) {
|
|
97
97
|
${globalObjectOptimizer}
|
|
98
|
-
${
|
|
98
|
+
${moduleLexicalOptimizer}
|
|
99
99
|
return function() {
|
|
100
100
|
'use strict';
|
|
101
101
|
return eval(arguments[0]);
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
} from './commons.js';
|
|
8
8
|
import { assert } from './error/assert.js';
|
|
9
9
|
|
|
10
|
+
const { Fail } = assert;
|
|
11
|
+
|
|
10
12
|
/*
|
|
11
13
|
* makeFunctionConstructor()
|
|
12
14
|
* A safe version of the native Function which relies on
|
|
@@ -67,14 +69,10 @@ export const makeFunctionConstructor = safeEvaluate => {
|
|
|
67
69
|
});
|
|
68
70
|
|
|
69
71
|
// Assert identity of Function.__proto__ accross all compartments
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
assert(
|
|
75
|
-
getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype,
|
|
76
|
-
'Function constructor prototype is the same accross compartments',
|
|
77
|
-
);
|
|
72
|
+
getPrototypeOf(FERAL_FUNCTION) === FERAL_FUNCTION.prototype ||
|
|
73
|
+
Fail`Function prototype is the same accross compartments`;
|
|
74
|
+
getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype ||
|
|
75
|
+
Fail`Function constructor prototype is the same accross compartments`;
|
|
78
76
|
|
|
79
77
|
return newFunction;
|
|
80
78
|
};
|