ses 1.0.1 → 1.1.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 +599 -185
- package/dist/lockdown.mjs +599 -185
- package/dist/lockdown.umd.js +599 -185
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +599 -185
- package/dist/ses.mjs +599 -185
- package/dist/ses.umd.js +599 -185
- package/dist/ses.umd.min.js +1 -1
- package/package.json +9 -9
- package/src/enable-property-overrides.js +40 -36
- package/src/enablements.js +13 -0
- package/src/error/README.md +1 -1
- package/src/error/fatal-assert.js +1 -1
- package/src/error/tame-console.js +72 -51
- package/src/lockdown.js +43 -12
- package/src/module-instance.js +10 -10
- package/src/module-proxy.js +42 -14
- package/src/permits-intrinsics.js +29 -15
- package/src/permits.js +14 -0
- package/src/tame-domains.js +4 -6
- package/src/tame-faux-data-properties.js +210 -0
- package/types.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"clean": "rm -rf dist",
|
|
53
53
|
"cover": "c8 ava",
|
|
54
54
|
"demo": "python3 -m http.server",
|
|
55
|
-
"lint": "yarn lint:types && yarn lint:
|
|
55
|
+
"lint": "yarn lint:types && yarn lint:eslint",
|
|
56
56
|
"lint-fix": "eslint --fix .",
|
|
57
|
-
"lint:
|
|
57
|
+
"lint:eslint": "eslint .",
|
|
58
58
|
"lint:types": "tsc",
|
|
59
59
|
"prepare": "yarn run clean && yarn build",
|
|
60
60
|
"qt": "ava",
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@endo/env-options": "^1.0
|
|
65
|
+
"@endo/env-options": "^1.1.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@endo/compartment-mapper": "^1.0
|
|
69
|
-
"@endo/static-module-record": "^1.0.
|
|
68
|
+
"@endo/compartment-mapper": "^1.1.0",
|
|
69
|
+
"@endo/static-module-record": "^1.0.2",
|
|
70
70
|
"@endo/test262-runner": "^0.1.32",
|
|
71
71
|
"ava": "^5.3.0",
|
|
72
72
|
"babel-eslint": "^10.0.3",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"sinon": "^15.1.0",
|
|
82
82
|
"terser": "^5.16.6",
|
|
83
83
|
"tsd": "^0.28.1",
|
|
84
|
-
"typescript": "~5.
|
|
84
|
+
"typescript": "~5.3.3"
|
|
85
85
|
},
|
|
86
86
|
"files": [
|
|
87
87
|
"LICENSE*",
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
"timeout": "2m"
|
|
183
183
|
},
|
|
184
184
|
"typeCoverage": {
|
|
185
|
-
"atLeast": 81.
|
|
185
|
+
"atLeast": 81.17
|
|
186
186
|
},
|
|
187
|
-
"gitHead": "
|
|
187
|
+
"gitHead": "373f9eebab66c94ed42350473c90fb25e6054f0a"
|
|
188
188
|
}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
defineProperty,
|
|
12
12
|
getOwnPropertyDescriptor,
|
|
13
13
|
getOwnPropertyDescriptors,
|
|
14
|
-
getOwnPropertyNames,
|
|
15
14
|
isObject,
|
|
16
15
|
objectHasOwnProperty,
|
|
17
16
|
ownKeys,
|
|
@@ -88,9 +87,43 @@ export default function enablePropertyOverrides(
|
|
|
88
87
|
if ('value' in desc && desc.configurable) {
|
|
89
88
|
const { value } = desc;
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
const isDebug = setHas(debugProperties, prop);
|
|
91
|
+
|
|
92
|
+
// We use concise method syntax to be `this` sensitive, but still
|
|
93
|
+
// omit a prototype property or [[Construct]] behavior.
|
|
94
|
+
// @ts-expect-error We know there is an accessor descriptor there
|
|
95
|
+
const { get: getter, set: setter } = getOwnPropertyDescriptor(
|
|
96
|
+
{
|
|
97
|
+
get [prop]() {
|
|
98
|
+
return value;
|
|
99
|
+
},
|
|
100
|
+
set [prop](newValue) {
|
|
101
|
+
if (obj === this) {
|
|
102
|
+
throw TypeError(
|
|
103
|
+
`Cannot assign to read only property '${String(
|
|
104
|
+
prop,
|
|
105
|
+
)}' of '${path}'`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (objectHasOwnProperty(this, prop)) {
|
|
109
|
+
this[prop] = newValue;
|
|
110
|
+
} else {
|
|
111
|
+
if (isDebug) {
|
|
112
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
113
|
+
console.error(TypeError(`Override property ${prop}`));
|
|
114
|
+
}
|
|
115
|
+
defineProperty(this, prop, {
|
|
116
|
+
value: newValue,
|
|
117
|
+
writable: true,
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
prop,
|
|
125
|
+
);
|
|
126
|
+
|
|
94
127
|
defineProperty(getter, 'originalValue', {
|
|
95
128
|
value,
|
|
96
129
|
writable: false,
|
|
@@ -98,32 +131,6 @@ export default function enablePropertyOverrides(
|
|
|
98
131
|
configurable: false,
|
|
99
132
|
});
|
|
100
133
|
|
|
101
|
-
const isDebug = setHas(debugProperties, prop);
|
|
102
|
-
|
|
103
|
-
function setter(newValue) {
|
|
104
|
-
if (obj === this) {
|
|
105
|
-
throw TypeError(
|
|
106
|
-
`Cannot assign to read only property '${String(
|
|
107
|
-
prop,
|
|
108
|
-
)}' of '${path}'`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (objectHasOwnProperty(this, prop)) {
|
|
112
|
-
this[prop] = newValue;
|
|
113
|
-
} else {
|
|
114
|
-
if (isDebug) {
|
|
115
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
116
|
-
console.error(TypeError(`Override property ${prop}`));
|
|
117
|
-
}
|
|
118
|
-
defineProperty(this, prop, {
|
|
119
|
-
value: newValue,
|
|
120
|
-
writable: true,
|
|
121
|
-
enumerable: true,
|
|
122
|
-
configurable: true,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
134
|
defineProperty(obj, prop, {
|
|
128
135
|
get: getter,
|
|
129
136
|
set: setter,
|
|
@@ -148,12 +155,11 @@ export default function enablePropertyOverrides(
|
|
|
148
155
|
}
|
|
149
156
|
// TypeScript does not allow symbols to be used as indexes because it
|
|
150
157
|
// cannot recokon types of symbolized properties.
|
|
151
|
-
// @ts-ignore
|
|
152
158
|
arrayForEach(ownKeys(descs), prop => enable(path, obj, prop, descs[prop]));
|
|
153
159
|
}
|
|
154
160
|
|
|
155
161
|
function enableProperties(path, obj, plan) {
|
|
156
|
-
for (const prop of
|
|
162
|
+
for (const prop of ownKeys(plan)) {
|
|
157
163
|
const desc = getOwnPropertyDescriptor(obj, prop);
|
|
158
164
|
if (!desc || desc.get || desc.set) {
|
|
159
165
|
// No not a value property, nothing to do.
|
|
@@ -161,10 +167,8 @@ export default function enablePropertyOverrides(
|
|
|
161
167
|
continue;
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
// with `String(..)` anyway just as good hygiene, since these paths are just
|
|
167
|
-
// for diagnostic purposes.
|
|
170
|
+
// In case `prop` is a symbol, we first coerce it with `String`,
|
|
171
|
+
// purely for diagnostic purposes.
|
|
168
172
|
const subPath = `${path}.${String(prop)}`;
|
|
169
173
|
const subPlan = plan[prop];
|
|
170
174
|
|
package/src/enablements.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { toStringTagSymbol } from './commons.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @file Exports {@code enablements}, a recursively defined
|
|
3
5
|
* JSON record defining the optimum set of intrinsics properties
|
|
@@ -74,6 +76,13 @@ export const minEnablements = {
|
|
|
74
76
|
'%ErrorPrototype%': {
|
|
75
77
|
name: true, // set by "precond", "ava", "node-fetch"
|
|
76
78
|
},
|
|
79
|
+
'%IteratorPrototype%': {
|
|
80
|
+
toString: true,
|
|
81
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
82
|
+
constructor: true,
|
|
83
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
84
|
+
[toStringTagSymbol]: true,
|
|
85
|
+
},
|
|
77
86
|
};
|
|
78
87
|
|
|
79
88
|
/**
|
|
@@ -152,6 +161,10 @@ export const moderateEnablements = {
|
|
|
152
161
|
|
|
153
162
|
'%IteratorPrototype%': {
|
|
154
163
|
toString: true,
|
|
164
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
165
|
+
constructor: true,
|
|
166
|
+
// https://github.com/tc39/proposal-iterator-helpers
|
|
167
|
+
[toStringTagSymbol]: true,
|
|
155
168
|
},
|
|
156
169
|
};
|
|
157
170
|
|
package/src/error/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Summary
|
|
|
5
5
|
* To that end, SES introduces an `assert` global with functions that add to errors annotations that will be hidden from callers. SES also tames the `Error` constructor to hide the `stack` to parent callers when possible (currently: v8, SpiderMonkey, XS).
|
|
6
6
|
* SES tames the global `console` and grants it the ability to reveal error annotations and stacks to the actual console.
|
|
7
7
|
* Both `assert` and `console` are powerful globals that SES does not implicitly carry into child compartments. When creating a child compartment, add `assert` to the compartment’s globals. Either add `console` too, or add a wrapper that annotates the console with a topic.
|
|
8
|
-
* SES hides annotations and stack traces by default. To reveal them,
|
|
8
|
+
* SES hides annotations and stack traces by default. To reveal them, SES uses mechanisms like `process.on("uncaughtException")` in Node.js to catch the error and log it back to the `console` tamed by `lockdown`.
|
|
9
9
|
* In the scope of the Agoric software ecosystem, this architecture will allow us to eventually introduce a more powerful distributed `console` that can meaningfully capture stack traces for a distributed debugger, based on the design of [Causeway](https://github.com/Agoric/agoric-sdk/issues/1318#issuecomment-662127549).
|
|
10
10
|
|
|
11
11
|
|
|
@@ -10,7 +10,7 @@ let abandon;
|
|
|
10
10
|
// below). Currently it only checks for the `process.abort` or `process.exit`
|
|
11
11
|
// found on Node. It should also sniff for a vat terminating function expected
|
|
12
12
|
// to be found within the start compartment of SwingSet vats. What else?
|
|
13
|
-
if (typeof process === 'object') {
|
|
13
|
+
if (typeof process === 'object' && process) {
|
|
14
14
|
abandon = process.abort || process.exit;
|
|
15
15
|
}
|
|
16
16
|
let raise;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
// Using TypeError minimizes risk of exposing the feral Error constructor
|
|
4
5
|
TypeError,
|
|
5
6
|
apply,
|
|
6
7
|
defineProperty,
|
|
@@ -13,36 +14,13 @@ import { makeRejectionHandlers } from './unhandled-rejection.js';
|
|
|
13
14
|
import './types.js';
|
|
14
15
|
import './internal-types.js';
|
|
15
16
|
|
|
17
|
+
const failFast = message => {
|
|
18
|
+
throw TypeError(message);
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
const wrapLogger = (logger, thisArg) =>
|
|
17
22
|
freeze((...args) => apply(logger, thisArg, args));
|
|
18
23
|
|
|
19
|
-
// eslint-disable-next-line no-restricted-globals
|
|
20
|
-
const originalConsole = /** @type {VirtualConsole} */ (
|
|
21
|
-
// eslint-disable-next-line no-nested-ternary
|
|
22
|
-
typeof console !== 'undefined'
|
|
23
|
-
? console
|
|
24
|
-
: typeof print === 'function'
|
|
25
|
-
? // Make a good-enough console for eshost (including only functions that
|
|
26
|
-
// log at a specific level with no special argument interpretation).
|
|
27
|
-
// https://console.spec.whatwg.org/#logging
|
|
28
|
-
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
|
|
29
|
-
// eslint-disable-next-line no-undef
|
|
30
|
-
wrapLogger(print),
|
|
31
|
-
)
|
|
32
|
-
: undefined
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// Upgrade a log-only console (as in `eshost -h SpiderMonkey`).
|
|
36
|
-
if (originalConsole && originalConsole.log) {
|
|
37
|
-
for (const methodName of ['warn', 'error']) {
|
|
38
|
-
if (!originalConsole[methodName]) {
|
|
39
|
-
defineProperty(originalConsole, methodName, {
|
|
40
|
-
value: wrapLogger(originalConsole.log, originalConsole),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
24
|
/**
|
|
47
25
|
* Wrap console unless suppressed.
|
|
48
26
|
* At the moment, the console is considered a host power in the start
|
|
@@ -60,9 +38,9 @@ export const tameConsole = (
|
|
|
60
38
|
unhandledRejectionTrapping = 'report',
|
|
61
39
|
optGetStackString = undefined,
|
|
62
40
|
) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
41
|
+
consoleTaming === 'safe' ||
|
|
42
|
+
consoleTaming === 'unsafe' ||
|
|
43
|
+
failFast(`unrecognized consoleTaming ${consoleTaming}`);
|
|
66
44
|
|
|
67
45
|
let loggedErrorHandler;
|
|
68
46
|
if (optGetStackString === undefined) {
|
|
@@ -73,6 +51,34 @@ export const tameConsole = (
|
|
|
73
51
|
getStackString: optGetStackString,
|
|
74
52
|
};
|
|
75
53
|
}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line no-restricted-globals
|
|
56
|
+
const originalConsole = /** @type {VirtualConsole} */ (
|
|
57
|
+
// eslint-disable-next-line no-nested-ternary
|
|
58
|
+
typeof globalThis.console !== 'undefined'
|
|
59
|
+
? globalThis.console
|
|
60
|
+
: typeof globalThis.print === 'function'
|
|
61
|
+
? // Make a good-enough console for eshost (including only functions that
|
|
62
|
+
// log at a specific level with no special argument interpretation).
|
|
63
|
+
// https://console.spec.whatwg.org/#logging
|
|
64
|
+
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
|
|
65
|
+
// eslint-disable-next-line no-undef
|
|
66
|
+
wrapLogger(globalThis.print),
|
|
67
|
+
)
|
|
68
|
+
: undefined
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Upgrade a log-only console (as in `eshost -h SpiderMonkey`).
|
|
72
|
+
if (originalConsole && originalConsole.log) {
|
|
73
|
+
for (const methodName of ['warn', 'error']) {
|
|
74
|
+
if (!originalConsole[methodName]) {
|
|
75
|
+
defineProperty(originalConsole, methodName, {
|
|
76
|
+
value: wrapLogger(originalConsole.log, originalConsole),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
const ourConsole = /** @type {VirtualConsole} */ (
|
|
77
83
|
consoleTaming === 'unsafe'
|
|
78
84
|
? originalConsole
|
|
@@ -95,21 +101,36 @@ export const tameConsole = (
|
|
|
95
101
|
/* eslint-disable @endo/no-polymorphic-call */
|
|
96
102
|
|
|
97
103
|
// Node.js
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
const globalProcess = globalThis.process || undefined;
|
|
105
|
+
if (
|
|
106
|
+
errorTrapping !== 'none' &&
|
|
107
|
+
typeof globalProcess === 'object' &&
|
|
108
|
+
typeof globalProcess.on === 'function'
|
|
109
|
+
) {
|
|
110
|
+
let terminate;
|
|
111
|
+
if (errorTrapping === 'platform' || errorTrapping === 'exit') {
|
|
112
|
+
const { exit } = globalProcess;
|
|
113
|
+
// If there is a function-valued process.on but no function-valued process.exit,
|
|
114
|
+
// fail early without caring whether errorTrapping is "platform" only by default.
|
|
115
|
+
typeof exit === 'function' || failFast('missing process.exit');
|
|
116
|
+
terminate = () => exit(globalProcess.exitCode || -1);
|
|
117
|
+
} else if (errorTrapping === 'abort') {
|
|
118
|
+
terminate = globalProcess.abort;
|
|
119
|
+
typeof terminate === 'function' || failFast('missing process.abort');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
globalProcess.on('uncaughtException', error => {
|
|
100
123
|
// causalConsole is born frozen so not vulnerable to method tampering.
|
|
101
124
|
ourConsole.error(error);
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
} else if (errorTrapping === 'abort') {
|
|
105
|
-
globalThis.process.abort();
|
|
125
|
+
if (terminate) {
|
|
126
|
+
terminate();
|
|
106
127
|
}
|
|
107
128
|
});
|
|
108
129
|
}
|
|
109
|
-
|
|
110
130
|
if (
|
|
111
131
|
unhandledRejectionTrapping !== 'none' &&
|
|
112
|
-
|
|
132
|
+
typeof globalProcess === 'object' &&
|
|
133
|
+
typeof globalProcess.on === 'function'
|
|
113
134
|
) {
|
|
114
135
|
const handleRejection = reason => {
|
|
115
136
|
// 'platform' and 'report' just log the reason.
|
|
@@ -119,32 +140,32 @@ export const tameConsole = (
|
|
|
119
140
|
const h = makeRejectionHandlers(handleRejection);
|
|
120
141
|
if (h) {
|
|
121
142
|
// Rejection handlers are supported.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
globalProcess.on('unhandledRejection', h.unhandledRejectionHandler);
|
|
144
|
+
globalProcess.on('rejectionHandled', h.rejectionHandledHandler);
|
|
145
|
+
globalProcess.on('exit', h.processTerminationHandler);
|
|
125
146
|
}
|
|
126
147
|
}
|
|
127
148
|
|
|
128
149
|
// Browser
|
|
150
|
+
const globalWindow = globalThis.window || undefined;
|
|
129
151
|
if (
|
|
130
152
|
errorTrapping !== 'none' &&
|
|
131
|
-
|
|
132
|
-
|
|
153
|
+
typeof globalWindow === 'object' &&
|
|
154
|
+
typeof globalWindow.addEventListener === 'function'
|
|
133
155
|
) {
|
|
134
|
-
|
|
156
|
+
globalWindow.addEventListener('error', event => {
|
|
135
157
|
event.preventDefault();
|
|
136
158
|
// 'platform' and 'report' just log the reason.
|
|
137
159
|
ourConsole.error(event.error);
|
|
138
160
|
if (errorTrapping === 'exit' || errorTrapping === 'abort') {
|
|
139
|
-
|
|
161
|
+
globalWindow.location.href = `about:blank`;
|
|
140
162
|
}
|
|
141
163
|
});
|
|
142
164
|
}
|
|
143
|
-
|
|
144
165
|
if (
|
|
145
166
|
unhandledRejectionTrapping !== 'none' &&
|
|
146
|
-
|
|
147
|
-
|
|
167
|
+
typeof globalWindow === 'object' &&
|
|
168
|
+
typeof globalWindow.addEventListener === 'function'
|
|
148
169
|
) {
|
|
149
170
|
const handleRejection = reason => {
|
|
150
171
|
ourConsole.error('SES_UNHANDLED_REJECTION:', reason);
|
|
@@ -153,17 +174,17 @@ export const tameConsole = (
|
|
|
153
174
|
const h = makeRejectionHandlers(handleRejection);
|
|
154
175
|
if (h) {
|
|
155
176
|
// Rejection handlers are supported.
|
|
156
|
-
|
|
177
|
+
globalWindow.addEventListener('unhandledrejection', event => {
|
|
157
178
|
event.preventDefault();
|
|
158
179
|
h.unhandledRejectionHandler(event.reason, event.promise);
|
|
159
180
|
});
|
|
160
181
|
|
|
161
|
-
|
|
182
|
+
globalWindow.addEventListener('rejectionhandled', event => {
|
|
162
183
|
event.preventDefault();
|
|
163
184
|
h.rejectionHandledHandler(event.promise);
|
|
164
185
|
});
|
|
165
186
|
|
|
166
|
-
|
|
187
|
+
globalWindow.addEventListener('beforeunload', _event => {
|
|
167
188
|
h.processTerminationHandler();
|
|
168
189
|
});
|
|
169
190
|
}
|
package/src/lockdown.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
// @ts-check
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { getEnvironmentOption as getenv } from '@endo/env-options';
|
|
18
18
|
import {
|
|
19
19
|
FERAL_FUNCTION,
|
|
20
20
|
FERAL_EVAL,
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
stringSplit,
|
|
27
27
|
noEvalEvaluate,
|
|
28
28
|
getOwnPropertyNames,
|
|
29
|
+
getPrototypeOf,
|
|
29
30
|
} from './commons.js';
|
|
30
31
|
import { makeHardener } from './make-hardener.js';
|
|
31
32
|
import { makeIntrinsicsCollector } from './intrinsics.js';
|
|
@@ -53,6 +54,7 @@ import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
|
|
|
53
54
|
import { makeCompartmentConstructor } from './compartment.js';
|
|
54
55
|
import { tameHarden } from './tame-harden.js';
|
|
55
56
|
import { tameSymbolConstructor } from './tame-symbol-constructor.js';
|
|
57
|
+
import { tameFauxDataProperties } from './tame-faux-data-properties.js';
|
|
56
58
|
|
|
57
59
|
/** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
|
|
58
60
|
|
|
@@ -155,8 +157,6 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
155
157
|
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
|
|
156
158
|
// for an explanation.
|
|
157
159
|
|
|
158
|
-
const { getEnvironmentOption: getenv } = makeEnvironmentCaptor(globalThis);
|
|
159
|
-
|
|
160
160
|
const {
|
|
161
161
|
errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
|
|
162
162
|
errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit" | undefined} */ (
|
|
@@ -281,6 +281,14 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
281
281
|
|
|
282
282
|
const intrinsics = finalIntrinsics();
|
|
283
283
|
|
|
284
|
+
const hostIntrinsics = { __proto__: null };
|
|
285
|
+
|
|
286
|
+
// The Node.js Buffer is a derived class of Uint8Array, and as such is often
|
|
287
|
+
// passed around where a Uint8Array is expected.
|
|
288
|
+
if (typeof globalThis.Buffer === 'function') {
|
|
289
|
+
hostIntrinsics.Buffer = globalThis.Buffer;
|
|
290
|
+
}
|
|
291
|
+
|
|
284
292
|
/**
|
|
285
293
|
* Wrap console unless suppressed.
|
|
286
294
|
* At the moment, the console is considered a host power in the start
|
|
@@ -301,6 +309,19 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
301
309
|
);
|
|
302
310
|
globalThis.console = /** @type {Console} */ (consoleRecord.console);
|
|
303
311
|
|
|
312
|
+
// The untamed Node.js console cannot itself be hardened as it has mutable
|
|
313
|
+
// internal properties, but some of these properties expose internal versions
|
|
314
|
+
// of classes from node's "primordials" concept.
|
|
315
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
316
|
+
if (typeof (/** @type {any} */ (consoleRecord.console)._times) === 'object') {
|
|
317
|
+
// SafeMap is a derived Map class used internally by Node
|
|
318
|
+
// There doesn't seem to be a cleaner way to reach it.
|
|
319
|
+
hostIntrinsics.SafeMap = getPrototypeOf(
|
|
320
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
321
|
+
/** @type {any} */ (consoleRecord.console)._times,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
304
325
|
// @ts-ignore assert is absent on globalThis type def.
|
|
305
326
|
if (errorTaming === 'unsafe' && globalThis.assert === assert) {
|
|
306
327
|
// If errorTaming is 'unsafe' we replace the global assert with
|
|
@@ -315,6 +336,8 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
315
336
|
// Replace *Locale* methods with their non-locale equivalents
|
|
316
337
|
tameLocaleMethods(intrinsics, localeTaming);
|
|
317
338
|
|
|
339
|
+
tameFauxDataProperties(intrinsics);
|
|
340
|
+
|
|
318
341
|
/**
|
|
319
342
|
* 2. WHITELIST to standardize the environment.
|
|
320
343
|
*/
|
|
@@ -388,20 +411,28 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
388
411
|
|
|
389
412
|
// Finally register and optionally freeze all the intrinsics. This
|
|
390
413
|
// must be the operation that modifies the intrinsics.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
414
|
+
const toHarden = {
|
|
415
|
+
intrinsics,
|
|
416
|
+
hostIntrinsics,
|
|
417
|
+
globals: {
|
|
418
|
+
// Harden evaluators
|
|
419
|
+
Function: globalThis.Function,
|
|
420
|
+
eval: globalThis.eval,
|
|
421
|
+
// @ts-ignore Compartment does exist on globalThis
|
|
422
|
+
Compartment: globalThis.Compartment,
|
|
423
|
+
|
|
424
|
+
// Harden Symbol
|
|
425
|
+
Symbol: globalThis.Symbol,
|
|
426
|
+
},
|
|
427
|
+
};
|
|
398
428
|
|
|
399
429
|
// Harden Symbol and properties for initialGlobalPropertyNames in the host realm
|
|
400
|
-
tamedHarden(globalThis.Symbol);
|
|
401
430
|
for (const prop of getOwnPropertyNames(initialGlobalPropertyNames)) {
|
|
402
|
-
|
|
431
|
+
toHarden.globals[prop] = globalThis[prop];
|
|
403
432
|
}
|
|
404
433
|
|
|
434
|
+
tamedHarden(toHarden);
|
|
435
|
+
|
|
405
436
|
return tamedHarden;
|
|
406
437
|
};
|
|
407
438
|
|
package/src/module-instance.js
CHANGED
|
@@ -32,7 +32,7 @@ export const makeThirdPartyModuleInstance = (
|
|
|
32
32
|
moduleSpecifier,
|
|
33
33
|
resolvedImports,
|
|
34
34
|
) => {
|
|
35
|
-
const { exportsProxy,
|
|
35
|
+
const { exportsProxy, exportsTarget, activate } = getDeferredExports(
|
|
36
36
|
compartment,
|
|
37
37
|
weakmapGet(compartmentPrivateFields, compartment),
|
|
38
38
|
moduleAliases,
|
|
@@ -51,7 +51,7 @@ export const makeThirdPartyModuleInstance = (
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
arrayForEach(staticModuleRecord.exports, name => {
|
|
54
|
-
let value =
|
|
54
|
+
let value = exportsTarget[name];
|
|
55
55
|
const updaters = [];
|
|
56
56
|
|
|
57
57
|
const get = () => value;
|
|
@@ -63,7 +63,7 @@ export const makeThirdPartyModuleInstance = (
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
defineProperty(
|
|
66
|
+
defineProperty(exportsTarget, name, {
|
|
67
67
|
get,
|
|
68
68
|
set,
|
|
69
69
|
enumerable: true,
|
|
@@ -75,9 +75,9 @@ export const makeThirdPartyModuleInstance = (
|
|
|
75
75
|
update(value);
|
|
76
76
|
};
|
|
77
77
|
});
|
|
78
|
-
// This is enough to support import * from cjs - the '*' field doesn't need to be in exports nor
|
|
78
|
+
// This is enough to support import * from cjs - the '*' field doesn't need to be in exports nor exportsTarget because import will only ever access it via notifiers
|
|
79
79
|
notifiers['*'] = update => {
|
|
80
|
-
update(
|
|
80
|
+
update(exportsTarget);
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -97,7 +97,7 @@ export const makeThirdPartyModuleInstance = (
|
|
|
97
97
|
try {
|
|
98
98
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
99
99
|
staticModuleRecord.execute(
|
|
100
|
-
|
|
100
|
+
exportsTarget,
|
|
101
101
|
compartment,
|
|
102
102
|
resolvedImports,
|
|
103
103
|
);
|
|
@@ -143,7 +143,7 @@ export const makeModuleInstance = (
|
|
|
143
143
|
|
|
144
144
|
const { __shimTransforms__, importMetaHook } = compartmentFields;
|
|
145
145
|
|
|
146
|
-
const { exportsProxy,
|
|
146
|
+
const { exportsProxy, exportsTarget, activate } = getDeferredExports(
|
|
147
147
|
compartment,
|
|
148
148
|
compartmentFields,
|
|
149
149
|
moduleAliases,
|
|
@@ -342,7 +342,7 @@ export const makeModuleInstance = (
|
|
|
342
342
|
);
|
|
343
343
|
|
|
344
344
|
const notifyStar = update => {
|
|
345
|
-
update(
|
|
345
|
+
update(exportsTarget);
|
|
346
346
|
};
|
|
347
347
|
notifiers['*'] = notifyStar;
|
|
348
348
|
|
|
@@ -435,10 +435,10 @@ export const makeModuleInstance = (
|
|
|
435
435
|
// and the string must correspond to a valid identifier, sorting these
|
|
436
436
|
// properties works for this specific case.
|
|
437
437
|
arrayForEach(arraySort(keys(exportsProps)), k =>
|
|
438
|
-
defineProperty(
|
|
438
|
+
defineProperty(exportsTarget, k, exportsProps[k]),
|
|
439
439
|
);
|
|
440
440
|
|
|
441
|
-
freeze(
|
|
441
|
+
freeze(exportsTarget);
|
|
442
442
|
activate();
|
|
443
443
|
}
|
|
444
444
|
|