ses 1.9.0 → 1.10.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/README.md +3 -1
- package/dist/lockdown.cjs +592 -348
- package/dist/lockdown.mjs +592 -348
- package/dist/lockdown.umd.js +592 -348
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +592 -348
- package/dist/ses.mjs +592 -348
- package/dist/ses.umd.js +592 -348
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +2 -1
- package/package.json +8 -8
- package/src/cauterize-property.js +69 -0
- package/src/compartment-shim.js +7 -3
- package/src/enable-property-overrides.js +6 -3
- package/src/enablements.js +1 -1
- package/src/error/README.md +2 -2
- package/src/error/assert.js +1 -0
- package/src/error/console.js +13 -10
- package/src/error/internal-types.js +5 -1
- package/src/error/note-log-args.js +4 -1
- package/src/error/tame-console.js +5 -2
- package/src/error/tame-v8-error-constructor.js +3 -3
- package/src/global-object.js +1 -1
- package/src/intrinsics.js +27 -9
- package/src/lockdown.js +34 -10
- package/src/module-link.js +6 -8
- package/src/module-load.js +17 -6
- package/src/permits-intrinsics.js +19 -62
- package/src/permits.js +12 -10
- package/src/reporting-types.d.ts +13 -0
- package/src/reporting.js +106 -0
- package/src/tame-symbol-constructor.js +2 -2
- package/types.d.ts +2 -1
package/dist/types.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @module Types of the SES environment
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/* eslint-disable no-restricted-globals, vars-on-top, no-var */
|
|
@@ -24,6 +24,7 @@ export interface RepairOptions {
|
|
|
24
24
|
localeTaming?: 'safe' | 'unsafe';
|
|
25
25
|
consoleTaming?: 'safe' | 'unsafe';
|
|
26
26
|
errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
|
|
27
|
+
reporting?: 'platform' | 'console' | 'none';
|
|
27
28
|
unhandledRejectionTrapping?: 'report' | 'none';
|
|
28
29
|
errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
|
|
29
30
|
dateTaming?: 'safe' | 'unsafe'; // deprecated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@endo/env-options": "^1.1.
|
|
81
|
+
"@endo/env-options": "^1.1.8"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@endo/compartment-mapper": "^1.
|
|
85
|
-
"@endo/module-source": "^1.1.
|
|
86
|
-
"@endo/test262-runner": "^0.1.
|
|
84
|
+
"@endo/compartment-mapper": "^1.4.0",
|
|
85
|
+
"@endo/module-source": "^1.1.2",
|
|
86
|
+
"@endo/test262-runner": "^0.1.43",
|
|
87
87
|
"ava": "^6.1.3",
|
|
88
88
|
"babel-eslint": "^10.1.0",
|
|
89
89
|
"c8": "^7.14.0",
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"eslint-config-prettier": "^9.1.0",
|
|
94
94
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
95
95
|
"eslint-plugin-import": "^2.29.1",
|
|
96
|
-
"prettier": "^3.
|
|
96
|
+
"prettier": "^3.3.3",
|
|
97
97
|
"terser": "^5.16.6",
|
|
98
98
|
"tsd": "^0.31.2",
|
|
99
|
-
"typescript": "~5.6.
|
|
99
|
+
"typescript": "~5.6.3"
|
|
100
100
|
},
|
|
101
101
|
"files": [
|
|
102
102
|
"./*.d.ts",
|
|
@@ -203,5 +203,5 @@
|
|
|
203
203
|
"typeCoverage": {
|
|
204
204
|
"atLeast": 81.17
|
|
205
205
|
},
|
|
206
|
-
"gitHead": "
|
|
206
|
+
"gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
|
|
207
207
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { objectHasOwnProperty } from './commons.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @import {Reporter} from './reporting-types.js'
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Delete `obj[prop]` or at least make it harmless.
|
|
9
|
+
*
|
|
10
|
+
* If the property was not expected, then emit a reporter-dependent warning
|
|
11
|
+
* to bring attention to this case, so someone can determine what to do with it.
|
|
12
|
+
*
|
|
13
|
+
* If the property to be deleted is a function's `.prototype` property, this
|
|
14
|
+
* will normally be because the function was supposed to be a
|
|
15
|
+
* - builtin method or non-constructor function
|
|
16
|
+
* - arrow function
|
|
17
|
+
* - concise method
|
|
18
|
+
*
|
|
19
|
+
* all of whom are not supposed to have a `.prototype` property. Nevertheless,
|
|
20
|
+
* on some platforms (like older versions of Hermes), or as a result of
|
|
21
|
+
* some shim-based mods to the primordials (like core-js?), some of these
|
|
22
|
+
* functions may accidentally be more like `function` functions with
|
|
23
|
+
* an undeletable `.prototype` property. In these cases, if we can
|
|
24
|
+
* set the value of that bogus `.prototype` property to `undefined`,
|
|
25
|
+
* we do so, issuing a warning, rather than failing to initialize ses.
|
|
26
|
+
*
|
|
27
|
+
* @param {object} obj
|
|
28
|
+
* @param {PropertyKey} prop
|
|
29
|
+
* @param {boolean} known If deletion is expected, don't warn
|
|
30
|
+
* @param {string} subPath Used for warning messages
|
|
31
|
+
* @param {Reporter} reporter Where to issue warning or error.
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
export const cauterizeProperty = (
|
|
35
|
+
obj,
|
|
36
|
+
prop,
|
|
37
|
+
known,
|
|
38
|
+
subPath,
|
|
39
|
+
{ warn, error },
|
|
40
|
+
) => {
|
|
41
|
+
// Either the object lacks a permit or the object doesn't match the
|
|
42
|
+
// permit.
|
|
43
|
+
// If the permit is specifically false, not merely undefined,
|
|
44
|
+
// this is a property we expect to see because we know it exists in
|
|
45
|
+
// some environments and we have expressly decided to exclude it.
|
|
46
|
+
// Any other disallowed property is one we have not audited and we log
|
|
47
|
+
// that we are removing it so we know to look into it, as happens when
|
|
48
|
+
// the language evolves new features to existing intrinsics.
|
|
49
|
+
if (!known) {
|
|
50
|
+
warn(`Removing ${subPath}`);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
delete obj[prop];
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (objectHasOwnProperty(obj, prop)) {
|
|
56
|
+
if (typeof obj === 'function' && prop === 'prototype') {
|
|
57
|
+
obj.prototype = undefined;
|
|
58
|
+
if (obj.prototype === undefined) {
|
|
59
|
+
warn(`Tolerating undeletable ${subPath} === undefined`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
error(`failed to delete ${subPath}`, err);
|
|
64
|
+
} else {
|
|
65
|
+
error(`deleting ${subPath} threw`, err);
|
|
66
|
+
}
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
};
|
package/src/compartment-shim.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
/// <reference types="ses"/>
|
|
2
|
-
|
|
3
1
|
import { globalThis } from './commons.js';
|
|
4
2
|
import { makeCompartmentConstructor } from './compartment.js';
|
|
5
3
|
import { tameFunctionToString } from './tame-function-tostring.js';
|
|
6
4
|
import { getGlobalIntrinsics } from './intrinsics.js';
|
|
5
|
+
import { chooseReporter } from './reporting.js';
|
|
7
6
|
|
|
8
7
|
const markVirtualizedNativeFunction = tameFunctionToString();
|
|
9
8
|
|
|
9
|
+
const muteReporter = chooseReporter('none');
|
|
10
|
+
|
|
10
11
|
// @ts-ignore Compartment is definitely on globalThis.
|
|
11
12
|
globalThis.Compartment = makeCompartmentConstructor(
|
|
12
13
|
makeCompartmentConstructor,
|
|
13
|
-
|
|
14
|
+
// Any reporting that would need to be done should have already been done
|
|
15
|
+
// during `lockdown()`.
|
|
16
|
+
// See https://github.com/endojs/endo/pull/2624#discussion_r1840979770
|
|
17
|
+
getGlobalIntrinsics(globalThis, muteReporter),
|
|
14
18
|
markVirtualizedNativeFunction,
|
|
15
19
|
);
|
|
@@ -23,8 +23,10 @@ import {
|
|
|
23
23
|
severeEnablements,
|
|
24
24
|
} from './enablements.js';
|
|
25
25
|
|
|
26
|
+
/** @import {Reporter} from './reporting-types.js' */
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
|
-
* For a special set of properties defined in the `enablement`
|
|
29
|
+
* For a special set of properties defined in the `enablement` list,
|
|
28
30
|
* `enablePropertyOverrides` ensures that the effect of freezing does not
|
|
29
31
|
* suppress the ability to override these properties on derived objects by
|
|
30
32
|
* simple assignment.
|
|
@@ -75,11 +77,13 @@ import {
|
|
|
75
77
|
*
|
|
76
78
|
* @param {Record<string, any>} intrinsics
|
|
77
79
|
* @param {'min' | 'moderate' | 'severe'} overrideTaming
|
|
80
|
+
* @param {Reporter} reporter
|
|
78
81
|
* @param {Iterable<string | symbol>} [overrideDebug]
|
|
79
82
|
*/
|
|
80
83
|
export default function enablePropertyOverrides(
|
|
81
84
|
intrinsics,
|
|
82
85
|
overrideTaming,
|
|
86
|
+
{ warn },
|
|
83
87
|
overrideDebug = [],
|
|
84
88
|
) {
|
|
85
89
|
const debugProperties = new Set(overrideDebug);
|
|
@@ -109,8 +113,7 @@ export default function enablePropertyOverrides(
|
|
|
109
113
|
this[prop] = newValue;
|
|
110
114
|
} else {
|
|
111
115
|
if (isDebug) {
|
|
112
|
-
|
|
113
|
-
console.error(TypeError(`Override property ${prop}`));
|
|
116
|
+
warn(TypeError(`Override property ${prop}`));
|
|
114
117
|
}
|
|
115
118
|
defineProperty(this, prop, {
|
|
116
119
|
value: newValue,
|
package/src/enablements.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toStringTagSymbol, iteratorSymbol } from './commons.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
4
|
+
* @module Exports {@code enablements}, a recursively defined
|
|
5
5
|
* JSON record defining the optimum set of intrinsics properties
|
|
6
6
|
* that need to be "repaired" before hardening is applied on
|
|
7
7
|
* enviromments subject to the override mistake.
|
package/src/error/README.md
CHANGED
|
@@ -62,9 +62,9 @@ Before repair or `lockdown`, we assume there is some prior "system" console boun
|
|
|
62
62
|
|
|
63
63
|
The default `{ consoleTaming: 'safe' }` setting replaces the system console with a root console that does use all these side tables to generate a more informative log. This root console wraps the prior system console. This root console outputs its log information only by invoking this wrapped system console, which therefore determines how this log information is made available to the external world. To support determinism, we will also need to support a no-op console setting, as explained at [deterministic handling of adversarial code calling console.log with a Proxy #1852](https://github.com/Agoric/agoric-sdk/issues/1852) and [Need no-op console setting for determinism #487](https://github.com/Agoric/SES-shim/issues/487).
|
|
64
64
|
|
|
65
|
-
SES considers both `assert` and `console` to be powerful objects, appearing initially in the start compartment, and not
|
|
65
|
+
SES considers both `assert` and `console` to be powerful objects, appearing initially in the start compartment, and not permitted for implicit propagation to created compartments. Rather, we recommend an endowment pattern where the global `assert` is passed forward as-is, but only filtered forms of the `console` are. As compartments create each other in a tree, they create a corresponding filtering tree of consoles. Information sent to any compartment's console is then sent up the filtering tree. Only information that survives all the filters in its path arrive at the root console, producing log output. The others have no effect. Given the expected pattern of a compartment per package, the per-compartment console filter is effectly a topic filter, treating the package identity as a topic. We plan to also support coordinated stack-frame filters, as explained at [Need source-prefix-based stackframe filter #488](https://github.com/Agoric/SES-shim/issues/488).
|
|
66
66
|
|
|
67
|
-
For security and determinism, we normally reason from the *in-band frame of reference* where the console logging output does not exist, is not an effect, and `console` operations are write-only. Within this frame of reference, the `assert` and `console` powers are not very powerful. They are almost as safe as the
|
|
67
|
+
For security and determinism, we normally reason from the *in-band frame of reference* where the console logging output does not exist, is not an effect, and `console` operations are write-only. Within this frame of reference, the `assert` and `console` powers are not very powerful. They are almost as safe as the permitted, powerless, shared primordials, which is why we're willing to recommend this endowment pattern be habitual.
|
|
68
68
|
|
|
69
69
|
## Hiding and Revealing Distributed Diagnostic Information
|
|
70
70
|
|
package/src/error/assert.js
CHANGED
|
@@ -48,6 +48,7 @@ import { makeNoteLogArgsArrayKit } from './note-log-args.js';
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* @import {BaseAssert, Assert, AssertionFunctions, AssertionUtilities, StringablePayload, DetailsToken, MakeAssert} from '../../types.js'
|
|
51
|
+
* @import {LogArgs, NoteCallback, LoggedErrorHandler} from "./internal-types.js";
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
// For our internal debugging purposes, uncomment
|
package/src/error/console.js
CHANGED
|
@@ -22,13 +22,16 @@ import {
|
|
|
22
22
|
weaksetAdd,
|
|
23
23
|
weaksetHas,
|
|
24
24
|
} from '../commons.js';
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @import {FilterConsole, LogSeverity, VirtualConsole} from './types.js'
|
|
28
|
+
* @import {ErrorInfo, ErrorInfoKind, LogRecord, NoteCallback, LoggedErrorHandler, MakeCausalConsole, MakeLoggingConsoleKit} from "./internal-types.js";
|
|
29
|
+
*/
|
|
27
30
|
|
|
28
31
|
// For our internal debugging purposes, uncomment
|
|
29
32
|
// const internalDebugConsole = console;
|
|
30
33
|
|
|
31
|
-
// The
|
|
34
|
+
// The permitted console methods, from:
|
|
32
35
|
// Whatwg "living standard" https://console.spec.whatwg.org/
|
|
33
36
|
// Node https://nodejs.org/dist/latest-v14.x/docs/api/console.html
|
|
34
37
|
// MDN https://developer.mozilla.org/en-US/docs/Web/API/Console_API
|
|
@@ -107,7 +110,7 @@ export const consoleOtherMethods = freeze([
|
|
|
107
110
|
]);
|
|
108
111
|
|
|
109
112
|
/** @type {readonly [ConsoleProps, LogSeverity | undefined][]} */
|
|
110
|
-
const
|
|
113
|
+
const consoleMethodPermits = freeze([
|
|
111
114
|
...consoleLevelMethods,
|
|
112
115
|
...consoleOtherMethods,
|
|
113
116
|
]);
|
|
@@ -115,8 +118,8 @@ const consoleWhitelist = freeze([
|
|
|
115
118
|
/**
|
|
116
119
|
* consoleOmittedProperties is currently unused. I record and maintain it here
|
|
117
120
|
* with the intention that it be treated like the `false` entries in the main
|
|
118
|
-
* SES
|
|
119
|
-
* seeing anything else that's outside the
|
|
121
|
+
* SES permits: that seeing these on the original console is expected, but
|
|
122
|
+
* seeing anything else that's outside the permits is surprising and should
|
|
120
123
|
* provide a diagnostic.
|
|
121
124
|
*
|
|
122
125
|
* const consoleOmittedProperties = freeze([
|
|
@@ -155,7 +158,7 @@ export const makeLoggingConsoleKit = (
|
|
|
155
158
|
let logArray = [];
|
|
156
159
|
|
|
157
160
|
const loggingConsole = fromEntries(
|
|
158
|
-
arrayMap(
|
|
161
|
+
arrayMap(consoleMethodPermits, ([name, _]) => {
|
|
159
162
|
// Use an arrow function so that it doesn't come with its own name in
|
|
160
163
|
// its printed form. Instead, we're hoping that tooling uses only
|
|
161
164
|
// the `.name` property set below.
|
|
@@ -505,11 +508,11 @@ freeze(defineCausalConsoleFromLogger);
|
|
|
505
508
|
/** @type {FilterConsole} */
|
|
506
509
|
export const filterConsole = (baseConsole, filter, _topic = undefined) => {
|
|
507
510
|
// TODO do something with optional topic string
|
|
508
|
-
const
|
|
509
|
-
|
|
511
|
+
const methodPermits = arrayFilter(
|
|
512
|
+
consoleMethodPermits,
|
|
510
513
|
([name, _]) => name in baseConsole,
|
|
511
514
|
);
|
|
512
|
-
const methods = arrayMap(
|
|
515
|
+
const methods = arrayMap(methodPermits, ([name, severity]) => {
|
|
513
516
|
/**
|
|
514
517
|
* @param {...any} args
|
|
515
518
|
*/
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @import {VirtualConsole} from './types.js'
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* @typedef {readonly any[]} LogArgs
|
|
5
9
|
*
|
|
@@ -58,7 +62,7 @@
|
|
|
58
62
|
/**
|
|
59
63
|
* @callback MakeLoggingConsoleKit
|
|
60
64
|
*
|
|
61
|
-
* A logging console just accumulates the contents of all
|
|
65
|
+
* A logging console just accumulates the contents of all permitted calls,
|
|
62
66
|
* making them available to callers of `takeLog()`. Calling `takeLog()`
|
|
63
67
|
* consumes these, so later calls to `takeLog()` will only provide a log of
|
|
64
68
|
* calls that have happened since then.
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
/* eslint-disable no-restricted-globals */
|
|
4
4
|
|
|
5
5
|
import { makeLRUCacheMap } from '../make-lru-cachemap.js';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import {LogArgs} from './internal-types.js';
|
|
9
|
+
*/
|
|
7
10
|
|
|
8
11
|
const { freeze } = Object;
|
|
9
12
|
const { isSafeInteger } = Number;
|
|
@@ -11,8 +11,11 @@ import {
|
|
|
11
11
|
import { loggedErrorHandler as defaultHandler } from './assert.js';
|
|
12
12
|
import { makeCausalConsole } from './console.js';
|
|
13
13
|
import { makeRejectionHandlers } from './unhandled-rejection.js';
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @import {VirtualConsole} from './types.js'
|
|
17
|
+
* @import {GetStackString} from './internal-types.js';
|
|
18
|
+
*/
|
|
16
19
|
|
|
17
20
|
const failFast = message => {
|
|
18
21
|
throw TypeError(message);
|
|
@@ -19,8 +19,8 @@ import {
|
|
|
19
19
|
TypeError,
|
|
20
20
|
} from '../commons.js';
|
|
21
21
|
|
|
22
|
-
//
|
|
23
|
-
//
|
|
22
|
+
// Permit names from https://v8.dev/docs/stack-trace-api
|
|
23
|
+
// Permiting only the names used by error-stack-shim/src/v8StackFrames
|
|
24
24
|
// callSiteToFrame to shim the error stack proposal.
|
|
25
25
|
const safeV8CallSiteMethodNames = [
|
|
26
26
|
// suppress 'getThis' definitely
|
|
@@ -45,7 +45,7 @@ const safeV8CallSiteMethodNames = [
|
|
|
45
45
|
'getPosition',
|
|
46
46
|
'getScriptNameOrSourceURL',
|
|
47
47
|
|
|
48
|
-
'toString', // TODO replace to use only
|
|
48
|
+
'toString', // TODO replace to use only permitted info
|
|
49
49
|
];
|
|
50
50
|
|
|
51
51
|
// TODO this is a ridiculously expensive way to attenuate callsites.
|
package/src/global-object.js
CHANGED
|
@@ -121,7 +121,7 @@ export const setGlobalObjectMutableProperties = (
|
|
|
121
121
|
),
|
|
122
122
|
);
|
|
123
123
|
|
|
124
|
-
// TODO These should still be tamed according to the
|
|
124
|
+
// TODO These should still be tamed according to the permits before
|
|
125
125
|
// being made available.
|
|
126
126
|
for (const [name, value] of entries(perCompartmentGlobals)) {
|
|
127
127
|
defineProperty(globalObject, name, {
|
package/src/intrinsics.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cauterizeProperty } from './cauterize-property.js';
|
|
1
2
|
import {
|
|
2
3
|
TypeError,
|
|
3
4
|
WeakSet,
|
|
@@ -23,12 +24,16 @@ import {
|
|
|
23
24
|
permitted,
|
|
24
25
|
} from './permits.js';
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @import {Reporter} from './reporting-types.js'
|
|
29
|
+
*/
|
|
30
|
+
|
|
26
31
|
const isFunction = obj => typeof obj === 'function';
|
|
27
32
|
|
|
28
33
|
// Like defineProperty, but throws if it would modify an existing property.
|
|
29
34
|
// We use this to ensure that two conflicting attempts to define the same
|
|
30
35
|
// property throws, causing SES initialization to fail. Otherwise, a
|
|
31
|
-
// conflict between, for example, two of SES's internal
|
|
36
|
+
// conflict between, for example, two of SES's internal permits might
|
|
32
37
|
// get masked as one overwrites the other. Accordingly, the thrown error
|
|
33
38
|
// complains of a "Conflicting definition".
|
|
34
39
|
function initProperty(obj, name, desc) {
|
|
@@ -71,7 +76,10 @@ function sampleGlobals(globalObject, newPropertyNames) {
|
|
|
71
76
|
return newIntrinsics;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @param {Reporter} reporter
|
|
81
|
+
*/
|
|
82
|
+
export const makeIntrinsicsCollector = reporter => {
|
|
75
83
|
/** @type {Record<any, any>} */
|
|
76
84
|
const intrinsics = create(null);
|
|
77
85
|
let pseudoNatives;
|
|
@@ -82,7 +90,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
82
90
|
freeze(addIntrinsics);
|
|
83
91
|
|
|
84
92
|
// For each intrinsic, if it has a `.prototype` property, use the
|
|
85
|
-
//
|
|
93
|
+
// permits to find out the intrinsic name for that prototype and add it
|
|
86
94
|
// to the intrinsics.
|
|
87
95
|
const completePrototypes = () => {
|
|
88
96
|
for (const [name, intrinsic] of entries(intrinsics)) {
|
|
@@ -96,17 +104,25 @@ export const makeIntrinsicsCollector = () => {
|
|
|
96
104
|
}
|
|
97
105
|
const permit = permitted[name];
|
|
98
106
|
if (typeof permit !== 'object') {
|
|
99
|
-
throw TypeError(`Expected permit object at
|
|
107
|
+
throw TypeError(`Expected permit object at permits.${name}`);
|
|
100
108
|
}
|
|
101
109
|
const namePrototype = permit.prototype;
|
|
102
110
|
if (!namePrototype) {
|
|
103
|
-
|
|
111
|
+
cauterizeProperty(
|
|
112
|
+
intrinsic,
|
|
113
|
+
'prototype',
|
|
114
|
+
false,
|
|
115
|
+
`${name}.prototype`,
|
|
116
|
+
reporter,
|
|
117
|
+
);
|
|
118
|
+
// eslint-disable-next-line no-continue
|
|
119
|
+
continue;
|
|
104
120
|
}
|
|
105
121
|
if (
|
|
106
122
|
typeof namePrototype !== 'string' ||
|
|
107
123
|
!objectHasOwnProperty(permitted, namePrototype)
|
|
108
124
|
) {
|
|
109
|
-
throw TypeError(`Unrecognized ${name}.prototype
|
|
125
|
+
throw TypeError(`Unrecognized ${name}.prototype permits entry`);
|
|
110
126
|
}
|
|
111
127
|
const intrinsicPrototype = intrinsic.prototype;
|
|
112
128
|
if (objectHasOwnProperty(intrinsics, namePrototype)) {
|
|
@@ -155,7 +171,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
155
171
|
/**
|
|
156
172
|
* getGlobalIntrinsics()
|
|
157
173
|
* Doesn't tame, delete, or modify anything. Samples globalObject to create an
|
|
158
|
-
* intrinsics record containing only the
|
|
174
|
+
* intrinsics record containing only the permitted global variables, listed
|
|
159
175
|
* by the intrinsic names appropriate for new globals, i.e., the globals of
|
|
160
176
|
* newly constructed compartments.
|
|
161
177
|
*
|
|
@@ -164,9 +180,11 @@ export const makeIntrinsicsCollector = () => {
|
|
|
164
180
|
* *original* unsafe (feral, untamed) bindings of these global variables.
|
|
165
181
|
*
|
|
166
182
|
* @param {object} globalObject
|
|
183
|
+
* @param {Reporter} reporter
|
|
167
184
|
*/
|
|
168
|
-
export const getGlobalIntrinsics = globalObject => {
|
|
169
|
-
|
|
185
|
+
export const getGlobalIntrinsics = (globalObject, reporter) => {
|
|
186
|
+
// TODO pass a proper reporter to `makeIntrinsicsCollector`
|
|
187
|
+
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector(reporter);
|
|
170
188
|
|
|
171
189
|
addIntrinsics(sampleGlobals(globalObject, sharedGlobalPropertyNames));
|
|
172
190
|
|
package/src/lockdown.js
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
} from './commons.js';
|
|
31
31
|
import { makeHardener } from './make-hardener.js';
|
|
32
32
|
import { makeIntrinsicsCollector } from './intrinsics.js';
|
|
33
|
-
import
|
|
33
|
+
import removeUnpermittedIntrinsics from './permits-intrinsics.js';
|
|
34
34
|
import tameFunctionConstructors from './tame-function-constructors.js';
|
|
35
35
|
import tameDateConstructor from './tame-date-constructor.js';
|
|
36
36
|
import tameMathObject from './tame-math-object.js';
|
|
@@ -58,6 +58,7 @@ import { tameSymbolConstructor } from './tame-symbol-constructor.js';
|
|
|
58
58
|
import { tameFauxDataProperties } from './tame-faux-data-properties.js';
|
|
59
59
|
import { tameRegeneratorRuntime } from './tame-regenerator-runtime.js';
|
|
60
60
|
import { shimArrayBufferTransfer } from './shim-arraybuffer-transfer.js';
|
|
61
|
+
import { reportInGroup, chooseReporter } from './reporting.js';
|
|
61
62
|
|
|
62
63
|
/** @import {LockdownOptions} from '../types.js' */
|
|
63
64
|
|
|
@@ -162,19 +163,24 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
162
163
|
|
|
163
164
|
const {
|
|
164
165
|
errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
|
|
165
|
-
errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit"
|
|
166
|
+
errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit"} */ (
|
|
166
167
|
getenv('LOCKDOWN_ERROR_TRAPPING', 'platform')
|
|
167
168
|
),
|
|
168
|
-
|
|
169
|
+
reporting = /** @type {"platform" | "console" | "none"} */ (
|
|
170
|
+
getenv('LOCKDOWN_REPORTING', 'platform')
|
|
171
|
+
),
|
|
172
|
+
unhandledRejectionTrapping = /** @type {"none" | "report"} */ (
|
|
169
173
|
getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report')
|
|
170
174
|
),
|
|
171
175
|
regExpTaming = getenv('LOCKDOWN_REGEXP_TAMING', 'safe'),
|
|
172
176
|
localeTaming = getenv('LOCKDOWN_LOCALE_TAMING', 'safe'),
|
|
173
177
|
|
|
174
|
-
consoleTaming = /** @type {'unsafe' | 'safe'
|
|
178
|
+
consoleTaming = /** @type {'unsafe' | 'safe'} */ (
|
|
175
179
|
getenv('LOCKDOWN_CONSOLE_TAMING', 'safe')
|
|
176
180
|
),
|
|
177
|
-
overrideTaming =
|
|
181
|
+
overrideTaming = /** @type {'moderate' | 'min' | 'severe'} */ (
|
|
182
|
+
getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate')
|
|
183
|
+
),
|
|
178
184
|
stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
|
|
179
185
|
domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
|
|
180
186
|
evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safeEval'),
|
|
@@ -208,6 +214,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
208
214
|
extraOptionsNames.length === 0 ||
|
|
209
215
|
Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;
|
|
210
216
|
|
|
217
|
+
const reporter = chooseReporter(reporting);
|
|
218
|
+
|
|
211
219
|
priorRepairIntrinsics === undefined ||
|
|
212
220
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
213
221
|
assert.fail(
|
|
@@ -273,7 +281,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
273
281
|
const markVirtualizedNativeFunction = tameFunctionToString();
|
|
274
282
|
|
|
275
283
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
276
|
-
makeIntrinsicsCollector();
|
|
284
|
+
makeIntrinsicsCollector(reporter);
|
|
277
285
|
|
|
278
286
|
// @ts-expect-error __hardenTaming__ could be any string
|
|
279
287
|
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
|
|
@@ -357,13 +365,22 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
357
365
|
tameFauxDataProperties(intrinsics);
|
|
358
366
|
|
|
359
367
|
/**
|
|
360
|
-
* 2.
|
|
368
|
+
* 2. Enforce PERMITS on shared intrinsics
|
|
361
369
|
*/
|
|
362
370
|
|
|
363
371
|
// Remove non-standard properties.
|
|
364
|
-
// All remaining
|
|
372
|
+
// All remaining functions encountered during whitelisting are
|
|
365
373
|
// branded as honorary native functions.
|
|
366
|
-
|
|
374
|
+
reportInGroup(
|
|
375
|
+
'SES Removing unpermitted intrinsics',
|
|
376
|
+
reporter,
|
|
377
|
+
groupReporter =>
|
|
378
|
+
removeUnpermittedIntrinsics(
|
|
379
|
+
intrinsics,
|
|
380
|
+
markVirtualizedNativeFunction,
|
|
381
|
+
groupReporter,
|
|
382
|
+
),
|
|
383
|
+
);
|
|
367
384
|
|
|
368
385
|
// Initialize the powerful initial global, i.e., the global of the
|
|
369
386
|
// start compartment, from the intrinsics.
|
|
@@ -425,7 +442,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
425
442
|
// therefore before vetted shims rather than afterwards. It is not
|
|
426
443
|
// clear yet which is better.
|
|
427
444
|
// @ts-ignore enablePropertyOverrides does its own input validation
|
|
428
|
-
|
|
445
|
+
reportInGroup('SES Enabling property overrides', reporter, groupReporter =>
|
|
446
|
+
enablePropertyOverrides(
|
|
447
|
+
intrinsics,
|
|
448
|
+
overrideTaming,
|
|
449
|
+
groupReporter,
|
|
450
|
+
overrideDebug,
|
|
451
|
+
),
|
|
452
|
+
);
|
|
429
453
|
if (legacyRegeneratorRuntimeTaming === 'unsafe-ignore') {
|
|
430
454
|
tameRegeneratorRuntime();
|
|
431
455
|
}
|
package/src/module-link.js
CHANGED
|
@@ -76,27 +76,27 @@ function mayBeVirtualModuleSource(moduleSource) {
|
|
|
76
76
|
function validateVirtualModuleSource(moduleSource, moduleSpecifier) {
|
|
77
77
|
const { exports } = moduleSource;
|
|
78
78
|
isArray(exports) ||
|
|
79
|
-
Fail`
|
|
79
|
+
Fail`Invalid module source: 'exports' of a virtual module source must be an array, got ${q(
|
|
80
80
|
exports,
|
|
81
81
|
)}, for module ${q(moduleSpecifier)}`;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
function validateModuleSource(moduleSource, moduleSpecifier) {
|
|
85
85
|
isObject(moduleSource) ||
|
|
86
|
-
Fail`
|
|
86
|
+
Fail`Invalid module source: must be of type object, got ${q(
|
|
87
87
|
moduleSource,
|
|
88
88
|
)}, for module ${q(moduleSpecifier)}`;
|
|
89
89
|
const { imports, exports, reexports = [] } = moduleSource;
|
|
90
90
|
isArray(imports) ||
|
|
91
|
-
Fail`
|
|
91
|
+
Fail`Invalid module source: 'imports' must be an array, got ${q(
|
|
92
92
|
imports,
|
|
93
93
|
)}, for module ${q(moduleSpecifier)}`;
|
|
94
94
|
isArray(exports) ||
|
|
95
|
-
Fail`
|
|
95
|
+
Fail`Invalid module source: 'exports' must be an array, got ${q(
|
|
96
96
|
exports,
|
|
97
97
|
)}, for module ${q(moduleSpecifier)}`;
|
|
98
98
|
isArray(reexports) ||
|
|
99
|
-
Fail`
|
|
99
|
+
Fail`Invalid module source: 'reexports' must be an array if present, got ${q(
|
|
100
100
|
reexports,
|
|
101
101
|
)}, for module ${q(moduleSpecifier)}`;
|
|
102
102
|
}
|
|
@@ -138,9 +138,7 @@ export const instantiate = (
|
|
|
138
138
|
resolvedImports,
|
|
139
139
|
);
|
|
140
140
|
} else {
|
|
141
|
-
throw TypeError(
|
|
142
|
-
`importHook must provide a module source, got ${q(moduleSource)}`,
|
|
143
|
-
);
|
|
141
|
+
throw TypeError(`Invalid module source, got ${q(moduleSource)}`);
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
// Memoize.
|
package/src/module-load.js
CHANGED
|
@@ -6,11 +6,13 @@ import {
|
|
|
6
6
|
arrayJoin,
|
|
7
7
|
arrayMap,
|
|
8
8
|
arrayPush,
|
|
9
|
+
arraySome,
|
|
9
10
|
create,
|
|
10
11
|
freeze,
|
|
11
12
|
generatorNext,
|
|
12
13
|
generatorThrow,
|
|
13
14
|
getOwnPropertyNames,
|
|
15
|
+
isArray,
|
|
14
16
|
isObject,
|
|
15
17
|
mapGet,
|
|
16
18
|
mapHas,
|
|
@@ -85,14 +87,23 @@ const loadModuleSource = (
|
|
|
85
87
|
moduleLoads,
|
|
86
88
|
importMeta,
|
|
87
89
|
) => {
|
|
88
|
-
const { resolveHook } = weakmapGet(
|
|
90
|
+
const { resolveHook, name: compartmentName } = weakmapGet(
|
|
91
|
+
compartmentPrivateFields,
|
|
92
|
+
compartment,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const { imports } = moduleSource;
|
|
96
|
+
if (
|
|
97
|
+
!isArray(imports) ||
|
|
98
|
+
arraySome(imports, specifier => typeof specifier !== 'string')
|
|
99
|
+
) {
|
|
100
|
+
throw makeError(
|
|
101
|
+
X`Invalid module source: 'imports' must be an array of strings, got ${imports} for module ${q(moduleSpecifier)} of compartment ${q(compartmentName)}`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
89
104
|
|
|
90
105
|
// resolve all imports relative to this referrer module.
|
|
91
|
-
const resolvedImports = resolveAll(
|
|
92
|
-
moduleSource.imports,
|
|
93
|
-
resolveHook,
|
|
94
|
-
moduleSpecifier,
|
|
95
|
-
);
|
|
106
|
+
const resolvedImports = resolveAll(imports, resolveHook, moduleSpecifier);
|
|
96
107
|
const moduleRecord = freeze({
|
|
97
108
|
compartment,
|
|
98
109
|
moduleSource,
|