ses 0.18.3 → 0.18.4
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 +4 -0
- package/dist/lockdown.cjs +65 -36
- package/dist/lockdown.mjs +65 -36
- package/dist/lockdown.umd.js +65 -36
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +65 -36
- package/dist/ses.mjs +65 -36
- package/dist/ses.umd.js +65 -36
- package/dist/ses.umd.min.js +1 -1
- package/package.json +4 -4
- package/src/commons.js +12 -8
- package/src/compartment-shim.js +1 -5
- package/src/error/tame-v8-error-constructor.js +1 -1
- package/src/eval-scope.js +4 -2
- package/src/get-anonymous-intrinsics.js +2 -4
- package/src/intrinsics.js +4 -1
- package/src/make-hardener.js +7 -0
- package/src/make-safe-evaluator.js +6 -5
- package/src/module-instance.js +3 -2
- package/src/module-load.js +1 -1
- package/src/scope-constants.js +1 -0
- package/src/tame-function-tostring.js +1 -1
- package/src/tame-harden.js +6 -0
- package/src/tame-regexp-constructor.js +10 -1
- package/src/whitelist-intrinsics.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@endo/compartment-mapper": "^0.8.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
63
|
+
"@endo/compartment-mapper": "^0.8.4",
|
|
64
|
+
"@endo/static-module-record": "^0.7.19",
|
|
65
65
|
"@endo/test262-runner": "^0.1.31",
|
|
66
66
|
"ava": "^5.2.0",
|
|
67
67
|
"babel-eslint": "^10.0.3",
|
|
@@ -175,5 +175,5 @@
|
|
|
175
175
|
],
|
|
176
176
|
"timeout": "2m"
|
|
177
177
|
},
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "38c2c59d6ae8c53f84cd333e6c7828e2d37604e2"
|
|
179
179
|
}
|
package/src/commons.js
CHANGED
|
@@ -135,6 +135,7 @@ export const { prototype: promisePrototype } = Promise;
|
|
|
135
135
|
export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
|
|
136
136
|
|
|
137
137
|
const { bind } = functionPrototype;
|
|
138
|
+
|
|
138
139
|
/**
|
|
139
140
|
* uncurryThis()
|
|
140
141
|
* Equivalent of: fn => (thisArg, ...args) => apply(fn, thisArg, args)
|
|
@@ -154,8 +155,8 @@ export const arrayFilter = uncurryThis(arrayPrototype.filter);
|
|
|
154
155
|
export const arrayForEach = uncurryThis(arrayPrototype.forEach);
|
|
155
156
|
export const arrayIncludes = uncurryThis(arrayPrototype.includes);
|
|
156
157
|
export const arrayJoin = uncurryThis(arrayPrototype.join);
|
|
157
|
-
/** @type {<T, U>(thisArg: readonly T[], callbackfn: (value: T, index: number, array: T[]) => U,
|
|
158
|
-
export const arrayMap = uncurryThis(arrayPrototype.map);
|
|
158
|
+
/** @type {<T, U>(thisArg: readonly T[], callbackfn: (value: T, index: number, array: T[]) => U, cbThisArg?: any) => U[]} */
|
|
159
|
+
export const arrayMap = /** @type {any} */ (uncurryThis(arrayPrototype.map));
|
|
159
160
|
export const arrayPop = uncurryThis(arrayPrototype.pop);
|
|
160
161
|
/** @type {<T>(thisArg: T[], ...items: T[]) => number} */
|
|
161
162
|
export const arrayPush = uncurryThis(arrayPrototype.push);
|
|
@@ -186,12 +187,14 @@ export const stringIncludes = uncurryThis(stringPrototype.includes);
|
|
|
186
187
|
export const stringIndexOf = uncurryThis(stringPrototype.indexOf);
|
|
187
188
|
export const stringMatch = uncurryThis(stringPrototype.match);
|
|
188
189
|
/**
|
|
189
|
-
* @type {
|
|
190
|
-
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string)
|
|
190
|
+
* @type { &
|
|
191
|
+
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string) &
|
|
191
192
|
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string) => string)
|
|
192
193
|
* }
|
|
193
194
|
*/
|
|
194
|
-
export const stringReplace =
|
|
195
|
+
export const stringReplace = /** @type {any} */ (
|
|
196
|
+
uncurryThis(stringPrototype.replace)
|
|
197
|
+
);
|
|
195
198
|
export const stringSearch = uncurryThis(stringPrototype.search);
|
|
196
199
|
export const stringSlice = uncurryThis(stringPrototype.slice);
|
|
197
200
|
/** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */
|
|
@@ -200,13 +203,12 @@ export const stringStartsWith = uncurryThis(stringPrototype.startsWith);
|
|
|
200
203
|
export const iterateString = uncurryThis(stringPrototype[iteratorSymbol]);
|
|
201
204
|
//
|
|
202
205
|
export const weakmapDelete = uncurryThis(weakmapPrototype.delete);
|
|
203
|
-
/** @type {<K, V>(thisArg: WeakMap<K, V>, ...args: Parameters<WeakMap<K,V>['get']>) => ReturnType<WeakMap<K,V>['get']>} */
|
|
206
|
+
/** @type {<K extends {}, V>(thisArg: WeakMap<K, V>, ...args: Parameters<WeakMap<K,V>['get']>) => ReturnType<WeakMap<K,V>['get']>} */
|
|
204
207
|
export const weakmapGet = uncurryThis(weakmapPrototype.get);
|
|
205
208
|
export const weakmapHas = uncurryThis(weakmapPrototype.has);
|
|
206
209
|
export const weakmapSet = uncurryThis(weakmapPrototype.set);
|
|
207
210
|
//
|
|
208
211
|
export const weaksetAdd = uncurryThis(weaksetPrototype.add);
|
|
209
|
-
export const weaksetGet = uncurryThis(weaksetPrototype.get);
|
|
210
212
|
export const weaksetHas = uncurryThis(weaksetPrototype.has);
|
|
211
213
|
//
|
|
212
214
|
export const functionToString = uncurryThis(functionPrototype.toString);
|
|
@@ -215,7 +217,9 @@ const { all } = Promise;
|
|
|
215
217
|
export const promiseAll = promises => apply(all, Promise, [promises]);
|
|
216
218
|
export const promiseCatch = uncurryThis(promisePrototype.catch);
|
|
217
219
|
/** @type {<T, TResult1 = T, TResult2 = never>(thisArg: T, onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null) => Promise<TResult1 | TResult2>} */
|
|
218
|
-
export const promiseThen =
|
|
220
|
+
export const promiseThen = /** @type {any} */ (
|
|
221
|
+
uncurryThis(promisePrototype.then)
|
|
222
|
+
);
|
|
219
223
|
//
|
|
220
224
|
export const finalizationRegistryRegister =
|
|
221
225
|
FinalizationRegistry && uncurryThis(FinalizationRegistry.prototype.register);
|
package/src/compartment-shim.js
CHANGED
|
@@ -41,10 +41,6 @@ const moduleAliases = new WeakMap();
|
|
|
41
41
|
// privateFields captures the private state for each compartment.
|
|
42
42
|
const privateFields = new WeakMap();
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {(source: string) => string} Transform
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
44
|
// Compartments do not need an importHook or resolveHook to be useful
|
|
49
45
|
// as a vessel for evaluating programs.
|
|
50
46
|
// However, any method that operates the module system will throw an exception
|
|
@@ -97,7 +93,7 @@ export const CompartmentPrototype = {
|
|
|
97
93
|
/**
|
|
98
94
|
* @param {string} source is a JavaScript program grammar construction.
|
|
99
95
|
* @param {object} [options]
|
|
100
|
-
* @param {Array<Transform>} [options.transforms]
|
|
96
|
+
* @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
|
|
101
97
|
* @param {boolean} [options.sloppyGlobalsMode]
|
|
102
98
|
* @param {object} [options.__moduleShimLexicals__]
|
|
103
99
|
* @param {boolean} [options.__evadeHtmlCommentTest__]
|
|
@@ -207,7 +207,7 @@ export const tameV8ErrorConstructor = (
|
|
|
207
207
|
// Mapping from error instance to the stack for that instance.
|
|
208
208
|
// The stack info is either the structured stack trace
|
|
209
209
|
// or the generated tamed stack string
|
|
210
|
-
/** @type {WeakMap<Error, ParsedStackInfo | StructuredStackInfo} */
|
|
210
|
+
/** @type {WeakMap<Error, ParsedStackInfo | StructuredStackInfo>} */
|
|
211
211
|
const stackInfos = new WeakMap();
|
|
212
212
|
|
|
213
213
|
// Use concise methods to obtain named functions without constructors.
|
package/src/eval-scope.js
CHANGED
|
@@ -72,14 +72,16 @@ export const makeEvalScopeKit = () => {
|
|
|
72
72
|
const evalScopeKit = {
|
|
73
73
|
evalScope,
|
|
74
74
|
allowNextEvalToBeUnsafe() {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const { revoked } = evalScopeKit;
|
|
76
|
+
if (revoked !== null) {
|
|
77
|
+
Fail`a handler did not reset allowNextEvalToBeUnsafe ${revoked.err}`;
|
|
77
78
|
}
|
|
78
79
|
// Allow next reference to eval produce the unsafe FERAL_EVAL.
|
|
79
80
|
// We avoid defineProperty because it consumes an extra stack frame taming
|
|
80
81
|
// its return value.
|
|
81
82
|
defineProperties(evalScope, oneTimeEvalProperties);
|
|
82
83
|
},
|
|
84
|
+
/** @type {null | { err: any }} */
|
|
83
85
|
revoked: null,
|
|
84
86
|
};
|
|
85
87
|
|
|
@@ -45,10 +45,8 @@ export const getAnonymousIntrinsics = () => {
|
|
|
45
45
|
|
|
46
46
|
// 9.2.4.1 %ThrowTypeError%
|
|
47
47
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
'callee',
|
|
51
|
-
).get;
|
|
48
|
+
const argsCalleeDesc = getOwnPropertyDescriptor(makeArguments(), 'callee');
|
|
49
|
+
const ThrowTypeError = argsCalleeDesc && argsCalleeDesc.get;
|
|
52
50
|
|
|
53
51
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
54
52
|
|
package/src/intrinsics.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
TypeError,
|
|
3
3
|
WeakSet,
|
|
4
4
|
arrayFilter,
|
|
5
|
+
create,
|
|
5
6
|
defineProperty,
|
|
6
7
|
entries,
|
|
7
8
|
freeze,
|
|
@@ -34,6 +35,7 @@ function initProperty(obj, name, desc) {
|
|
|
34
35
|
if (objectHasOwnProperty(obj, name)) {
|
|
35
36
|
const preDesc = getOwnPropertyDescriptor(obj, name);
|
|
36
37
|
if (
|
|
38
|
+
!preDesc ||
|
|
37
39
|
!is(preDesc.value, desc.value) ||
|
|
38
40
|
preDesc.get !== desc.get ||
|
|
39
41
|
preDesc.set !== desc.set ||
|
|
@@ -70,7 +72,8 @@ function sampleGlobals(globalObject, newPropertyNames) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export const makeIntrinsicsCollector = () => {
|
|
73
|
-
|
|
75
|
+
/** @type {Record<any, any>} */
|
|
76
|
+
const intrinsics = create(null);
|
|
74
77
|
let pseudoNatives;
|
|
75
78
|
|
|
76
79
|
const addIntrinsics = newIntrinsics => {
|
package/src/make-hardener.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
TypeError,
|
|
28
28
|
WeakMap,
|
|
29
29
|
WeakSet,
|
|
30
|
+
globalThis,
|
|
30
31
|
apply,
|
|
31
32
|
arrayForEach,
|
|
32
33
|
defineProperty,
|
|
@@ -127,6 +128,12 @@ const freezeTypedArray = array => {
|
|
|
127
128
|
* @returns {Harden}
|
|
128
129
|
*/
|
|
129
130
|
export const makeHardener = () => {
|
|
131
|
+
// Use a native hardener if possible.
|
|
132
|
+
if (typeof globalThis.harden === 'function') {
|
|
133
|
+
const safeHarden = globalThis.harden;
|
|
134
|
+
return safeHarden;
|
|
135
|
+
}
|
|
136
|
+
|
|
130
137
|
const hardened = new WeakSet();
|
|
131
138
|
|
|
132
139
|
const { harden } = {
|
|
@@ -19,15 +19,15 @@ const { Fail } = assert;
|
|
|
19
19
|
* @param {object} options
|
|
20
20
|
* @param {object} options.globalObject
|
|
21
21
|
* @param {object} [options.moduleLexicals]
|
|
22
|
-
* @param {Array<Transform>} [options.globalTransforms]
|
|
23
|
-
* @param {
|
|
22
|
+
* @param {Array<import('./lockdown-shim.js').Transform>} [options.globalTransforms]
|
|
23
|
+
* @param {boolean} [options.sloppyGlobalsMode]
|
|
24
24
|
*/
|
|
25
25
|
export const makeSafeEvaluator = ({
|
|
26
26
|
globalObject,
|
|
27
27
|
moduleLexicals = {},
|
|
28
28
|
globalTransforms = [],
|
|
29
29
|
sloppyGlobalsMode = false,
|
|
30
|
-
}
|
|
30
|
+
}) => {
|
|
31
31
|
const scopeTerminator = sloppyGlobalsMode
|
|
32
32
|
? createSloppyGlobalsScopeTerminator(globalObject)
|
|
33
33
|
: strictScopeTerminator;
|
|
@@ -54,9 +54,10 @@ export const makeSafeEvaluator = ({
|
|
|
54
54
|
/**
|
|
55
55
|
* @param {string} source
|
|
56
56
|
* @param {object} [options]
|
|
57
|
-
* @param {Array<Transform>} [options.localTransforms]
|
|
57
|
+
* @param {Array<import('./lockdown-shim.js').Transform>} [options.localTransforms]
|
|
58
58
|
*/
|
|
59
|
-
const safeEvaluate = (source,
|
|
59
|
+
const safeEvaluate = (source, options) => {
|
|
60
|
+
const { localTransforms = [] } = options || {};
|
|
60
61
|
provideEvaluate();
|
|
61
62
|
|
|
62
63
|
// Execute the mandatory transforms last to ensure that any rewritten code
|
package/src/module-instance.js
CHANGED
|
@@ -189,6 +189,7 @@ export const makeModuleInstance = (
|
|
|
189
189
|
// fixed binding state
|
|
190
190
|
let value;
|
|
191
191
|
let tdz = true;
|
|
192
|
+
/** @type {null | Array<(value: any) => void>} */
|
|
192
193
|
let optUpdaters = [];
|
|
193
194
|
|
|
194
195
|
// tdz sensitive getter
|
|
@@ -214,7 +215,7 @@ export const makeModuleInstance = (
|
|
|
214
215
|
const updaters = optUpdaters;
|
|
215
216
|
optUpdaters = null;
|
|
216
217
|
tdz = false;
|
|
217
|
-
for (const updater of updaters) {
|
|
218
|
+
for (const updater of updaters || []) {
|
|
218
219
|
updater(initValue);
|
|
219
220
|
}
|
|
220
221
|
return initValue;
|
|
@@ -228,7 +229,7 @@ export const makeModuleInstance = (
|
|
|
228
229
|
return;
|
|
229
230
|
}
|
|
230
231
|
if (tdz) {
|
|
231
|
-
arrayPush(optUpdaters, updater);
|
|
232
|
+
arrayPush(optUpdaters || [], updater);
|
|
232
233
|
} else {
|
|
233
234
|
updater(value);
|
|
234
235
|
}
|
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<object, Map<string, Promise<Record
|
|
322
|
+
/** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
|
|
323
323
|
const moduleLoads = new Map();
|
|
324
324
|
/** @type {Array<Error>} */
|
|
325
325
|
const errors = [];
|
package/src/scope-constants.js
CHANGED
|
@@ -115,6 +115,7 @@ export const isValidIdentifierName = name => {
|
|
|
115
115
|
function isImmutableDataProperty(obj, name) {
|
|
116
116
|
const desc = getOwnPropertyDescriptor(obj, name);
|
|
117
117
|
return (
|
|
118
|
+
desc &&
|
|
118
119
|
//
|
|
119
120
|
// The getters will not have .writable, don't let the falsyness of
|
|
120
121
|
// 'undefined' trick us: test with === false, not ! . However descriptors
|
|
@@ -27,7 +27,7 @@ export const tameFunctionToString = () => {
|
|
|
27
27
|
|
|
28
28
|
const tamingMethods = {
|
|
29
29
|
toString() {
|
|
30
|
-
const str = functionToString(this
|
|
30
|
+
const str = functionToString(this);
|
|
31
31
|
if (
|
|
32
32
|
stringEndsWith(str, nativeSuffix) ||
|
|
33
33
|
!weaksetHas(virtualizedNativeFunctions, this)
|
package/src/tame-harden.js
CHANGED
|
@@ -16,6 +16,12 @@ export const tameHarden = (safeHarden, hardenTaming) => {
|
|
|
16
16
|
Object.isSealed = () => true;
|
|
17
17
|
Reflect.isExtensible = () => false;
|
|
18
18
|
|
|
19
|
+
if (safeHarden.isFake) {
|
|
20
|
+
// The "safe" hardener is already a fake hardener.
|
|
21
|
+
// Just use it.
|
|
22
|
+
return safeHarden;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
const fakeHarden = arg => arg;
|
|
20
26
|
fakeHarden.isFake = true;
|
|
21
27
|
return freeze(fakeHarden);
|
|
@@ -15,6 +15,9 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
15
15
|
|
|
16
16
|
const makeRegExpConstructor = (_ = {}) => {
|
|
17
17
|
// RegExp has non-writable static properties we need to omit.
|
|
18
|
+
/**
|
|
19
|
+
* @param {Parameters<typeof FERAL_REG_EXP>} rest
|
|
20
|
+
*/
|
|
18
21
|
const ResultRegExp = function RegExp(...rest) {
|
|
19
22
|
if (new.target === undefined) {
|
|
20
23
|
return FERAL_REG_EXP(...rest);
|
|
@@ -22,6 +25,11 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
22
25
|
return construct(FERAL_REG_EXP, rest, new.target);
|
|
23
26
|
};
|
|
24
27
|
|
|
28
|
+
const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
|
|
29
|
+
if (!speciesDesc) {
|
|
30
|
+
throw new TypeError('no RegExp[Symbol.species] descriptor');
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
defineProperties(ResultRegExp, {
|
|
26
34
|
length: { value: 2 },
|
|
27
35
|
prototype: {
|
|
@@ -30,7 +38,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
30
38
|
enumerable: false,
|
|
31
39
|
configurable: false,
|
|
32
40
|
},
|
|
33
|
-
[speciesSymbol]:
|
|
41
|
+
[speciesSymbol]: speciesDesc,
|
|
34
42
|
});
|
|
35
43
|
return ResultRegExp;
|
|
36
44
|
};
|
|
@@ -39,6 +47,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
39
47
|
const SharedRegExp = makeRegExpConstructor();
|
|
40
48
|
|
|
41
49
|
if (regExpTaming !== 'unsafe') {
|
|
50
|
+
// @ts-expect-error Deleted properties must be optional
|
|
42
51
|
delete RegExpPrototype.compile;
|
|
43
52
|
}
|
|
44
53
|
defineProperties(RegExpPrototype, {
|
|
@@ -212,6 +212,9 @@ export default function whitelistIntrinsics(
|
|
|
212
212
|
*/
|
|
213
213
|
function isAllowedProperty(path, obj, prop, permit) {
|
|
214
214
|
const desc = getOwnPropertyDescriptor(obj, prop);
|
|
215
|
+
if (!desc) {
|
|
216
|
+
throw new TypeError(`Property ${prop} not found at ${path}`);
|
|
217
|
+
}
|
|
215
218
|
|
|
216
219
|
// Is this a value property?
|
|
217
220
|
if (objectHasOwnProperty(desc, 'value')) {
|