ses 0.18.1 → 0.18.3
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 +15 -0
- package/README.md +9 -4
- package/SECURITY.md +1 -1
- package/dist/lockdown.cjs +753 -384
- package/dist/lockdown.mjs +753 -384
- package/dist/lockdown.umd.js +753 -384
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +753 -384
- package/dist/ses.mjs +753 -384
- package/dist/ses.umd.js +753 -384
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -0
- package/package.json +16 -21
- package/src/commons.js +4 -0
- package/src/compartment-shim.js +3 -3
- package/src/enablements.js +13 -1
- package/src/environment-options.js +10 -19
- package/src/error/assert.js +28 -35
- package/src/error/internal-types.js +3 -3
- package/src/error/note-log-args.js +280 -0
- package/src/error/types.js +51 -70
- package/src/get-anonymous-intrinsics.js +2 -2
- package/src/get-source-url.js +3 -0
- package/src/global-object.js +9 -9
- package/src/intrinsics.js +1 -1
- package/src/lockdown-shim.js +14 -8
- package/src/make-hardener.js +1 -1
- package/src/make-safe-evaluator.js +4 -4
- package/src/module-instance.js +11 -5
- package/src/module-load.js +1 -1
- package/src/scope-constants.js +2 -2
- package/src/sloppy-globals-scope-terminator.js +1 -0
- package/src/strict-scope-terminator.js +2 -3
- package/src/tame-domains.js +1 -0
- package/src/tame-harden.js +23 -0
- package/src/tame-locale-methods.js +2 -2
- package/src/transforms.js +15 -0
- package/src/whitelist-intrinsics.js +2 -2
- package/src/whitelist.js +9 -1
- package/tools.js +25 -0
- package/{index.d.ts → types.d.ts} +1 -0
package/src/error/types.js
CHANGED
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
*
|
|
35
35
|
* The `assert.fail` method.
|
|
36
36
|
*
|
|
37
|
-
* Fail an assertion, recording details to the console and
|
|
38
|
-
* raising an exception with
|
|
37
|
+
* Fail an assertion, recording full details to the console and
|
|
38
|
+
* raising an exception with a message in which `details` substitution values
|
|
39
|
+
* have been redacted.
|
|
39
40
|
*
|
|
40
41
|
* The optional `optDetails` can be a string for backwards compatibility
|
|
41
42
|
* with the nodejs assertion library.
|
|
@@ -141,14 +142,15 @@
|
|
|
141
142
|
* Assert an expected typeof result.
|
|
142
143
|
* @param {any} specimen The value to get the typeof
|
|
143
144
|
* @param {Details=} optDetails The details to throw
|
|
145
|
+
* @returns {asserts specimen is string}
|
|
144
146
|
*/
|
|
145
147
|
|
|
146
148
|
/**
|
|
147
149
|
* @callback AssertNote
|
|
148
150
|
* The `assert.note` method.
|
|
149
151
|
*
|
|
150
|
-
* Annotate
|
|
151
|
-
* augmented console
|
|
152
|
+
* Annotate an error with details, potentially to be used by an
|
|
153
|
+
* augmented console such as the causal console of `console.js`, to
|
|
152
154
|
* provide extra information associated with logged errors.
|
|
153
155
|
*
|
|
154
156
|
* @param {Error} error
|
|
@@ -178,38 +180,24 @@
|
|
|
178
180
|
|
|
179
181
|
/**
|
|
180
182
|
* To "declassify" and quote a substitution value used in a
|
|
181
|
-
* details`...` template literal, enclose that substitution expression
|
|
182
|
-
* in a call to `quote`. This
|
|
183
|
-
* (as if with `JSON.stringify`)
|
|
183
|
+
* ``` details`...` ``` template literal, enclose that substitution expression
|
|
184
|
+
* in a call to `quote`. This makes the value appear quoted
|
|
185
|
+
* (as if with `JSON.stringify`) in the message of the thrown error. The
|
|
184
186
|
* payload itself is still passed unquoted to the console as it would be
|
|
185
187
|
* without `quote`.
|
|
186
188
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* want to reveal the sky's actual color, but we do want the thrown error's
|
|
190
|
-
* message to reveal what color the sky was supposed to be:
|
|
189
|
+
* For example, the following will reveal the expected sky color, but not the
|
|
190
|
+
* actual incorrect sky color, in the thrown error's message:
|
|
191
191
|
* ```js
|
|
192
|
-
*
|
|
193
|
-
* sky.color,
|
|
194
|
-
* color,
|
|
195
|
-
* details`${sky.color} should be ${quote(color)}`,
|
|
196
|
-
* );
|
|
192
|
+
* sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
|
|
197
193
|
* ```
|
|
198
194
|
*
|
|
199
195
|
* // TODO Update SES-shim to new convention, where `details` is
|
|
200
196
|
* // renamed to `X` rather than `d`.
|
|
201
|
-
* The normal convention is to locally rename `quote` to `q`
|
|
202
|
-
* `details
|
|
203
|
-
* ```js
|
|
204
|
-
* const { details: d, quote: q } = assert;
|
|
205
|
-
* ```
|
|
206
|
-
* so the above example would then be
|
|
197
|
+
* The normal convention is to locally rename `details` to `d` and `quote` to `q`
|
|
198
|
+
* like `const { details: d, quote: q } = assert;`, so the above example would then be
|
|
207
199
|
* ```js
|
|
208
|
-
*
|
|
209
|
-
* sky.color,
|
|
210
|
-
* color,
|
|
211
|
-
* d`${sky.color} should be ${q(color)}`,
|
|
212
|
-
* );
|
|
200
|
+
* sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
|
|
213
201
|
* ```
|
|
214
202
|
*
|
|
215
203
|
* @callback AssertQuote
|
|
@@ -261,75 +249,68 @@
|
|
|
261
249
|
* ```js
|
|
262
250
|
* assert(sky.isBlue(), details`${sky.color} should be "blue"`);
|
|
263
251
|
* ```
|
|
252
|
+
* // TODO Update SES-shim to new convention, where `details` is
|
|
253
|
+
* // renamed to `X` rather than `d`.
|
|
254
|
+
* or following the normal convention to locally rename `details` to `d`
|
|
255
|
+
* and `quote` to `q` like `const { details: d, quote: q } = assert;`:
|
|
256
|
+
* ```js
|
|
257
|
+
* assert(sky.isBlue(), d`${sky.color} should be "blue"`);
|
|
258
|
+
* ```
|
|
259
|
+
* However, note that in most cases it is preferable to instead use the `Fail`
|
|
260
|
+
* template literal tag (which has the same input signature as `details`
|
|
261
|
+
* but automatically creates and throws an error):
|
|
262
|
+
* ```js
|
|
263
|
+
* sky.isBlue() || Fail`${sky.color} should be "blue"`;
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
264
266
|
* The details template tag returns a `DetailsToken` object that can print
|
|
265
267
|
* itself with the formatted message in two ways.
|
|
266
|
-
* It will report
|
|
267
|
-
*
|
|
268
|
+
* It will report full details to the console, but
|
|
269
|
+
* mask embedded substitution values with their typeof information in the thrown error
|
|
268
270
|
* to prevent revealing secrets up the exceptional path. In the example
|
|
269
271
|
* above, the thrown error may reveal only that `sky.color` is a string,
|
|
270
272
|
* whereas the same diagnostic printed to the console reveals that the
|
|
271
|
-
* sky was green.
|
|
273
|
+
* sky was green. This masking can be disabled for an individual substitution value
|
|
274
|
+
* using `quote`.
|
|
272
275
|
*
|
|
273
|
-
* The `raw`
|
|
274
|
-
*
|
|
276
|
+
* The `raw` property of an input template array is ignored, so a simple
|
|
277
|
+
* array of strings may be provided directly.
|
|
275
278
|
*/
|
|
276
279
|
|
|
277
280
|
/**
|
|
278
281
|
* @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
282
|
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
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
|
|
283
|
+
* Use the `Fail` function as a template literal tag to efficiently
|
|
284
|
+
* create and throw a `details`-style error only when a condition is not satisfied.
|
|
301
285
|
* ```js
|
|
302
|
-
*
|
|
286
|
+
* condition || Fail`...complaint...`;
|
|
303
287
|
* ```
|
|
304
|
-
*
|
|
305
|
-
* return to the
|
|
288
|
+
* This avoids the overhead of creating usually-unnecessary errors like
|
|
306
289
|
* ```js
|
|
307
|
-
* assert(
|
|
290
|
+
* assert(condition, details`...complaint...`);
|
|
308
291
|
* ```
|
|
309
|
-
*
|
|
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
|
|
292
|
+
* while improving readability over alternatives like
|
|
312
293
|
* ```js
|
|
313
|
-
* assert.fail(
|
|
294
|
+
* condition || assert.fail(details`...complaint...`);
|
|
314
295
|
* ```
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
296
|
+
*
|
|
297
|
+
* However, due to current weakness in TypeScript, static reasoning
|
|
298
|
+
* is less powerful with the `||` patterns than with an `assert` call.
|
|
299
|
+
* Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
|
|
300
|
+
* for `||`-style assertions where this loss of static reasoning is a problem,
|
|
318
301
|
* instead express the assertion as
|
|
319
302
|
* ```js
|
|
320
|
-
* if (!
|
|
303
|
+
* if (!condition) {
|
|
321
304
|
* Fail`...complaint...`;
|
|
322
305
|
* }
|
|
323
306
|
* ```
|
|
324
307
|
* or, if needed,
|
|
325
308
|
* ```js
|
|
326
|
-
* if (!
|
|
327
|
-
* // `throw` is noop since `Fail` throws
|
|
309
|
+
* if (!condition) {
|
|
310
|
+
* // `throw` is noop since `Fail` throws, but it improves static analysis
|
|
328
311
|
* throw Fail`...complaint...`;
|
|
329
312
|
* }
|
|
330
313
|
* ```
|
|
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
314
|
*/
|
|
334
315
|
|
|
335
316
|
/**
|
|
@@ -367,7 +348,7 @@
|
|
|
367
348
|
// /////////////////////////////////////////////////////////////////////////////
|
|
368
349
|
|
|
369
350
|
/**
|
|
370
|
-
* @typedef {
|
|
351
|
+
* @typedef {object} VirtualConsole
|
|
371
352
|
* @property {Console['debug']} debug
|
|
372
353
|
* @property {Console['log']} log
|
|
373
354
|
* @property {Console['info']} info
|
|
@@ -20,7 +20,7 @@ import { InertCompartment } from './compartment-shim.js';
|
|
|
20
20
|
* Object.getConstructorOf()
|
|
21
21
|
* Helper function to improve readability, similar to Object.getPrototypeOf().
|
|
22
22
|
*
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {object} obj
|
|
24
24
|
*/
|
|
25
25
|
function getConstructorOf(obj) {
|
|
26
26
|
return getPrototypeOf(obj).constructor;
|
|
@@ -38,7 +38,7 @@ function makeArguments() {
|
|
|
38
38
|
* Get the intrinsics not otherwise reachable by named own property
|
|
39
39
|
* traversal from the global object.
|
|
40
40
|
*
|
|
41
|
-
* @returns {
|
|
41
|
+
* @returns {object}
|
|
42
42
|
*/
|
|
43
43
|
export const getAnonymousIntrinsics = () => {
|
|
44
44
|
const InertFunction = FERAL_FUNCTION.prototype.constructor;
|
package/src/get-source-url.js
CHANGED
package/src/global-object.js
CHANGED
|
@@ -22,7 +22,7 @@ import { constantProperties, universalPropertyNames } from './whitelist.js';
|
|
|
22
22
|
* But, we can install this setter to prevent a program from proceding on
|
|
23
23
|
* this false assumption.
|
|
24
24
|
*
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {object} globalObject
|
|
26
26
|
*/
|
|
27
27
|
export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
28
28
|
defineProperty(
|
|
@@ -48,7 +48,7 @@ export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
|
48
48
|
* (SetDefaultGlobalBindings). This process is split between this function and
|
|
49
49
|
* `setGlobalObjectMutableProperties`.
|
|
50
50
|
*
|
|
51
|
-
* @param {
|
|
51
|
+
* @param {object} globalObject
|
|
52
52
|
*/
|
|
53
53
|
export const setGlobalObjectConstantProperties = globalObject => {
|
|
54
54
|
for (const [name, constant] of entries(constantProperties)) {
|
|
@@ -68,12 +68,12 @@ export const setGlobalObjectConstantProperties = globalObject => {
|
|
|
68
68
|
* `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
|
|
69
69
|
* `sharedGlobalPropertyNames`.
|
|
70
70
|
*
|
|
71
|
-
* @param {
|
|
72
|
-
* @param {
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
71
|
+
* @param {object} globalObject
|
|
72
|
+
* @param {object} param1
|
|
73
|
+
* @param {object} param1.intrinsics
|
|
74
|
+
* @param {object} param1.newGlobalPropertyNames
|
|
75
75
|
* @param {Function} param1.makeCompartmentConstructor
|
|
76
|
-
* @param {(
|
|
76
|
+
* @param {(object) => void} param1.markVirtualizedNativeFunction
|
|
77
77
|
*/
|
|
78
78
|
export const setGlobalObjectMutableProperties = (
|
|
79
79
|
globalObject,
|
|
@@ -135,9 +135,9 @@ export const setGlobalObjectMutableProperties = (
|
|
|
135
135
|
* setGlobalObjectEvaluators()
|
|
136
136
|
* Set the eval and the Function evaluator on the global object with given evalTaming policy.
|
|
137
137
|
*
|
|
138
|
-
* @param {
|
|
138
|
+
* @param {object} globalObject
|
|
139
139
|
* @param {Function} evaluator
|
|
140
|
-
* @param {(
|
|
140
|
+
* @param {(object) => void} markVirtualizedNativeFunction
|
|
141
141
|
*/
|
|
142
142
|
export const setGlobalObjectEvaluators = (
|
|
143
143
|
globalObject,
|
package/src/intrinsics.js
CHANGED
|
@@ -160,7 +160,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
160
160
|
* If run before lockdown, the returned intrinsics record will carry the
|
|
161
161
|
* *original* unsafe (feral, untamed) bindings of these global variables.
|
|
162
162
|
*
|
|
163
|
-
* @param {
|
|
163
|
+
* @param {object} globalObject
|
|
164
164
|
*/
|
|
165
165
|
export const getGlobalIntrinsics = globalObject => {
|
|
166
166
|
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector();
|
package/src/lockdown-shim.js
CHANGED
|
@@ -52,8 +52,9 @@ import { assert, makeAssert } from './error/assert.js';
|
|
|
52
52
|
import { makeEnvironmentCaptor } from './environment-options.js';
|
|
53
53
|
import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
|
|
54
54
|
import { makeCompartmentConstructor } from './compartment-shim.js';
|
|
55
|
+
import { tameHarden } from './tame-harden.js';
|
|
55
56
|
|
|
56
|
-
/** @typedef {import('../
|
|
57
|
+
/** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
|
|
57
58
|
|
|
58
59
|
const { Fail, details: d, quote: q } = assert;
|
|
59
60
|
|
|
@@ -67,7 +68,7 @@ let priorLockdown;
|
|
|
67
68
|
* @param {T} ref
|
|
68
69
|
* @returns {T}
|
|
69
70
|
*/
|
|
70
|
-
const
|
|
71
|
+
const safeHarden = makeHardener();
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* @callback Transform
|
|
@@ -77,9 +78,9 @@ const harden = makeHardener();
|
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* @callback CompartmentConstructor
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
81
|
+
* @param {object} endowments
|
|
82
|
+
* @param {object} moduleMap
|
|
83
|
+
* @param {object} [options]
|
|
83
84
|
* @param {Array<Transform>} [options.transforms]
|
|
84
85
|
* @param {Array<Transform>} [options.__shimTransforms__]
|
|
85
86
|
*/
|
|
@@ -115,6 +116,7 @@ const assertDirectEvalAvailable = () => {
|
|
|
115
116
|
allowed = true;
|
|
116
117
|
}
|
|
117
118
|
if (!allowed) {
|
|
119
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
|
|
118
120
|
throw new TypeError(
|
|
119
121
|
`SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
|
|
120
122
|
);
|
|
@@ -173,6 +175,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
173
175
|
/** @param {string} debugName */
|
|
174
176
|
debugName => debugName !== '',
|
|
175
177
|
),
|
|
178
|
+
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
|
|
176
179
|
dateTaming = 'safe', // deprecated
|
|
177
180
|
mathTaming = 'safe', // deprecated
|
|
178
181
|
...extraOptions
|
|
@@ -206,6 +209,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
206
209
|
d`Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
|
|
207
210
|
TypeError,
|
|
208
211
|
);
|
|
212
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
|
|
209
213
|
priorLockdown = new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
210
214
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
211
215
|
// trace retained:
|
|
@@ -247,6 +251,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
247
251
|
};
|
|
248
252
|
|
|
249
253
|
if (seemsToBeLockedDown()) {
|
|
254
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_MULTIPLE_INSTANCES.md
|
|
250
255
|
throw new TypeError(
|
|
251
256
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`,
|
|
252
257
|
);
|
|
@@ -261,7 +266,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
261
266
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
262
267
|
makeIntrinsicsCollector();
|
|
263
268
|
|
|
264
|
-
|
|
269
|
+
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
|
|
270
|
+
addIntrinsics({ harden: tamedHarden });
|
|
265
271
|
|
|
266
272
|
addIntrinsics(tameFunctionConstructors());
|
|
267
273
|
|
|
@@ -374,7 +380,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
374
380
|
|
|
375
381
|
// Finally register and optionally freeze all the intrinsics. This
|
|
376
382
|
// must be the operation that modifies the intrinsics.
|
|
377
|
-
|
|
383
|
+
tamedHarden(intrinsics);
|
|
378
384
|
|
|
379
385
|
// Reveal harden after lockdown.
|
|
380
386
|
// Harden is dangerous before lockdown because hardening just
|
|
@@ -384,7 +390,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
384
390
|
// scope signals whether such code should attempt to use harden in the
|
|
385
391
|
// defense of its own API.
|
|
386
392
|
// @ts-ignore harden not yet recognized on globalThis.
|
|
387
|
-
globalThis.harden =
|
|
393
|
+
globalThis.harden = tamedHarden;
|
|
388
394
|
|
|
389
395
|
// Returning `true` indicates that this is a JS to SES transition.
|
|
390
396
|
return true;
|
package/src/make-hardener.js
CHANGED
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
import { assert } from './error/assert.js';
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @typedef {import('../
|
|
55
|
+
* @typedef {import('../types.js').Harden} Harden
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
58
|
// Obtain the string tag accessor of of TypedArray so we can indirectly use the
|
|
@@ -16,9 +16,9 @@ const { Fail } = assert;
|
|
|
16
16
|
* Build the low-level operation used by all evaluators:
|
|
17
17
|
* eval(), Function(), Compartment.prototype.evaluate().
|
|
18
18
|
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
19
|
+
* @param {object} options
|
|
20
|
+
* @param {object} options.globalObject
|
|
21
|
+
* @param {object} [options.moduleLexicals]
|
|
22
22
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
23
23
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
24
24
|
*/
|
|
@@ -53,7 +53,7 @@ export const makeSafeEvaluator = ({
|
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* @param {string} source
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {object} [options]
|
|
57
57
|
* @param {Array<Transform>} [options.localTransforms]
|
|
58
58
|
*/
|
|
59
59
|
const safeEvaluate = (source, { localTransforms = [] } = {}) => {
|
package/src/module-instance.js
CHANGED
|
@@ -136,6 +136,7 @@ export const makeModuleInstance = (
|
|
|
136
136
|
__liveExportMap__: liveExportMap = {},
|
|
137
137
|
__reexportMap__: reexportMap = {},
|
|
138
138
|
__needsImportMeta__: needsImportMeta = false,
|
|
139
|
+
__syncModuleFunctor__,
|
|
139
140
|
} = staticModuleRecord;
|
|
140
141
|
|
|
141
142
|
const compartmentFields = weakmapGet(privateFields, compartment);
|
|
@@ -444,11 +445,16 @@ export const makeModuleInstance = (
|
|
|
444
445
|
activate();
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
let optFunctor
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
448
|
+
let optFunctor;
|
|
449
|
+
if (__syncModuleFunctor__ !== undefined) {
|
|
450
|
+
optFunctor = __syncModuleFunctor__;
|
|
451
|
+
} else {
|
|
452
|
+
optFunctor = compartmentEvaluate(compartmentFields, functorSource, {
|
|
453
|
+
globalObject: compartment.globalThis,
|
|
454
|
+
transforms: __shimTransforms__,
|
|
455
|
+
__moduleShimLexicals__: moduleLexicals,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
452
458
|
let didThrow = false;
|
|
453
459
|
let thrownError;
|
|
454
460
|
function execute() {
|
package/src/module-load.js
CHANGED
|
@@ -319,7 +319,7 @@ export const load = async (
|
|
|
319
319
|
|
|
320
320
|
/** @type {Set<Promise<undefined>>} */
|
|
321
321
|
const pendingJobs = new Set();
|
|
322
|
-
/** @type {Map<
|
|
322
|
+
/** @type {Map<object, Map<string, Promise<Record>>} */
|
|
323
323
|
const moduleLoads = new Map();
|
|
324
324
|
/** @type {Array<Error>} */
|
|
325
325
|
const errors = [];
|
package/src/scope-constants.js
CHANGED
|
@@ -143,8 +143,8 @@ function isImmutableDataProperty(obj, name) {
|
|
|
143
143
|
* service if any of the names are keywords or keyword-like. This is
|
|
144
144
|
* safe and only prevent performance optimization.
|
|
145
145
|
*
|
|
146
|
-
* @param {
|
|
147
|
-
* @param {
|
|
146
|
+
* @param {object} globalObject
|
|
147
|
+
* @param {object} moduleLexicals
|
|
148
148
|
*/
|
|
149
149
|
export const getScopeConstants = (globalObject, moduleLexicals = {}) => {
|
|
150
150
|
// getOwnPropertyNames() does ignore Symbols so we don't need to
|
|
@@ -57,9 +57,8 @@ const scopeProxyHandlerProperties = {
|
|
|
57
57
|
return null;
|
|
58
58
|
},
|
|
59
59
|
|
|
60
|
-
//
|
|
61
|
-
// TODO
|
|
62
|
-
// TODO report as bug to v8 or Chrome, and record issue link here.
|
|
60
|
+
// See https://github.com/endojs/endo/issues/1510
|
|
61
|
+
// TODO: report as bug to v8 or Chrome, and record issue link here.
|
|
63
62
|
getOwnPropertyDescriptor(_target, prop) {
|
|
64
63
|
// Coerce with `String` in case prop is a symbol.
|
|
65
64
|
const quotedProp = q(String(prop));
|
package/src/tame-domains.js
CHANGED
|
@@ -26,6 +26,7 @@ export function tameDomains(domainTaming = 'safe') {
|
|
|
26
26
|
if (domainDescriptor !== undefined && domainDescriptor.get !== undefined) {
|
|
27
27
|
// The domain descriptor on Node.js initially has value: null, which
|
|
28
28
|
// becomes a get, set pair after domains initialize.
|
|
29
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_DOMAINS.md
|
|
29
30
|
throw new TypeError(
|
|
30
31
|
`SES failed to lockdown, Node.js domains have been initialized (SES_NO_DOMAINS)`,
|
|
31
32
|
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
import { TypeError, freeze } from './commons.js';
|
|
3
|
+
|
|
4
|
+
export const tameHarden = (safeHarden, hardenTaming) => {
|
|
5
|
+
if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
|
|
6
|
+
throw new TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (hardenTaming === 'safe') {
|
|
10
|
+
return safeHarden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// In on the joke
|
|
14
|
+
Object.isExtensible = () => false;
|
|
15
|
+
Object.isFrozen = () => true;
|
|
16
|
+
Object.isSealed = () => true;
|
|
17
|
+
Reflect.isExtensible = () => false;
|
|
18
|
+
|
|
19
|
+
const fakeHarden = arg => arg;
|
|
20
|
+
fakeHarden.isFake = true;
|
|
21
|
+
return freeze(fakeHarden);
|
|
22
|
+
};
|
|
23
|
+
freeze(tameHarden);
|
|
@@ -17,14 +17,14 @@ const localePattern = /^(\w*[a-z])Locale([A-Z]\w*)$/;
|
|
|
17
17
|
// behavior or `.prototype` property.
|
|
18
18
|
const tamedMethods = {
|
|
19
19
|
// See https://tc39.es/ecma262/#sec-string.prototype.localecompare
|
|
20
|
-
localeCompare(
|
|
20
|
+
localeCompare(arg) {
|
|
21
21
|
if (this === null || this === undefined) {
|
|
22
22
|
throw new TypeError(
|
|
23
23
|
'Cannot localeCompare with null or undefined "this" value',
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
const s = `${this}`;
|
|
27
|
-
that = `${
|
|
27
|
+
const that = `${arg}`;
|
|
28
28
|
if (s < that) {
|
|
29
29
|
return -1;
|
|
30
30
|
}
|
package/src/transforms.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
stringSearch,
|
|
8
8
|
stringSlice,
|
|
9
9
|
stringSplit,
|
|
10
|
+
freeze,
|
|
10
11
|
} from './commons.js';
|
|
11
12
|
import { getSourceURL } from './get-source-url.js';
|
|
12
13
|
|
|
@@ -69,6 +70,7 @@ export const rejectHtmlComments = src => {
|
|
|
69
70
|
return src;
|
|
70
71
|
}
|
|
71
72
|
const name = getSourceURL(src);
|
|
73
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md
|
|
72
74
|
throw new SyntaxError(
|
|
73
75
|
`Possible HTML comment rejected at ${name}:${lineNumber}. (SES_HTML_COMMENT_REJECTED)`,
|
|
74
76
|
);
|
|
@@ -144,6 +146,7 @@ export const rejectImportExpressions = src => {
|
|
|
144
146
|
return src;
|
|
145
147
|
}
|
|
146
148
|
const name = getSourceURL(src);
|
|
149
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_IMPORT_REJECTED.md
|
|
147
150
|
throw new SyntaxError(
|
|
148
151
|
`Possible import expression rejected at ${name}:${lineNumber}. (SES_IMPORT_REJECTED)`,
|
|
149
152
|
);
|
|
@@ -215,6 +218,7 @@ export const rejectSomeDirectEvalExpressions = src => {
|
|
|
215
218
|
return src;
|
|
216
219
|
}
|
|
217
220
|
const name = getSourceURL(src);
|
|
221
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_EVAL_REJECTED.md
|
|
218
222
|
throw new SyntaxError(
|
|
219
223
|
`Possible direct eval expression rejected at ${name}:${lineNumber}. (SES_EVAL_REJECTED)`,
|
|
220
224
|
);
|
|
@@ -249,3 +253,14 @@ export const applyTransforms = (source, transforms) => {
|
|
|
249
253
|
}
|
|
250
254
|
return source;
|
|
251
255
|
};
|
|
256
|
+
|
|
257
|
+
// export all as a frozen object
|
|
258
|
+
export const transforms = freeze({
|
|
259
|
+
rejectHtmlComments: freeze(rejectHtmlComments),
|
|
260
|
+
evadeHtmlCommentTest: freeze(evadeHtmlCommentTest),
|
|
261
|
+
rejectImportExpressions: freeze(rejectImportExpressions),
|
|
262
|
+
evadeImportExpressionTest: freeze(evadeImportExpressionTest),
|
|
263
|
+
rejectSomeDirectEvalExpressions: freeze(rejectSomeDirectEvalExpressions),
|
|
264
|
+
mandatoryTransforms: freeze(mandatoryTransforms),
|
|
265
|
+
applyTransforms: freeze(applyTransforms),
|
|
266
|
+
});
|
|
@@ -66,8 +66,8 @@ import {
|
|
|
66
66
|
* Removes all non-allowed properties found by recursively and
|
|
67
67
|
* reflectively walking own property chains.
|
|
68
68
|
*
|
|
69
|
-
* @param {
|
|
70
|
-
* @param {(
|
|
69
|
+
* @param {object} intrinsics
|
|
70
|
+
* @param {(object) => void} markVirtualizedNativeFunction
|
|
71
71
|
*/
|
|
72
72
|
export default function whitelistIntrinsics(
|
|
73
73
|
intrinsics,
|
package/src/whitelist.js
CHANGED
|
@@ -1221,6 +1221,10 @@ export const whitelist = {
|
|
|
1221
1221
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1222
1222
|
constructor: '%InertAsyncGeneratorFunction%',
|
|
1223
1223
|
prototype: '%AsyncGeneratorPrototype%',
|
|
1224
|
+
// length prop added here for React Native jsc-android
|
|
1225
|
+
// https://github.com/endojs/endo/issues/660
|
|
1226
|
+
// https://github.com/react-native-community/jsc-android-buildscripts/issues/181
|
|
1227
|
+
length: 'number',
|
|
1224
1228
|
'@@toStringTag': 'string',
|
|
1225
1229
|
},
|
|
1226
1230
|
|
|
@@ -1303,6 +1307,10 @@ export const whitelist = {
|
|
|
1303
1307
|
// Properties of the AsyncFunction Prototype Object
|
|
1304
1308
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1305
1309
|
constructor: '%InertAsyncFunction%',
|
|
1310
|
+
// length prop added here for React Native jsc-android
|
|
1311
|
+
// https://github.com/endojs/endo/issues/660
|
|
1312
|
+
// https://github.com/react-native-community/jsc-android-buildscripts/issues/181
|
|
1313
|
+
length: 'number',
|
|
1306
1314
|
'@@toStringTag': 'string',
|
|
1307
1315
|
},
|
|
1308
1316
|
|
|
@@ -1368,7 +1376,7 @@ export const whitelist = {
|
|
|
1368
1376
|
},
|
|
1369
1377
|
|
|
1370
1378
|
lockdown: fn,
|
|
1371
|
-
harden: fn,
|
|
1379
|
+
harden: { ...fn, isFake: 'boolean' },
|
|
1372
1380
|
|
|
1373
1381
|
'%InitialGetStackString%': fn,
|
|
1374
1382
|
};
|
package/tools.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (C) 2018 Agoric
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { freeze } from './src/commons.js';
|
|
16
|
+
import { transforms } from './src/transforms.js';
|
|
17
|
+
import { strictScopeTerminator } from './src/strict-scope-terminator.js';
|
|
18
|
+
import { createSloppyGlobalsScopeTerminator } from './src/sloppy-globals-scope-terminator.js';
|
|
19
|
+
|
|
20
|
+
export { transforms };
|
|
21
|
+
|
|
22
|
+
export const scopeTerminators = freeze({
|
|
23
|
+
strictScopeTerminator,
|
|
24
|
+
createSloppyGlobalsScopeTerminator,
|
|
25
|
+
});
|
|
@@ -33,6 +33,7 @@ export interface LockdownOptions {
|
|
|
33
33
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
34
34
|
overrideDebug?: Array<string>;
|
|
35
35
|
domainTaming?: 'safe' | 'unsafe';
|
|
36
|
+
__hardenTaming__?: 'safe' | 'unsafe';
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export type Lockdown = (options?: LockdownOptions) => void;
|