ses 1.12.0 → 1.13.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/LICENSE +1 -1
- package/SECURITY.md +2 -2
- package/dist/lockdown.cjs +854 -406
- package/dist/lockdown.mjs +854 -406
- package/dist/lockdown.umd.js +854 -406
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +742 -406
- package/dist/ses.cjs +854 -406
- package/dist/ses.mjs +854 -406
- package/dist/ses.umd.js +854 -406
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +14 -5
- package/package.json +11 -10
- package/src/commons.js +3 -1
- package/src/compartment.js +3 -1
- package/src/enablements.js +3 -1
- package/src/error/tame-console.js +0 -4
- package/src/error/tame-error-constructor.js +0 -11
- package/src/error/tame-v8-error-constructor.js +58 -15
- package/src/get-anonymous-intrinsics.js +11 -0
- package/src/lockdown.js +99 -56
- package/src/make-eval-function.js +5 -4
- package/src/make-function-constructor.js +5 -4
- package/src/module-load.js +47 -24
- package/src/permits.js +30 -1
- package/src/reporting.js +1 -4
- package/src/shim-arraybuffer-transfer.js +0 -1
- package/src/tame-domains.js +0 -4
- package/src/tame-harden.js +1 -5
- package/src/tame-locale-methods.js +0 -3
- package/src/tame-regexp-constructor.js +0 -3
- package/types.d.ts +14 -5
package/src/module-load.js
CHANGED
|
@@ -507,18 +507,17 @@ const memoizedLoadWithErrorAnnotation = (
|
|
|
507
507
|
return moduleLoading;
|
|
508
508
|
};
|
|
509
509
|
|
|
510
|
-
const asyncJobQueue = () => {
|
|
510
|
+
const asyncJobQueue = (errors = []) => {
|
|
511
511
|
/** @type {Set<Promise<undefined>>} */
|
|
512
512
|
const pendingJobs = new Set();
|
|
513
|
-
/** @type {Array<Error>} */
|
|
514
|
-
const errors = [];
|
|
515
513
|
|
|
516
514
|
/**
|
|
517
515
|
* Enqueues a job that starts immediately but won't be awaited until drainQueue is called.
|
|
518
516
|
*
|
|
519
|
-
* @template {any[]}
|
|
520
|
-
* @param {
|
|
521
|
-
* @param {
|
|
517
|
+
* @template {(...args: any[]) => Promise<void>} F
|
|
518
|
+
* @param {F} func - An async function to execute
|
|
519
|
+
* @param {Parameters<F>} args - Arguments to pass to the function
|
|
520
|
+
* @returns {void}
|
|
522
521
|
*/
|
|
523
522
|
const enqueueJob = (func, args) => {
|
|
524
523
|
setAdd(
|
|
@@ -530,8 +529,6 @@ const asyncJobQueue = () => {
|
|
|
530
529
|
};
|
|
531
530
|
/**
|
|
532
531
|
* Sequentially awaits pending jobs and returns an array of errors
|
|
533
|
-
*
|
|
534
|
-
* @returns {Promise<Array<Error>>}
|
|
535
532
|
*/
|
|
536
533
|
const drainQueue = async () => {
|
|
537
534
|
await null;
|
|
@@ -539,9 +536,42 @@ const asyncJobQueue = () => {
|
|
|
539
536
|
// eslint-disable-next-line no-await-in-loop
|
|
540
537
|
await job;
|
|
541
538
|
}
|
|
542
|
-
return errors;
|
|
543
539
|
};
|
|
544
|
-
return { enqueueJob, drainQueue };
|
|
540
|
+
return { enqueueJob, drainQueue, errors };
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const syncJobQueue = (errors = []) => {
|
|
544
|
+
let current = [];
|
|
545
|
+
let next = [];
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Enqueues a job
|
|
549
|
+
*
|
|
550
|
+
* @template {(...args: any[]) => void} F
|
|
551
|
+
* @param {F} func - An async function to execute
|
|
552
|
+
* @param {Parameters<F>} args - Arguments to pass to the function
|
|
553
|
+
* @returns {void}
|
|
554
|
+
*/
|
|
555
|
+
const enqueueJob = (func, args) => {
|
|
556
|
+
arrayPush(next, [func, args]);
|
|
557
|
+
};
|
|
558
|
+
const drainQueue = () => {
|
|
559
|
+
// Attention: load bearing flow order. Calling another enqueued function in the
|
|
560
|
+
// synchronous usecase must happen after the one that enqueued it has finished.
|
|
561
|
+
// Jobs enqueued in one pass do not interleave with jobs resulting from them.
|
|
562
|
+
// It's necessary for efficient memoization and to break cycles.
|
|
563
|
+
for (const [func, args] of current) {
|
|
564
|
+
try {
|
|
565
|
+
func(...args);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
arrayPush(errors, error);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
current = next;
|
|
571
|
+
next = [];
|
|
572
|
+
if (current.length > 0) drainQueue();
|
|
573
|
+
};
|
|
574
|
+
return { enqueueJob, drainQueue, errors };
|
|
545
575
|
};
|
|
546
576
|
|
|
547
577
|
/**
|
|
@@ -553,7 +583,8 @@ const throwAggregateError = ({ errors, errorPrefix }) => {
|
|
|
553
583
|
// Throw an aggregate error if there were any errors.
|
|
554
584
|
if (errors.length > 0) {
|
|
555
585
|
const verbose =
|
|
556
|
-
|
|
586
|
+
/** @type {'' | 'verbose'} */
|
|
587
|
+
(getenv('COMPARTMENT_LOAD_ERRORS', '', ['verbose'])) === 'verbose';
|
|
557
588
|
throw TypeError(
|
|
558
589
|
`${errorPrefix} (${errors.length} underlying failures: ${arrayJoin(
|
|
559
590
|
arrayMap(errors, error => error.message + (verbose ? error.stack : '')),
|
|
@@ -587,7 +618,7 @@ export const load = async (
|
|
|
587
618
|
/** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
|
|
588
619
|
const moduleLoads = new Map();
|
|
589
620
|
|
|
590
|
-
const { enqueueJob, drainQueue } = asyncJobQueue();
|
|
621
|
+
const { enqueueJob, drainQueue, errors } = asyncJobQueue();
|
|
591
622
|
|
|
592
623
|
enqueueJob(memoizedLoadWithErrorAnnotation, [
|
|
593
624
|
compartmentPrivateFields,
|
|
@@ -599,8 +630,7 @@ export const load = async (
|
|
|
599
630
|
moduleLoads,
|
|
600
631
|
]);
|
|
601
632
|
|
|
602
|
-
|
|
603
|
-
const errors = await drainQueue();
|
|
633
|
+
await drainQueue();
|
|
604
634
|
|
|
605
635
|
throwAggregateError({
|
|
606
636
|
errors,
|
|
@@ -631,16 +661,7 @@ export const loadNow = (
|
|
|
631
661
|
/** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
|
|
632
662
|
const moduleLoads = new Map();
|
|
633
663
|
|
|
634
|
-
|
|
635
|
-
const errors = [];
|
|
636
|
-
|
|
637
|
-
const enqueueJob = (func, args) => {
|
|
638
|
-
try {
|
|
639
|
-
func(...args);
|
|
640
|
-
} catch (error) {
|
|
641
|
-
arrayPush(errors, error);
|
|
642
|
-
}
|
|
643
|
-
};
|
|
664
|
+
const { enqueueJob, drainQueue, errors } = syncJobQueue();
|
|
644
665
|
|
|
645
666
|
enqueueJob(memoizedLoadWithErrorAnnotation, [
|
|
646
667
|
compartmentPrivateFields,
|
|
@@ -652,6 +673,8 @@ export const loadNow = (
|
|
|
652
673
|
moduleLoads,
|
|
653
674
|
]);
|
|
654
675
|
|
|
676
|
+
drainQueue();
|
|
677
|
+
|
|
655
678
|
throwAggregateError({
|
|
656
679
|
errors,
|
|
657
680
|
errorPrefix: `Failed to load module ${q(moduleSpecifier)} in package ${q(
|
package/src/permits.js
CHANGED
|
@@ -6,12 +6,14 @@ import { arrayPush, arrayForEach } from './commons.js';
|
|
|
6
6
|
/** @import {GenericErrorConstructor} from '../types.js' */
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Exports {@code permits}, a recursively defined
|
|
10
10
|
* JSON record enumerating all intrinsics and their properties
|
|
11
11
|
* according to ECMA specs.
|
|
12
12
|
*
|
|
13
13
|
* @author JF Paradis
|
|
14
14
|
* @author Mark S. Miller
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -1356,6 +1358,33 @@ export const permitted = {
|
|
|
1356
1358
|
// https://github.com/tc39/proposal-arraybuffer-transfer
|
|
1357
1359
|
transferToFixedLength: fn,
|
|
1358
1360
|
detached: getter,
|
|
1361
|
+
// https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
|
|
1362
|
+
// to be proposed
|
|
1363
|
+
transferToImmutable: fn,
|
|
1364
|
+
sliceToImmutable: fn,
|
|
1365
|
+
immutable: getter,
|
|
1366
|
+
},
|
|
1367
|
+
|
|
1368
|
+
// If this exists, it is purely an artifact of how we currently shim
|
|
1369
|
+
// `transferToImmutable`. As natively implemented, there would be no
|
|
1370
|
+
// such extra prototype.
|
|
1371
|
+
'%ImmutableArrayBufferPrototype%': {
|
|
1372
|
+
'[[Proto]]': '%ArrayBufferPrototype%',
|
|
1373
|
+
byteLength: getter,
|
|
1374
|
+
slice: fn,
|
|
1375
|
+
// See https://github.com/tc39/proposal-resizablearraybuffer
|
|
1376
|
+
transfer: fn,
|
|
1377
|
+
resize: fn,
|
|
1378
|
+
resizable: getter,
|
|
1379
|
+
maxByteLength: getter,
|
|
1380
|
+
// https://github.com/tc39/proposal-arraybuffer-transfer
|
|
1381
|
+
transferToFixedLength: fn,
|
|
1382
|
+
detached: getter,
|
|
1383
|
+
// https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
|
|
1384
|
+
// to be proposed
|
|
1385
|
+
transferToImmutable: fn,
|
|
1386
|
+
sliceToImmutable: fn,
|
|
1387
|
+
immutable: getter,
|
|
1359
1388
|
},
|
|
1360
1389
|
|
|
1361
1390
|
// SharedArrayBuffer Objects
|
package/src/reporting.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { functionBind, globalThis } from './commons.js';
|
|
2
2
|
import { assert } from './error/assert.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -51,9 +51,6 @@ export const chooseReporter = reporting => {
|
|
|
51
51
|
if (reporting === 'none') {
|
|
52
52
|
return makeReportPrinter(mute);
|
|
53
53
|
}
|
|
54
|
-
if (reporting !== 'platform' && reporting !== 'console') {
|
|
55
|
-
throw new TypeError(`Invalid lockdown reporting option: ${reporting}`);
|
|
56
|
-
}
|
|
57
54
|
if (
|
|
58
55
|
reporting === 'console' ||
|
|
59
56
|
globalThis.window === globalThis ||
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
} from './commons.js';
|
|
12
12
|
|
|
13
13
|
export const shimArrayBufferTransfer = () => {
|
|
14
|
-
// @ts-expect-error TODO extend ArrayBuffer type to include transfer, etc.
|
|
15
14
|
if (typeof arrayBufferPrototype.transfer === 'function') {
|
|
16
15
|
// Assume already exists so does not need to be shimmed.
|
|
17
16
|
// Such conditional shimming is ok in this case since ArrayBuffer.p.transfer
|
package/src/tame-domains.js
CHANGED
|
@@ -8,10 +8,6 @@ import {
|
|
|
8
8
|
} from './commons.js';
|
|
9
9
|
|
|
10
10
|
export function tameDomains(domainTaming = 'safe') {
|
|
11
|
-
if (domainTaming !== 'safe' && domainTaming !== 'unsafe') {
|
|
12
|
-
throw TypeError(`unrecognized domainTaming ${domainTaming}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
if (domainTaming === 'unsafe') {
|
|
16
12
|
return;
|
|
17
13
|
}
|
package/src/tame-harden.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
|
-
import {
|
|
2
|
+
import { freeze } from './commons.js';
|
|
3
3
|
|
|
4
4
|
/** @import {Harden} from '../types.js'; */
|
|
5
5
|
|
|
6
6
|
/** @type {(safeHarden: Harden, hardenTaming: 'safe' | 'unsafe') => Harden} */
|
|
7
7
|
export const tameHarden = (safeHarden, hardenTaming) => {
|
|
8
|
-
if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
|
|
9
|
-
throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
8
|
if (hardenTaming === 'safe') {
|
|
13
9
|
return safeHarden;
|
|
14
10
|
}
|
|
@@ -44,9 +44,6 @@ const nonLocaleCompare = tamedMethods.localeCompare;
|
|
|
44
44
|
const numberToString = tamedMethods.toString;
|
|
45
45
|
|
|
46
46
|
export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
47
|
-
if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
|
|
48
|
-
throw TypeError(`unrecognized localeTaming ${localeTaming}`);
|
|
49
|
-
}
|
|
50
47
|
if (localeTaming === 'unsafe') {
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
@@ -8,9 +8,6 @@ import {
|
|
|
8
8
|
} from './commons.js';
|
|
9
9
|
|
|
10
10
|
export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
11
|
-
if (regExpTaming !== 'safe' && regExpTaming !== 'unsafe') {
|
|
12
|
-
throw TypeError(`unrecognized regExpTaming ${regExpTaming}`);
|
|
13
|
-
}
|
|
14
11
|
const RegExpPrototype = FERAL_REG_EXP.prototype;
|
|
15
12
|
|
|
16
13
|
const makeRegExpConstructor = (_ = {}) => {
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Types of the SES environment
|
|
3
|
+
* @module
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
/* eslint-disable no-restricted-globals, vars-on-top, no-var */
|
|
@@ -19,6 +20,10 @@
|
|
|
19
20
|
// version of harden.
|
|
20
21
|
export type Harden = <T>(value: T) => T; // not Hardened<T>;
|
|
21
22
|
|
|
23
|
+
// TODO Somehow remove the redundancy between these type deinitions and the
|
|
24
|
+
// inline casts on each call to `getenv` in `lockdown.js`. Hopefully we can
|
|
25
|
+
// keep the type info in those casts so it is easily comparable by eye to
|
|
26
|
+
// the parameters of that call to `genev`.
|
|
22
27
|
export interface RepairOptions {
|
|
23
28
|
regExpTaming?: 'safe' | 'unsafe';
|
|
24
29
|
localeTaming?: 'safe' | 'unsafe';
|
|
@@ -43,7 +48,7 @@ export interface RepairOptions {
|
|
|
43
48
|
| 'safeEval'
|
|
44
49
|
| 'unsafeEval'
|
|
45
50
|
| 'noEval';
|
|
46
|
-
stackFiltering?: 'concise' | 'verbose';
|
|
51
|
+
stackFiltering?: 'concise' | 'omit-frames' | 'shorten-paths' | 'verbose';
|
|
47
52
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
48
53
|
overrideDebug?: Array<string>;
|
|
49
54
|
domainTaming?: 'safe' | 'unsafe';
|
|
@@ -142,10 +147,12 @@ export type ModuleMapHook = (
|
|
|
142
147
|
moduleSpecifier: string,
|
|
143
148
|
) => ModuleDescriptor | undefined;
|
|
144
149
|
export type ImportHook = (moduleSpecifier: string) => Promise<ModuleDescriptor>;
|
|
145
|
-
export type ImportNowHook = (
|
|
150
|
+
export type ImportNowHook = (
|
|
151
|
+
moduleSpecifier: string,
|
|
152
|
+
) => ModuleDescriptor | undefined;
|
|
146
153
|
export type ImportMetaHook = (
|
|
147
154
|
moduleSpecifier: string,
|
|
148
|
-
importMeta:
|
|
155
|
+
importMeta: ImportMeta,
|
|
149
156
|
) => void;
|
|
150
157
|
|
|
151
158
|
export interface CompartmentOptions {
|
|
@@ -576,7 +583,9 @@ declare global {
|
|
|
576
583
|
|
|
577
584
|
evaluate(code: string, options?: CompartmentEvaluateOptions): any;
|
|
578
585
|
|
|
579
|
-
import(
|
|
586
|
+
import(
|
|
587
|
+
specifier: string | null,
|
|
588
|
+
): Promise<{ namespace: ModuleExportsNamespace }>;
|
|
580
589
|
|
|
581
590
|
load(specifier: string): Promise<void>;
|
|
582
591
|
|