ses 1.11.0 → 1.12.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 +3747 -3649
- package/dist/lockdown.mjs +3747 -3649
- package/dist/lockdown.umd.js +3747 -3649
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +13146 -0
- package/dist/ses.cjs +3747 -3649
- package/dist/ses.mjs +3747 -3649
- package/dist/ses.umd.js +3747 -3649
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +8 -1
- package/package.json +21 -6
- package/src/commons.js +41 -1
- package/src/compartment.js +4 -2
- package/src/get-anonymous-intrinsics.js +23 -18
- package/src/lockdown.js +26 -10
- package/src/strict-scope-terminator.js +1 -2
- package/src/tame-function-constructors.js +9 -5
- package/types.d.ts +8 -1
package/dist/types.d.cts
CHANGED
|
@@ -35,7 +35,14 @@ export interface RepairOptions {
|
|
|
35
35
|
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
|
|
36
36
|
*/
|
|
37
37
|
mathTaming?: 'safe' | 'unsafe';
|
|
38
|
-
evalTaming?:
|
|
38
|
+
evalTaming?:
|
|
39
|
+
| 'safe-eval'
|
|
40
|
+
| 'unsafe-eval'
|
|
41
|
+
| 'no-eval'
|
|
42
|
+
// deprecated
|
|
43
|
+
| 'safeEval'
|
|
44
|
+
| 'unsafeEval'
|
|
45
|
+
| 'noEval';
|
|
39
46
|
stackFiltering?: 'concise' | 'verbose';
|
|
40
47
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
41
48
|
overrideDebug?: Array<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -56,6 +56,12 @@
|
|
|
56
56
|
"default": "./dist/ses.cjs"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
+
"./hermes": {
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/types.d.cts",
|
|
62
|
+
"default": "./dist/ses-hermes.cjs"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
59
65
|
"./tools.js": "./tools.js",
|
|
60
66
|
"./assert-shim.js": "./assert-shim.js",
|
|
61
67
|
"./lockdown-shim.js": {
|
|
@@ -70,7 +76,9 @@
|
|
|
70
76
|
"./package.json": "./package.json"
|
|
71
77
|
},
|
|
72
78
|
"scripts": {
|
|
73
|
-
"build": "node scripts/bundle.js",
|
|
79
|
+
"build:vanilla": "node scripts/bundle.js",
|
|
80
|
+
"build:hermes": "node scripts/bundle.js hermes",
|
|
81
|
+
"build": "yarn build:vanilla && yarn build:hermes",
|
|
74
82
|
"clean": "rm -rf dist",
|
|
75
83
|
"cover": "c8 ava",
|
|
76
84
|
"demo": "python3 -m http.server",
|
|
@@ -81,6 +89,7 @@
|
|
|
81
89
|
"prepare": "npm run clean && npm run build",
|
|
82
90
|
"qt": "ava",
|
|
83
91
|
"test": "tsd && ava",
|
|
92
|
+
"test:hermes": "./scripts/hermes-test.sh",
|
|
84
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",
|
|
85
94
|
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
|
|
86
95
|
},
|
|
@@ -88,9 +97,14 @@
|
|
|
88
97
|
"@endo/env-options": "^1.1.8"
|
|
89
98
|
},
|
|
90
99
|
"devDependencies": {
|
|
91
|
-
"@
|
|
92
|
-
"@
|
|
93
|
-
"@
|
|
100
|
+
"@babel/generator": "^7.26.3",
|
|
101
|
+
"@babel/parser": "~7.26.2",
|
|
102
|
+
"@babel/traverse": "~7.25.9",
|
|
103
|
+
"@babel/types": "~7.26.0",
|
|
104
|
+
"@endo/compartment-mapper": "^1.6.0",
|
|
105
|
+
"@endo/module-source": "^1.3.0",
|
|
106
|
+
"@endo/test262-runner": "^0.1.45",
|
|
107
|
+
"@types/babel__traverse": "^7.20.5",
|
|
94
108
|
"ava": "^6.1.3",
|
|
95
109
|
"babel-eslint": "^10.1.0",
|
|
96
110
|
"c8": "^7.14.0",
|
|
@@ -100,6 +114,7 @@
|
|
|
100
114
|
"eslint-config-prettier": "^9.1.0",
|
|
101
115
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
102
116
|
"eslint-plugin-import": "^2.29.1",
|
|
117
|
+
"hermes-engine-cli": "^0.12.0",
|
|
103
118
|
"prettier": "^3.3.3",
|
|
104
119
|
"terser": "^5.16.6",
|
|
105
120
|
"tsd": "^0.31.2",
|
|
@@ -210,5 +225,5 @@
|
|
|
210
225
|
"typeCoverage": {
|
|
211
226
|
"atLeast": 81.17
|
|
212
227
|
},
|
|
213
|
-
"gitHead": "
|
|
228
|
+
"gitHead": "9b6784831d37db948cdd61f6da1f3489e8f97906"
|
|
214
229
|
}
|
package/src/commons.js
CHANGED
|
@@ -320,7 +320,7 @@ export const FERAL_FUNCTION = Function;
|
|
|
320
320
|
|
|
321
321
|
export const noEvalEvaluate = () => {
|
|
322
322
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
323
|
-
throw TypeError('Cannot eval with evalTaming set to "
|
|
323
|
+
throw TypeError('Cannot eval with evalTaming set to "no-eval" (SES_NO_EVAL)');
|
|
324
324
|
};
|
|
325
325
|
|
|
326
326
|
// ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////
|
|
@@ -380,3 +380,43 @@ export const FERAL_STACK_GETTER = feralStackGetter;
|
|
|
380
380
|
* @type {((newValue: any) => void) | undefined}
|
|
381
381
|
*/
|
|
382
382
|
export const FERAL_STACK_SETTER = feralStackSetter;
|
|
383
|
+
|
|
384
|
+
const getAsyncGeneratorFunctionInstance = () => {
|
|
385
|
+
// Test for async generator function syntax support.
|
|
386
|
+
try {
|
|
387
|
+
// Wrapping one in an new Function lets the `hermesc` binary file
|
|
388
|
+
// parse the Metro js bundle without SyntaxError, to generate the
|
|
389
|
+
// optimised Hermes bytecode bundle, when `gradlew` is called to
|
|
390
|
+
// assemble the release build APK for React Native prod Android apps.
|
|
391
|
+
// Delaying the error until runtime lets us customise lockdown behaviour.
|
|
392
|
+
return new FERAL_FUNCTION(
|
|
393
|
+
'return (async function* AsyncGeneratorFunctionInstance() {})',
|
|
394
|
+
)();
|
|
395
|
+
} catch (error) {
|
|
396
|
+
// Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
|
|
397
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
|
|
398
|
+
if (error.name === 'SyntaxError') {
|
|
399
|
+
// Swallows Hermes error `async generators are unsupported` at runtime.
|
|
400
|
+
// Note: `console` is not a JS built-in, so Hermes engine throws:
|
|
401
|
+
// Uncaught ReferenceError: Property 'console' doesn't exist
|
|
402
|
+
// See: https://github.com/facebook/hermes/issues/675
|
|
403
|
+
// However React Native provides a `console` implementation when setting up error handling:
|
|
404
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
|
|
405
|
+
return undefined;
|
|
406
|
+
} else if (error.name === 'EvalError') {
|
|
407
|
+
// eslint-disable-next-line no-empty-function
|
|
408
|
+
return async function* AsyncGeneratorFunctionInstance() {};
|
|
409
|
+
} else {
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* If the platform supports async generator functions, this will be an
|
|
417
|
+
* async generator function instance. Otherwise, it will be `undefined`.
|
|
418
|
+
*
|
|
419
|
+
* @type {AsyncGeneratorFunction | undefined}
|
|
420
|
+
*/
|
|
421
|
+
export const AsyncGeneratorFunctionInstance =
|
|
422
|
+
getAsyncGeneratorFunctionInstance();
|
package/src/compartment.js
CHANGED
|
@@ -309,6 +309,8 @@ export const makeCompartmentConstructor = (
|
|
|
309
309
|
|
|
310
310
|
const globalObject = {};
|
|
311
311
|
|
|
312
|
+
const compartment = this;
|
|
313
|
+
|
|
312
314
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
313
315
|
|
|
314
316
|
// We must initialize all constant properties first because
|
|
@@ -367,11 +369,11 @@ export const makeCompartmentConstructor = (
|
|
|
367
369
|
`Compartment does not support dynamic import: no configured resolveHook for compartment ${q(name)}`,
|
|
368
370
|
);
|
|
369
371
|
}
|
|
370
|
-
await load(privateFields, moduleAliases,
|
|
372
|
+
await load(privateFields, moduleAliases, compartment, fullSpecifier);
|
|
371
373
|
const { execute, exportsProxy } = link(
|
|
372
374
|
privateFields,
|
|
373
375
|
moduleAliases,
|
|
374
|
-
|
|
376
|
+
compartment,
|
|
375
377
|
fullSpecifier,
|
|
376
378
|
);
|
|
377
379
|
execute();
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
matchAllSymbol,
|
|
15
15
|
regexpPrototype,
|
|
16
16
|
globalThis,
|
|
17
|
+
assign,
|
|
18
|
+
AsyncGeneratorFunctionInstance,
|
|
17
19
|
} from './commons.js';
|
|
18
20
|
import { InertCompartment } from './compartment.js';
|
|
19
21
|
|
|
@@ -95,20 +97,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
95
97
|
|
|
96
98
|
const Generator = GeneratorFunction.prototype;
|
|
97
99
|
|
|
98
|
-
// 25.3.1 The AsyncGeneratorFunction Constructor
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line no-empty-function
|
|
101
|
-
async function* AsyncGeneratorFunctionInstance() {}
|
|
102
|
-
const AsyncGeneratorFunction = getConstructorOf(
|
|
103
|
-
AsyncGeneratorFunctionInstance,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// 25.3.2.2 AsyncGeneratorFunction.prototype
|
|
107
|
-
const AsyncGenerator = AsyncGeneratorFunction.prototype;
|
|
108
|
-
// 25.5.1 Properties of the AsyncGenerator Prototype Object
|
|
109
|
-
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
|
|
110
|
-
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
|
|
111
|
-
|
|
112
100
|
// 25.7.1 The AsyncFunction Constructor
|
|
113
101
|
|
|
114
102
|
// eslint-disable-next-line no-empty-function
|
|
@@ -119,10 +107,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
119
107
|
'%InertFunction%': InertFunction,
|
|
120
108
|
'%ArrayIteratorPrototype%': ArrayIteratorPrototype,
|
|
121
109
|
'%InertAsyncFunction%': AsyncFunction,
|
|
122
|
-
'%AsyncGenerator%': AsyncGenerator,
|
|
123
|
-
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
|
|
124
|
-
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
|
|
125
|
-
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
|
|
126
110
|
'%Generator%': Generator,
|
|
127
111
|
'%InertGeneratorFunction%': GeneratorFunction,
|
|
128
112
|
'%IteratorPrototype%': IteratorPrototype,
|
|
@@ -135,6 +119,27 @@ export const getAnonymousIntrinsics = () => {
|
|
|
135
119
|
'%InertCompartment%': InertCompartment,
|
|
136
120
|
};
|
|
137
121
|
|
|
122
|
+
if (AsyncGeneratorFunctionInstance !== undefined) {
|
|
123
|
+
// 25.3.1 The AsyncGeneratorFunction Constructor
|
|
124
|
+
|
|
125
|
+
const AsyncGeneratorFunction = getConstructorOf(
|
|
126
|
+
AsyncGeneratorFunctionInstance,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// 25.3.2.2 AsyncGeneratorFunction.prototype
|
|
130
|
+
const AsyncGenerator = AsyncGeneratorFunction.prototype;
|
|
131
|
+
// 25.5.1 Properties of the AsyncGenerator Prototype Object
|
|
132
|
+
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
|
|
133
|
+
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
|
|
134
|
+
|
|
135
|
+
assign(intrinsics, {
|
|
136
|
+
'%AsyncGenerator%': AsyncGenerator,
|
|
137
|
+
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
|
|
138
|
+
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
|
|
139
|
+
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
138
143
|
if (globalThis.Iterator) {
|
|
139
144
|
intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
|
|
140
145
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
package/src/lockdown.js
CHANGED
|
@@ -183,7 +183,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
183
183
|
),
|
|
184
184
|
stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
|
|
185
185
|
domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
|
|
186
|
-
evalTaming = getenv('LOCKDOWN_EVAL_TAMING', '
|
|
186
|
+
evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safe-eval'),
|
|
187
187
|
overrideDebug = arrayFilter(
|
|
188
188
|
stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
|
|
189
189
|
/** @param {string} debugName */
|
|
@@ -203,9 +203,12 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
203
203
|
legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
|
|
204
204
|
Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
|
|
205
205
|
|
|
206
|
-
evalTaming === '
|
|
207
|
-
evalTaming === '
|
|
208
|
-
evalTaming === '
|
|
206
|
+
evalTaming === 'unsafe-eval' ||
|
|
207
|
+
evalTaming === 'unsafeEval' || // deprecated
|
|
208
|
+
evalTaming === 'safe-eval' ||
|
|
209
|
+
evalTaming === 'safeEval' || // deprecated
|
|
210
|
+
evalTaming === 'no-eval' ||
|
|
211
|
+
evalTaming === 'noEval' || // deprecated
|
|
209
212
|
Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
|
|
210
213
|
|
|
211
214
|
// Assert that only supported options were passed.
|
|
@@ -408,23 +411,36 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
408
411
|
markVirtualizedNativeFunction,
|
|
409
412
|
});
|
|
410
413
|
|
|
411
|
-
if (
|
|
414
|
+
if (
|
|
415
|
+
evalTaming === 'no-eval' ||
|
|
416
|
+
// deprecated
|
|
417
|
+
evalTaming === 'noEval'
|
|
418
|
+
) {
|
|
412
419
|
setGlobalObjectEvaluators(
|
|
413
420
|
globalThis,
|
|
414
421
|
noEvalEvaluate,
|
|
415
422
|
markVirtualizedNativeFunction,
|
|
416
423
|
);
|
|
417
|
-
} else if (
|
|
424
|
+
} else if (
|
|
425
|
+
evalTaming === 'safe-eval' ||
|
|
426
|
+
// deprecated
|
|
427
|
+
evalTaming === 'safeEval'
|
|
428
|
+
) {
|
|
418
429
|
const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
|
|
419
430
|
setGlobalObjectEvaluators(
|
|
420
431
|
globalThis,
|
|
421
432
|
safeEvaluate,
|
|
422
433
|
markVirtualizedNativeFunction,
|
|
423
434
|
);
|
|
424
|
-
} else if (
|
|
425
|
-
|
|
426
|
-
//
|
|
427
|
-
|
|
435
|
+
} else if (
|
|
436
|
+
evalTaming === 'unsafe-eval' ||
|
|
437
|
+
// deprecated
|
|
438
|
+
evalTaming === 'unsafeEval'
|
|
439
|
+
) {
|
|
440
|
+
// Leave eval function and Function constructor of the initial
|
|
441
|
+
// compartment intact.
|
|
442
|
+
// Other compartments will not have access to these evaluators unless a
|
|
443
|
+
// guest program escapes containment.
|
|
428
444
|
}
|
|
429
445
|
|
|
430
446
|
/**
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
create,
|
|
7
7
|
freeze,
|
|
8
8
|
getOwnPropertyDescriptors,
|
|
9
|
-
globalThis,
|
|
10
9
|
} from './commons.js';
|
|
11
10
|
import { assert } from './error/assert.js';
|
|
12
11
|
|
|
@@ -55,7 +54,7 @@ const scopeProxyHandlerProperties = {
|
|
|
55
54
|
|
|
56
55
|
has(_shadow, prop) {
|
|
57
56
|
// we must at least return true for all properties on the realm globalThis
|
|
58
|
-
return
|
|
57
|
+
return true;
|
|
59
58
|
},
|
|
60
59
|
|
|
61
60
|
// note: this is likely a bug of safari
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getPrototypeOf,
|
|
7
7
|
setPrototypeOf,
|
|
8
8
|
freeze,
|
|
9
|
+
AsyncGeneratorFunctionInstance,
|
|
9
10
|
} from './commons.js';
|
|
10
11
|
|
|
11
12
|
// This module replaces the original `Function` constructor, and the original
|
|
@@ -126,11 +127,14 @@ export default function tameFunctionConstructors() {
|
|
|
126
127
|
'%InertAsyncFunction%',
|
|
127
128
|
'(async function(){})',
|
|
128
129
|
);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
|
|
131
|
+
if (AsyncGeneratorFunctionInstance !== undefined) {
|
|
132
|
+
repairFunction(
|
|
133
|
+
'AsyncGeneratorFunction',
|
|
134
|
+
'%InertAsyncGeneratorFunction%',
|
|
135
|
+
'(async function*(){})',
|
|
136
|
+
);
|
|
137
|
+
}
|
|
134
138
|
|
|
135
139
|
return newIntrinsics;
|
|
136
140
|
}
|
package/types.d.ts
CHANGED
|
@@ -35,7 +35,14 @@ export interface RepairOptions {
|
|
|
35
35
|
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
|
|
36
36
|
*/
|
|
37
37
|
mathTaming?: 'safe' | 'unsafe';
|
|
38
|
-
evalTaming?:
|
|
38
|
+
evalTaming?:
|
|
39
|
+
| 'safe-eval'
|
|
40
|
+
| 'unsafe-eval'
|
|
41
|
+
| 'no-eval'
|
|
42
|
+
// deprecated
|
|
43
|
+
| 'safeEval'
|
|
44
|
+
| 'unsafeEval'
|
|
45
|
+
| 'noEval';
|
|
39
46
|
stackFiltering?: 'concise' | 'verbose';
|
|
40
47
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
41
48
|
overrideDebug?: Array<string>;
|