ses 1.6.0 → 1.8.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/NEWS.md +18 -1
- package/dist/lockdown.cjs +113 -31
- package/dist/lockdown.mjs +113 -31
- package/dist/lockdown.umd.js +113 -31
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +113 -31
- package/dist/ses.mjs +113 -31
- package/dist/ses.umd.js +113 -31
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +6 -0
- package/package.json +8 -9
- package/src/commons.js +8 -2
- package/src/error/assert.js +1 -0
- package/src/error/tame-console.js +7 -4
- package/src/get-anonymous-intrinsics.js +5 -1
- package/src/lockdown-shim.js +2 -2
- package/src/lockdown.js +13 -0
- package/src/module-load.js +2 -2
- package/src/tame-harden.js +4 -0
- package/src/tame-regenerator-runtime.js +29 -0
- package/types.d.ts +6 -0
package/dist/types.d.cts
CHANGED
|
@@ -33,6 +33,12 @@ export interface RepairOptions {
|
|
|
33
33
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
34
34
|
overrideDebug?: Array<string>;
|
|
35
35
|
domainTaming?: 'safe' | 'unsafe';
|
|
36
|
+
/**
|
|
37
|
+
* safe (default): do nothing.
|
|
38
|
+
*
|
|
39
|
+
* unsafe-ignore: make %IteratorPrototype%[@@iterator] to a funky accessor which ignores all assignments.
|
|
40
|
+
*/
|
|
41
|
+
legacyRegeneratorRuntimeTaming?: 'safe' | 'unsafe-ignore';
|
|
36
42
|
__hardenTaming__?: 'safe' | 'unsafe';
|
|
37
43
|
}
|
|
38
44
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -72,16 +72,15 @@
|
|
|
72
72
|
"lint:types": "tsc",
|
|
73
73
|
"prepare": "npm run clean && npm run build",
|
|
74
74
|
"qt": "ava",
|
|
75
|
-
"test": "tsd && ava"
|
|
76
|
-
"test:platform-compatibility": "node test/package/test.cjs"
|
|
75
|
+
"test": "tsd && ava"
|
|
77
76
|
},
|
|
78
77
|
"dependencies": {
|
|
79
|
-
"@endo/env-options": "^1.1.
|
|
78
|
+
"@endo/env-options": "^1.1.6"
|
|
80
79
|
},
|
|
81
80
|
"devDependencies": {
|
|
82
|
-
"@endo/compartment-mapper": "^1.2.
|
|
83
|
-
"@endo/module-source": "^1.0.
|
|
84
|
-
"@endo/test262-runner": "^0.1.
|
|
81
|
+
"@endo/compartment-mapper": "^1.2.2",
|
|
82
|
+
"@endo/module-source": "^1.0.2",
|
|
83
|
+
"@endo/test262-runner": "^0.1.40",
|
|
85
84
|
"ava": "^6.1.3",
|
|
86
85
|
"babel-eslint": "^10.1.0",
|
|
87
86
|
"c8": "^7.14.0",
|
|
@@ -95,7 +94,7 @@
|
|
|
95
94
|
"sinon": "^15.1.0",
|
|
96
95
|
"terser": "^5.16.6",
|
|
97
96
|
"tsd": "^0.30.7",
|
|
98
|
-
"typescript": "5.
|
|
97
|
+
"typescript": "~5.6.1-rc"
|
|
99
98
|
},
|
|
100
99
|
"files": [
|
|
101
100
|
"LICENSE*",
|
|
@@ -199,5 +198,5 @@
|
|
|
199
198
|
"typeCoverage": {
|
|
200
199
|
"atLeast": 81.17
|
|
201
200
|
},
|
|
202
|
-
"gitHead": "
|
|
201
|
+
"gitHead": "cb060b7e22c92cc951fb03d86cdbceeae82fec34"
|
|
203
202
|
}
|
package/src/commons.js
CHANGED
|
@@ -137,6 +137,10 @@ export const { prototype: generatorPrototype } = getPrototypeOf(
|
|
|
137
137
|
// eslint-disable-next-line no-empty-function, func-names
|
|
138
138
|
function* () {},
|
|
139
139
|
);
|
|
140
|
+
export const iteratorPrototype = getPrototypeOf(
|
|
141
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
142
|
+
getPrototypeOf(arrayPrototype.values()),
|
|
143
|
+
);
|
|
140
144
|
|
|
141
145
|
export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
|
|
142
146
|
|
|
@@ -209,8 +213,10 @@ export const stringReplace = /** @type {any} */ (
|
|
|
209
213
|
);
|
|
210
214
|
export const stringSearch = uncurryThis(stringPrototype.search);
|
|
211
215
|
export const stringSlice = uncurryThis(stringPrototype.slice);
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
export const stringSplit =
|
|
217
|
+
/** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */ (
|
|
218
|
+
uncurryThis(stringPrototype.split)
|
|
219
|
+
);
|
|
214
220
|
export const stringStartsWith = uncurryThis(stringPrototype.startsWith);
|
|
215
221
|
export const iterateString = uncurryThis(stringPrototype[iteratorSymbol]);
|
|
216
222
|
//
|
package/src/error/assert.js
CHANGED
|
@@ -120,8 +120,8 @@ export const tameConsole = (
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
globalProcess.on('uncaughtException', error => {
|
|
123
|
-
//
|
|
124
|
-
ourConsole.error(error);
|
|
123
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
|
|
124
|
+
ourConsole.error('SES_UNCAUGHT_EXCEPTION:', error);
|
|
125
125
|
if (terminate) {
|
|
126
126
|
terminate();
|
|
127
127
|
}
|
|
@@ -133,8 +133,9 @@ export const tameConsole = (
|
|
|
133
133
|
typeof globalProcess.on === 'function'
|
|
134
134
|
) {
|
|
135
135
|
const handleRejection = reason => {
|
|
136
|
-
//
|
|
136
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
|
|
137
137
|
ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
|
|
138
|
+
// 'platform' and 'report' just log the reason.
|
|
138
139
|
};
|
|
139
140
|
// Maybe track unhandled promise rejections.
|
|
140
141
|
const h = makeRejectionHandlers(handleRejection);
|
|
@@ -155,8 +156,9 @@ export const tameConsole = (
|
|
|
155
156
|
) {
|
|
156
157
|
globalWindow.addEventListener('error', event => {
|
|
157
158
|
event.preventDefault();
|
|
159
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNCAUGHT_EXCEPTION.md
|
|
160
|
+
ourConsole.error('SES_UNCAUGHT_EXCEPTION:', event.error);
|
|
158
161
|
// 'platform' and 'report' just log the reason.
|
|
159
|
-
ourConsole.error(event.error);
|
|
160
162
|
if (errorTrapping === 'exit' || errorTrapping === 'abort') {
|
|
161
163
|
globalWindow.location.href = `about:blank`;
|
|
162
164
|
}
|
|
@@ -168,6 +170,7 @@ export const tameConsole = (
|
|
|
168
170
|
typeof globalWindow.addEventListener === 'function'
|
|
169
171
|
) {
|
|
170
172
|
const handleRejection = reason => {
|
|
173
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNHANDLED_REJECTION.md
|
|
171
174
|
ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
|
|
172
175
|
};
|
|
173
176
|
|
|
@@ -142,7 +142,11 @@ export const getAnonymousIntrinsics = () => {
|
|
|
142
142
|
);
|
|
143
143
|
intrinsics['%WrapForValidIteratorPrototype%'] = getPrototypeOf(
|
|
144
144
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
145
|
-
globalThis.Iterator.from({
|
|
145
|
+
globalThis.Iterator.from({
|
|
146
|
+
next() {
|
|
147
|
+
return { value: undefined };
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
146
150
|
);
|
|
147
151
|
}
|
|
148
152
|
|
package/src/lockdown-shim.js
CHANGED
|
@@ -10,7 +10,7 @@ import { repairIntrinsics } from './lockdown.js';
|
|
|
10
10
|
/** @import {LockdownOptions} from '../types.js' */
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param {LockdownOptions} options
|
|
13
|
+
* @param {LockdownOptions} [options]
|
|
14
14
|
*/
|
|
15
15
|
globalThis.lockdown = options => {
|
|
16
16
|
const hardenIntrinsics = repairIntrinsics(options);
|
|
@@ -18,7 +18,7 @@ globalThis.lockdown = options => {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* @param {LockdownOptions} options
|
|
21
|
+
* @param {LockdownOptions} [options]
|
|
22
22
|
*/
|
|
23
23
|
globalThis.repairIntrinsics = options => {
|
|
24
24
|
const hardenIntrinsics = repairIntrinsics(options);
|
package/src/lockdown.js
CHANGED
|
@@ -55,6 +55,7 @@ import { makeCompartmentConstructor } from './compartment.js';
|
|
|
55
55
|
import { tameHarden } from './tame-harden.js';
|
|
56
56
|
import { tameSymbolConstructor } from './tame-symbol-constructor.js';
|
|
57
57
|
import { tameFauxDataProperties } from './tame-faux-data-properties.js';
|
|
58
|
+
import { tameRegeneratorRuntime } from './tame-regenerator-runtime.js';
|
|
58
59
|
|
|
59
60
|
/** @import {LockdownOptions} from '../types.js' */
|
|
60
61
|
|
|
@@ -180,12 +181,20 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
180
181
|
/** @param {string} debugName */
|
|
181
182
|
debugName => debugName !== '',
|
|
182
183
|
),
|
|
184
|
+
legacyRegeneratorRuntimeTaming = getenv(
|
|
185
|
+
'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING',
|
|
186
|
+
'safe',
|
|
187
|
+
),
|
|
183
188
|
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
|
|
184
189
|
dateTaming = 'safe', // deprecated
|
|
185
190
|
mathTaming = 'safe', // deprecated
|
|
186
191
|
...extraOptions
|
|
187
192
|
} = options;
|
|
188
193
|
|
|
194
|
+
legacyRegeneratorRuntimeTaming === 'safe' ||
|
|
195
|
+
legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
|
|
196
|
+
Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
|
|
197
|
+
|
|
189
198
|
evalTaming === 'unsafeEval' ||
|
|
190
199
|
evalTaming === 'safeEval' ||
|
|
191
200
|
evalTaming === 'noEval' ||
|
|
@@ -264,6 +273,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
264
273
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
265
274
|
makeIntrinsicsCollector();
|
|
266
275
|
|
|
276
|
+
// @ts-expect-error __hardenTaming__ could be any string
|
|
267
277
|
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
|
|
268
278
|
addIntrinsics({ harden: tamedHarden });
|
|
269
279
|
|
|
@@ -412,6 +422,9 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
412
422
|
// clear yet which is better.
|
|
413
423
|
// @ts-ignore enablePropertyOverrides does its own input validation
|
|
414
424
|
enablePropertyOverrides(intrinsics, overrideTaming, overrideDebug);
|
|
425
|
+
if (legacyRegeneratorRuntimeTaming === 'unsafe-ignore') {
|
|
426
|
+
tameRegeneratorRuntime();
|
|
427
|
+
}
|
|
415
428
|
|
|
416
429
|
// Finally register and optionally freeze all the intrinsics. This
|
|
417
430
|
// must be the operation that modifies the intrinsics.
|
package/src/module-load.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
weakmapGet,
|
|
22
22
|
weakmapHas,
|
|
23
23
|
} from './commons.js';
|
|
24
|
-
import { makeError, annotateError, q, X } from './error/assert.js';
|
|
24
|
+
import { makeError, annotateError, q, b, X } from './error/assert.js';
|
|
25
25
|
|
|
26
26
|
const noop = () => {};
|
|
27
27
|
|
|
@@ -154,7 +154,7 @@ function* loadWithoutErrorAnnotation(
|
|
|
154
154
|
'importNowHook',
|
|
155
155
|
);
|
|
156
156
|
throw makeError(
|
|
157
|
-
X`${moduleHookName} needed to load module ${q(
|
|
157
|
+
X`${b(moduleHookName)} needed to load module ${q(
|
|
158
158
|
moduleSpecifier,
|
|
159
159
|
)} in compartment ${q(compartment.name)}`,
|
|
160
160
|
);
|
package/src/tame-harden.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
2
|
import { TypeError, freeze } from './commons.js';
|
|
3
3
|
|
|
4
|
+
/** @import {Harden} from '../types.js'; */
|
|
5
|
+
|
|
6
|
+
/** @type {(safeHarden: Harden, hardenTaming: 'safe' | 'unsafe') => Harden} */
|
|
4
7
|
export const tameHarden = (safeHarden, hardenTaming) => {
|
|
5
8
|
if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
|
|
6
9
|
throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
|
|
@@ -16,6 +19,7 @@ export const tameHarden = (safeHarden, hardenTaming) => {
|
|
|
16
19
|
Object.isSealed = () => true;
|
|
17
20
|
Reflect.isExtensible = () => false;
|
|
18
21
|
|
|
22
|
+
// @ts-expect-error secret property
|
|
19
23
|
if (safeHarden.isFake) {
|
|
20
24
|
// The "safe" hardener is already a fake hardener.
|
|
21
25
|
// Just use it.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineProperty,
|
|
3
|
+
iteratorPrototype,
|
|
4
|
+
iteratorSymbol,
|
|
5
|
+
objectHasOwnProperty,
|
|
6
|
+
} from './commons.js';
|
|
7
|
+
|
|
8
|
+
export const tameRegeneratorRuntime = () => {
|
|
9
|
+
const iter = iteratorPrototype[iteratorSymbol];
|
|
10
|
+
defineProperty(iteratorPrototype, iteratorSymbol, {
|
|
11
|
+
configurable: true,
|
|
12
|
+
get() {
|
|
13
|
+
return iter;
|
|
14
|
+
},
|
|
15
|
+
set(value) {
|
|
16
|
+
// ignore the assignment on IteratorPrototype
|
|
17
|
+
if (this === iteratorPrototype) return;
|
|
18
|
+
if (objectHasOwnProperty(this, iteratorSymbol)) {
|
|
19
|
+
this[iteratorSymbol] = value;
|
|
20
|
+
}
|
|
21
|
+
defineProperty(this, iteratorSymbol, {
|
|
22
|
+
value,
|
|
23
|
+
writable: true,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
};
|
package/types.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface RepairOptions {
|
|
|
33
33
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
34
34
|
overrideDebug?: Array<string>;
|
|
35
35
|
domainTaming?: 'safe' | 'unsafe';
|
|
36
|
+
/**
|
|
37
|
+
* safe (default): do nothing.
|
|
38
|
+
*
|
|
39
|
+
* unsafe-ignore: make %IteratorPrototype%[@@iterator] to a funky accessor which ignores all assignments.
|
|
40
|
+
*/
|
|
41
|
+
legacyRegeneratorRuntimeTaming?: 'safe' | 'unsafe-ignore';
|
|
36
42
|
__hardenTaming__?: 'safe' | 'unsafe';
|
|
37
43
|
}
|
|
38
44
|
|