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/dist/types.d.cts
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -94,31 +94,32 @@
|
|
|
94
94
|
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@endo/env-options": "^1.1.
|
|
97
|
+
"@endo/env-options": "^1.1.9",
|
|
98
|
+
"@endo/immutable-arraybuffer": "^1.1.0"
|
|
98
99
|
},
|
|
99
100
|
"devDependencies": {
|
|
100
101
|
"@babel/generator": "^7.26.3",
|
|
101
102
|
"@babel/parser": "~7.26.2",
|
|
102
103
|
"@babel/traverse": "~7.25.9",
|
|
103
104
|
"@babel/types": "~7.26.0",
|
|
104
|
-
"@endo/compartment-mapper": "^1.6.
|
|
105
|
-
"@endo/module-source": "^1.3.
|
|
106
|
-
"@endo/test262-runner": "^0.1.
|
|
105
|
+
"@endo/compartment-mapper": "^1.6.1",
|
|
106
|
+
"@endo/module-source": "^1.3.1",
|
|
107
|
+
"@endo/test262-runner": "^0.1.46",
|
|
107
108
|
"@types/babel__traverse": "^7.20.5",
|
|
108
109
|
"ava": "^6.1.3",
|
|
109
110
|
"babel-eslint": "^10.1.0",
|
|
110
111
|
"c8": "^7.14.0",
|
|
111
112
|
"core-js": "^3.31.0",
|
|
112
|
-
"eslint": "^8.57.
|
|
113
|
+
"eslint": "^8.57.1",
|
|
113
114
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
114
115
|
"eslint-config-prettier": "^9.1.0",
|
|
115
116
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
116
|
-
"eslint-plugin-import": "^2.
|
|
117
|
+
"eslint-plugin-import": "^2.31.0",
|
|
117
118
|
"hermes-engine-cli": "^0.12.0",
|
|
118
|
-
"prettier": "^3.
|
|
119
|
+
"prettier": "^3.5.3",
|
|
119
120
|
"terser": "^5.16.6",
|
|
120
121
|
"tsd": "^0.31.2",
|
|
121
|
-
"typescript": "~5.
|
|
122
|
+
"typescript": "~5.8.3"
|
|
122
123
|
},
|
|
123
124
|
"files": [
|
|
124
125
|
"./*.d.ts",
|
|
@@ -225,5 +226,5 @@
|
|
|
225
226
|
"typeCoverage": {
|
|
226
227
|
"atLeast": 81.17
|
|
227
228
|
},
|
|
228
|
-
"gitHead": "
|
|
229
|
+
"gitHead": "571b7803cf10df7cb4fa9d70e4d53a0b53767fa8"
|
|
229
230
|
}
|
package/src/commons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Captures native intrinsics during initialization, so vetted shims
|
|
3
3
|
* (running between initialization of SES and calling lockdown) are free to
|
|
4
4
|
* modify the environment without compromising the integrity of SES. For
|
|
5
5
|
* example, a vetted shim can modify Object.assign because we capture and
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* This pattern of use is enforced by eslint rules no-restricted-globals and
|
|
10
10
|
* no-polymorphic-call.
|
|
11
11
|
* We maintain the list of restricted globals in ../package.json.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/* global globalThis */
|
package/src/compartment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the mechanism to create a Compartment constructor that
|
|
3
3
|
* can provide either shim-specific or native XS features depending on
|
|
4
4
|
* the __native__ constructor option.
|
|
5
5
|
* This is necessary because a native Compartment can handle native ModuleSource
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
* Evaluating ./compartment.js does not have global side-effects.
|
|
34
34
|
* We defer modification of the global environment until the evaluation
|
|
35
35
|
* of ./compartment-shim.js.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
36
38
|
*/
|
|
37
39
|
|
|
38
40
|
// @ts-check
|
package/src/enablements.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { toStringTagSymbol, iteratorSymbol } from './commons.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 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.
|
|
8
8
|
*
|
|
9
9
|
* @author JF Paradis
|
|
10
10
|
* @author Mark S. Miller
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -41,10 +41,6 @@ export const tameConsole = (
|
|
|
41
41
|
unhandledRejectionTrapping = 'report',
|
|
42
42
|
optGetStackString = undefined,
|
|
43
43
|
) => {
|
|
44
|
-
consoleTaming === 'safe' ||
|
|
45
|
-
consoleTaming === 'unsafe' ||
|
|
46
|
-
failFast(`unrecognized consoleTaming ${consoleTaming}`);
|
|
47
|
-
|
|
48
44
|
let loggedErrorHandler;
|
|
49
45
|
if (optGetStackString === undefined) {
|
|
50
46
|
loggedErrorHandler = defaultHandler;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FERAL_ERROR,
|
|
3
|
-
TypeError,
|
|
4
3
|
apply,
|
|
5
4
|
construct,
|
|
6
5
|
defineProperties,
|
|
@@ -36,16 +35,6 @@ export default function tameErrorConstructor(
|
|
|
36
35
|
errorTaming = 'safe',
|
|
37
36
|
stackFiltering = 'concise',
|
|
38
37
|
) {
|
|
39
|
-
if (
|
|
40
|
-
errorTaming !== 'safe' &&
|
|
41
|
-
errorTaming !== 'unsafe' &&
|
|
42
|
-
errorTaming !== 'unsafe-debug'
|
|
43
|
-
) {
|
|
44
|
-
throw TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
45
|
-
}
|
|
46
|
-
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
47
|
-
throw TypeError(`unrecognized stackFiltering ${stackFiltering}`);
|
|
48
|
-
}
|
|
49
38
|
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
50
39
|
|
|
51
40
|
const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR;
|
|
@@ -71,10 +71,9 @@ const FILENAME_NODE_DEPENDENTS_CENSOR = /\/node_modules\//;
|
|
|
71
71
|
// stack traces.
|
|
72
72
|
const FILENAME_NODE_INTERNALS_CENSOR = /^(?:node:)?internal\//;
|
|
73
73
|
|
|
74
|
-
// Frames within
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
|
|
74
|
+
// Frames within SES `assert.js` should be dropped from concise stack traces, as
|
|
75
|
+
// these are just steps towards creating the error object in question.
|
|
76
|
+
const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert\.js$/;
|
|
78
77
|
|
|
79
78
|
// Frames within the `eventual-send` shim should be dropped so that concise
|
|
80
79
|
// deep stacks omit the internals of the eventual-sending mechanism causing
|
|
@@ -83,6 +82,10 @@ const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
|
|
|
83
82
|
// Endo, so this rule will be of general interest.
|
|
84
83
|
const FILENAME_EVENTUAL_SEND_CENSOR = /\/packages\/eventual-send\/src\//;
|
|
85
84
|
|
|
85
|
+
// Frames within the `ses-ava` package should be dropped from concise stack
|
|
86
|
+
// traces, as they just support exposing error details to AVA.
|
|
87
|
+
const FILENAME_SES_AVA_CENSOR = /\/packages\/ses-ava\/src\/ses-ava-test\.js$/;
|
|
88
|
+
|
|
86
89
|
// Any stack frame whose `fileName` matches any of these censor patterns
|
|
87
90
|
// will be omitted from concise stacks.
|
|
88
91
|
// TODO Enable users to configure FILENAME_CENSORS via `lockdown` options.
|
|
@@ -91,6 +94,7 @@ const FILENAME_CENSORS = [
|
|
|
91
94
|
FILENAME_NODE_INTERNALS_CENSOR,
|
|
92
95
|
FILENAME_ASSERT_CENSOR,
|
|
93
96
|
FILENAME_EVENTUAL_SEND_CENSOR,
|
|
97
|
+
FILENAME_SES_AVA_CENSOR,
|
|
94
98
|
];
|
|
95
99
|
|
|
96
100
|
// Should a stack frame with this as its fileName be included in a concise
|
|
@@ -114,34 +118,64 @@ export const filterFileName = fileName => {
|
|
|
114
118
|
// likely url-path prefix, ending in a `/.../` should get dropped.
|
|
115
119
|
// Anything to the left of the likely path text is kept.
|
|
116
120
|
// Everything to the right of `/.../` is kept. Thus
|
|
117
|
-
// `'Object.bar (/vat-v1/.../eventual-send/test/
|
|
121
|
+
// `'Object.bar (/vat-v1/.../eventual-send/test/deep-send.test.js:13:21)'`
|
|
122
|
+
// simplifies to
|
|
123
|
+
// `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
|
|
124
|
+
//
|
|
125
|
+
// See thread starting at
|
|
126
|
+
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
127
|
+
const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
|
|
128
|
+
|
|
129
|
+
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
130
|
+
// likely url-path prefix consisting of `.../` should get dropped.
|
|
131
|
+
// Anything to the left of the likely path text is kept.
|
|
132
|
+
// Everything to the right of `.../` is kept. Thus
|
|
133
|
+
// `'Object.bar (.../eventual-send/test/deep-send.test.js:13:21)'`
|
|
118
134
|
// simplifies to
|
|
119
|
-
// `'Object.bar (eventual-send/test/
|
|
135
|
+
// `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
|
|
120
136
|
//
|
|
121
137
|
// See thread starting at
|
|
122
138
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
123
|
-
const
|
|
139
|
+
const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
|
|
124
140
|
|
|
125
141
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
126
142
|
// likely url-path prefix, ending in a `/` and prior to `package/` should get
|
|
127
143
|
// dropped.
|
|
128
144
|
// Anything to the left of the likely path prefix text is kept. `package/` and
|
|
129
145
|
// everything to its right is kept. Thus
|
|
130
|
-
// `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/
|
|
146
|
+
// `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/deep-send.test.js:13:21)'`
|
|
131
147
|
// simplifies to
|
|
132
|
-
// `'Object.bar (packages/eventual-send/test/
|
|
148
|
+
// `'Object.bar (packages/eventual-send/test/deep-send.test.js:13:21)'`.
|
|
133
149
|
// Note that `/packages/` is a convention for monorepos encouraged by
|
|
134
150
|
// lerna.
|
|
135
151
|
const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
|
|
136
152
|
|
|
153
|
+
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
154
|
+
// likely url-path prefix of the form `file://` but not `file:///` gets
|
|
155
|
+
// dropped.
|
|
156
|
+
// Anything to the left of the likely path prefix text is kept. Everything to
|
|
157
|
+
// the right of `file://` is kept. Thus
|
|
158
|
+
// `'Object.bar (file:///Users/markmiller/src/ongithub/endojs/endo/packages/eventual-send/test/deep-send.test.js:13:21)'` is unchanged but
|
|
159
|
+
// `'Object.bar (file://test/deep-send.test.js:13:21)'`
|
|
160
|
+
|
|
161
|
+
// simplifies to
|
|
162
|
+
// `'Object.bar (test/deep-send.test.js:13:21)'`.
|
|
163
|
+
// The reason is that `file:///` usually precedes an absolute path which is
|
|
164
|
+
// clickable without removing the `file:///`, whereas `file://` usually precedes
|
|
165
|
+
// a relative path which, for whatever vscode reason, is not clickable until the
|
|
166
|
+
// `file://` is removed.
|
|
167
|
+
const CALLSITE_FILE_2SLASH_PATTERN = /^((?:.*[( ])?)file:\/\/([^/].*)$/;
|
|
168
|
+
|
|
137
169
|
// The use of these callSite patterns below assumes that any match will bind
|
|
138
170
|
// capture groups containing the parts of the original string we want
|
|
139
171
|
// to keep. The parts outside those capture groups will be dropped from concise
|
|
140
172
|
// stacks.
|
|
141
173
|
// TODO Enable users to configure CALLSITE_PATTERNS via `lockdown` options.
|
|
142
174
|
const CALLSITE_PATTERNS = [
|
|
143
|
-
|
|
175
|
+
CALLSITE_ELLIPSIS_PATTERN1,
|
|
176
|
+
CALLSITE_ELLIPSIS_PATTERN2,
|
|
144
177
|
CALLSITE_PACKAGES_PATTERN,
|
|
178
|
+
CALLSITE_FILE_2SLASH_PATTERN,
|
|
145
179
|
];
|
|
146
180
|
|
|
147
181
|
// For a stack frame that should be included in a concise stack trace, if
|
|
@@ -149,6 +183,9 @@ const CALLSITE_PATTERNS = [
|
|
|
149
183
|
// possibly-shorter stringified stack frame that should be shown instead.
|
|
150
184
|
// Exported only so it can be unit tested.
|
|
151
185
|
// TODO Move so that it applies not just to v8.
|
|
186
|
+
/**
|
|
187
|
+
* @param {string} callSiteString
|
|
188
|
+
*/
|
|
152
189
|
export const shortenCallSiteString = callSiteString => {
|
|
153
190
|
for (const filter of CALLSITE_PATTERNS) {
|
|
154
191
|
const match = regexpExec(filter, callSiteString);
|
|
@@ -175,18 +212,24 @@ export const tameV8ErrorConstructor = (
|
|
|
175
212
|
|
|
176
213
|
const originalCaptureStackTrace = OriginalError.captureStackTrace;
|
|
177
214
|
|
|
215
|
+
const omitFrames =
|
|
216
|
+
stackFiltering === 'concise' || stackFiltering === 'omit-frames';
|
|
217
|
+
|
|
218
|
+
const shortenPaths =
|
|
219
|
+
stackFiltering === 'concise' || stackFiltering === 'shorten-paths';
|
|
220
|
+
|
|
178
221
|
// const callSiteFilter = _callSite => true;
|
|
179
222
|
const callSiteFilter = callSite => {
|
|
180
|
-
if (
|
|
181
|
-
|
|
223
|
+
if (omitFrames) {
|
|
224
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
225
|
+
return filterFileName(callSite.getFileName());
|
|
182
226
|
}
|
|
183
|
-
|
|
184
|
-
return filterFileName(callSite.getFileName());
|
|
227
|
+
return true;
|
|
185
228
|
};
|
|
186
229
|
|
|
187
230
|
const callSiteStringifier = callSite => {
|
|
188
231
|
let callSiteString = `${callSite}`;
|
|
189
|
-
if (
|
|
232
|
+
if (shortenPaths) {
|
|
190
233
|
callSiteString = shortenCallSiteString(callSiteString);
|
|
191
234
|
}
|
|
192
235
|
return `\n at ${callSiteString}`;
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
globalThis,
|
|
17
17
|
assign,
|
|
18
18
|
AsyncGeneratorFunctionInstance,
|
|
19
|
+
ArrayBuffer,
|
|
19
20
|
} from './commons.js';
|
|
20
21
|
import { InertCompartment } from './compartment.js';
|
|
21
22
|
|
|
@@ -166,5 +167,15 @@ export const getAnonymousIntrinsics = () => {
|
|
|
166
167
|
);
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
const ab = new ArrayBuffer(0);
|
|
171
|
+
// @ts-expect-error TODO How do I add sliceToImmutable to ArrayBuffer type?
|
|
172
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
173
|
+
const iab = ab.sliceToImmutable();
|
|
174
|
+
const iabProto = getPrototypeOf(iab);
|
|
175
|
+
if (iabProto !== ArrayBuffer.prototype) {
|
|
176
|
+
// In a native implementation, these will be the same prototype
|
|
177
|
+
intrinsics['%ImmutableArrayBufferPrototype%'] = iabProto;
|
|
178
|
+
}
|
|
179
|
+
|
|
169
180
|
return intrinsics;
|
|
170
181
|
};
|
package/src/lockdown.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// @ts-check
|
|
16
16
|
|
|
17
17
|
import { getEnvironmentOption as getenv } from '@endo/env-options';
|
|
18
|
+
import '@endo/immutable-arraybuffer/shim.js';
|
|
18
19
|
import {
|
|
19
20
|
FERAL_FUNCTION,
|
|
20
21
|
FERAL_EVAL,
|
|
@@ -100,10 +101,32 @@ const safeHarden = makeHardener();
|
|
|
100
101
|
// only ever need to be called once and that simplifying lockdown will improve
|
|
101
102
|
// the quality of audits.
|
|
102
103
|
|
|
103
|
-
const
|
|
104
|
-
let
|
|
104
|
+
const probeHostEvaluators = () => {
|
|
105
|
+
let functionAllowed;
|
|
105
106
|
try {
|
|
106
|
-
|
|
107
|
+
functionAllowed = FERAL_FUNCTION('return true')();
|
|
108
|
+
} catch (_error) {
|
|
109
|
+
// We reach here if the Function() constructor is outright forbidden by a
|
|
110
|
+
// strict Content Security Policy (containing either a `default-src` or a
|
|
111
|
+
// `script-src` directive), not been implemented in the host, or the host
|
|
112
|
+
// is configured to throw an exception instead of `new Function`.
|
|
113
|
+
functionAllowed = false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let evalAllowed;
|
|
117
|
+
try {
|
|
118
|
+
evalAllowed = FERAL_EVAL('true');
|
|
119
|
+
} catch (_error) {
|
|
120
|
+
// We reach here if `eval` is outright forbidden by a strict Content Security Policy,
|
|
121
|
+
// not implemented in the host, or the host is configured to throw an exception.
|
|
122
|
+
// We allow this for SES usage that delegates the responsibility to isolate
|
|
123
|
+
// guest code to production code generation.
|
|
124
|
+
evalAllowed = false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let directEvalAllowed;
|
|
128
|
+
if (functionAllowed && evalAllowed) {
|
|
129
|
+
directEvalAllowed = FERAL_FUNCTION(
|
|
107
130
|
'eval',
|
|
108
131
|
'SES_changed',
|
|
109
132
|
`\
|
|
@@ -115,21 +138,12 @@ const assertDirectEvalAvailable = () => {
|
|
|
115
138
|
// and indirect, which generally creates a new global.
|
|
116
139
|
// We are going to throw an exception for failing to initialize SES, but
|
|
117
140
|
// good neighbors clean up.
|
|
118
|
-
if (!
|
|
141
|
+
if (!directEvalAllowed) {
|
|
119
142
|
delete globalThis.SES_changed;
|
|
120
143
|
}
|
|
121
|
-
} catch (_error) {
|
|
122
|
-
// We reach here if eval is outright forbidden by a Content Security Policy.
|
|
123
|
-
// We allow this for SES usage that delegates the responsibility to isolate
|
|
124
|
-
// guest code to production code generation.
|
|
125
|
-
allowed = true;
|
|
126
|
-
}
|
|
127
|
-
if (!allowed) {
|
|
128
|
-
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
|
|
129
|
-
throw TypeError(
|
|
130
|
-
`SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
|
|
131
|
-
);
|
|
132
144
|
}
|
|
145
|
+
|
|
146
|
+
return { functionAllowed, evalAllowed, directEvalAllowed };
|
|
133
147
|
};
|
|
134
148
|
|
|
135
149
|
/**
|
|
@@ -152,65 +166,85 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
152
166
|
// The `stackFiltering` is not a safety issue. Rather it is a tradeoff
|
|
153
167
|
// between relevance and completeness of the stack frames shown on the
|
|
154
168
|
// console. Setting`stackFiltering` to `'verbose'` applies no filters, providing
|
|
155
|
-
// the raw stack frames that can be quite
|
|
169
|
+
// the raw stack frames that can be quite verbose. Setting
|
|
156
170
|
// `stackFrameFiltering` to`'concise'` limits the display to the stack frame
|
|
157
171
|
// information most likely to be relevant, eliminating distracting frames
|
|
158
172
|
// such as those from the infrastructure. However, the bug you're trying to
|
|
159
|
-
// track down might be in the
|
|
173
|
+
// track down might be in the infrastructure, in which case the `'verbose'` setting
|
|
160
174
|
// is useful. See
|
|
161
175
|
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
|
|
162
176
|
// for an explanation.
|
|
163
177
|
|
|
164
178
|
const {
|
|
165
|
-
errorTaming =
|
|
166
|
-
|
|
167
|
-
getenv('LOCKDOWN_ERROR_TRAPPING', 'platform')
|
|
179
|
+
errorTaming = /** @type {'safe' | 'unsafe' | 'unsafe-debug'} */ (
|
|
180
|
+
getenv('LOCKDOWN_ERROR_TAMING', 'safe', ['unsafe', 'unsafe-debug'])
|
|
168
181
|
),
|
|
169
|
-
|
|
170
|
-
getenv('
|
|
182
|
+
errorTrapping = /** @type {'platform' | 'none' | 'report' | 'abort' | 'exit'} */ (
|
|
183
|
+
getenv('LOCKDOWN_ERROR_TRAPPING', 'platform', [
|
|
184
|
+
'none',
|
|
185
|
+
'report',
|
|
186
|
+
'abort',
|
|
187
|
+
'exit',
|
|
188
|
+
])
|
|
171
189
|
),
|
|
172
|
-
|
|
173
|
-
getenv('
|
|
190
|
+
reporting = /** @type {'platform' | 'console' | 'none'} */ (
|
|
191
|
+
getenv('LOCKDOWN_REPORTING', 'platform', ['console', 'none'])
|
|
192
|
+
),
|
|
193
|
+
unhandledRejectionTrapping = /** @type {'none' | 'report'} */ (
|
|
194
|
+
getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report', ['none'])
|
|
195
|
+
),
|
|
196
|
+
regExpTaming = /** @type {'safe' | 'unsafe'} */ (
|
|
197
|
+
getenv('LOCKDOWN_REGEXP_TAMING', 'safe', ['unsafe'])
|
|
198
|
+
),
|
|
199
|
+
localeTaming = /** @type {'safe' | 'unsafe'} */ (
|
|
200
|
+
getenv('LOCKDOWN_LOCALE_TAMING', 'safe', ['unsafe'])
|
|
174
201
|
),
|
|
175
|
-
regExpTaming = getenv('LOCKDOWN_REGEXP_TAMING', 'safe'),
|
|
176
|
-
localeTaming = getenv('LOCKDOWN_LOCALE_TAMING', 'safe'),
|
|
177
|
-
|
|
178
202
|
consoleTaming = /** @type {'unsafe' | 'safe'} */ (
|
|
179
|
-
getenv('LOCKDOWN_CONSOLE_TAMING', 'safe')
|
|
203
|
+
getenv('LOCKDOWN_CONSOLE_TAMING', 'safe', ['unsafe'])
|
|
180
204
|
),
|
|
181
205
|
overrideTaming = /** @type {'moderate' | 'min' | 'severe'} */ (
|
|
182
|
-
getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate')
|
|
206
|
+
getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate', ['min', 'severe'])
|
|
207
|
+
),
|
|
208
|
+
stackFiltering = /** @type {'concise' | 'omit-frames' | 'shorten-paths' | 'verbose'} */ (
|
|
209
|
+
getenv('LOCKDOWN_STACK_FILTERING', 'concise', [
|
|
210
|
+
'omit-frames',
|
|
211
|
+
'shorten-paths',
|
|
212
|
+
'verbose',
|
|
213
|
+
])
|
|
214
|
+
),
|
|
215
|
+
domainTaming = /** @type {'safe' | 'unsafe'} */ (
|
|
216
|
+
getenv('LOCKDOWN_DOMAIN_TAMING', 'safe', ['unsafe'])
|
|
183
217
|
),
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
218
|
+
evalTaming = /** @type {'safe-eval' | 'unsafe-eval' | 'no-eval'} */ (
|
|
219
|
+
getenv('LOCKDOWN_EVAL_TAMING', 'safe-eval', [
|
|
220
|
+
'unsafe-eval',
|
|
221
|
+
'no-eval',
|
|
222
|
+
// deprecated
|
|
223
|
+
'safeEval',
|
|
224
|
+
'unsafeEval',
|
|
225
|
+
'noEval',
|
|
226
|
+
])
|
|
191
227
|
),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
228
|
+
overrideDebug = /** @type {string[]} */ (
|
|
229
|
+
arrayFilter(
|
|
230
|
+
stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
|
|
231
|
+
/** @param {string} debugName */
|
|
232
|
+
debugName => debugName !== '',
|
|
233
|
+
)
|
|
234
|
+
),
|
|
235
|
+
legacyRegeneratorRuntimeTaming = /** @type {'safe' | 'unsafe-ignore'} */ (
|
|
236
|
+
getenv('LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING', 'safe', [
|
|
237
|
+
'unsafe-ignore',
|
|
238
|
+
])
|
|
239
|
+
),
|
|
240
|
+
__hardenTaming__ = /** @type {'safe' | 'unsafe'} */ (
|
|
241
|
+
getenv('LOCKDOWN_HARDEN_TAMING', 'safe', ['unsafe'])
|
|
195
242
|
),
|
|
196
|
-
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
|
|
197
243
|
dateTaming, // deprecated
|
|
198
244
|
mathTaming, // deprecated
|
|
199
245
|
...extraOptions
|
|
200
246
|
} = options;
|
|
201
247
|
|
|
202
|
-
legacyRegeneratorRuntimeTaming === 'safe' ||
|
|
203
|
-
legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
|
|
204
|
-
Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
|
|
205
|
-
|
|
206
|
-
evalTaming === 'unsafe-eval' ||
|
|
207
|
-
evalTaming === 'unsafeEval' || // deprecated
|
|
208
|
-
evalTaming === 'safe-eval' ||
|
|
209
|
-
evalTaming === 'safeEval' || // deprecated
|
|
210
|
-
evalTaming === 'no-eval' ||
|
|
211
|
-
evalTaming === 'noEval' || // deprecated
|
|
212
|
-
Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
|
|
213
|
-
|
|
214
248
|
// Assert that only supported options were passed.
|
|
215
249
|
// Use Reflect.ownKeys to reject symbol-named properties as well.
|
|
216
250
|
const extraOptionsNames = ownKeys(extraOptions);
|
|
@@ -221,13 +255,11 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
221
255
|
const { warn } = reporter;
|
|
222
256
|
|
|
223
257
|
if (dateTaming !== undefined) {
|
|
224
|
-
// eslint-disable-next-line no-console
|
|
225
258
|
warn(
|
|
226
259
|
`SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
|
|
227
260
|
);
|
|
228
261
|
}
|
|
229
262
|
if (mathTaming !== undefined) {
|
|
230
|
-
// eslint-disable-next-line no-console
|
|
231
263
|
warn(
|
|
232
264
|
`SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
|
|
233
265
|
);
|
|
@@ -245,7 +277,19 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
245
277
|
// trace retained:
|
|
246
278
|
priorRepairIntrinsics.stack;
|
|
247
279
|
|
|
248
|
-
|
|
280
|
+
const { functionAllowed, evalAllowed, directEvalAllowed } =
|
|
281
|
+
probeHostEvaluators();
|
|
282
|
+
|
|
283
|
+
if (
|
|
284
|
+
directEvalAllowed === false &&
|
|
285
|
+
evalTaming === 'safe-eval' &&
|
|
286
|
+
(functionAllowed || evalAllowed)
|
|
287
|
+
) {
|
|
288
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
|
|
289
|
+
throw TypeError(
|
|
290
|
+
"SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct eval (dynamically scoped eval) (SES_DIRECT_EVAL)",
|
|
291
|
+
);
|
|
292
|
+
}
|
|
249
293
|
|
|
250
294
|
/**
|
|
251
295
|
* Because of packagers and bundlers, etc, multiple invocations of lockdown
|
|
@@ -300,7 +344,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
300
344
|
const { addIntrinsics, completePrototypes, finalIntrinsics } =
|
|
301
345
|
makeIntrinsicsCollector(reporter);
|
|
302
346
|
|
|
303
|
-
// @ts-expect-error __hardenTaming__ could be any string
|
|
304
347
|
const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
|
|
305
348
|
addIntrinsics({ harden: tamedHarden });
|
|
306
349
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* makeEvalFunction()
|
|
3
3
|
* A safe version of the native eval function which relies on
|
|
4
|
-
* the safety of
|
|
4
|
+
* the safety of `safe-eval` for confinement, unless `no-eval`
|
|
5
|
+
* is specified (then a TypeError is thrown on use).
|
|
5
6
|
*
|
|
6
|
-
* @param {Function}
|
|
7
|
+
* @param {Function} evaluator
|
|
7
8
|
*/
|
|
8
|
-
export const makeEvalFunction =
|
|
9
|
+
export const makeEvalFunction = evaluator => {
|
|
9
10
|
// We use the concise method syntax to create an eval without a
|
|
10
11
|
// [[Construct]] behavior (such that the invocation "new eval()" throws
|
|
11
12
|
// TypeError: eval is not a constructor"), but which still accepts a
|
|
@@ -19,7 +20,7 @@ export const makeEvalFunction = safeEvaluate => {
|
|
|
19
20
|
// rule. Track.
|
|
20
21
|
return source;
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
+
return evaluator(source);
|
|
23
24
|
},
|
|
24
25
|
}.eval;
|
|
25
26
|
|
|
@@ -12,9 +12,10 @@ const { Fail } = assert;
|
|
|
12
12
|
/*
|
|
13
13
|
* makeFunctionConstructor()
|
|
14
14
|
* A safe version of the native Function which relies on
|
|
15
|
-
* the safety of
|
|
15
|
+
* the safety of `safe-eval` for confinement, unless `no-eval`
|
|
16
|
+
* is specified (then a TypeError is thrown on use).
|
|
16
17
|
*/
|
|
17
|
-
export const makeFunctionConstructor =
|
|
18
|
+
export const makeFunctionConstructor = evaluator => {
|
|
18
19
|
// Define an unused parameter to ensure Function.length === 1
|
|
19
20
|
const newFunction = function Function(_body) {
|
|
20
21
|
// Sanitize all parameters at the entry point.
|
|
@@ -54,7 +55,7 @@ export const makeFunctionConstructor = safeEvaluate => {
|
|
|
54
55
|
// TODO: since we create an anonymous function, the 'this' value
|
|
55
56
|
// isn't bound to the global object as per specs, but set as undefined.
|
|
56
57
|
const src = `(function anonymous(${parameters}\n) {\n${bodyText}\n})`;
|
|
57
|
-
return
|
|
58
|
+
return evaluator(src);
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
defineProperties(newFunction, {
|
|
@@ -72,7 +73,7 @@ export const makeFunctionConstructor = safeEvaluate => {
|
|
|
72
73
|
getPrototypeOf(FERAL_FUNCTION) === FERAL_FUNCTION.prototype ||
|
|
73
74
|
Fail`Function prototype is the same accross compartments`;
|
|
74
75
|
getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype ||
|
|
75
|
-
Fail`Function constructor prototype is the same
|
|
76
|
+
Fail`Function constructor prototype is the same across compartments`;
|
|
76
77
|
|
|
77
78
|
return newFunction;
|
|
78
79
|
};
|