ses 1.15.0 → 2.0.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/dist/lockdown.cjs +360 -219
- package/dist/lockdown.mjs +360 -219
- package/dist/lockdown.umd.js +360 -219
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +360 -219
- package/dist/ses.cjs +360 -219
- package/dist/ses.mjs +360 -219
- package/dist/ses.umd.js +360 -219
- package/dist/ses.umd.min.js +1 -1
- package/package.json +7 -7
- package/src/commons.js +4 -1
- package/src/enablements.js +15 -14
- package/src/get-anonymous-intrinsics.js +2 -2
- package/src/lockdown.js +2 -0
- package/src/module-load.js +4 -4
- package/src/permits.js +13 -4
- package/src/tame-nan-sidechannel.js +103 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"test": "tsd && ava",
|
|
92
92
|
"test:hermes": "./scripts/hermes-test.sh",
|
|
93
93
|
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp",
|
|
94
|
-
"postpack": "git clean -fX
|
|
94
|
+
"postpack": "git clean -fX -e node_modules/"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
97
|
"@endo/cache-map": "^1.1.0",
|
|
@@ -103,9 +103,9 @@
|
|
|
103
103
|
"@babel/parser": "~7.28.3",
|
|
104
104
|
"@babel/traverse": "~7.28.3",
|
|
105
105
|
"@babel/types": "~7.28.2",
|
|
106
|
-
"@endo/compartment-mapper": "^2.
|
|
107
|
-
"@endo/module-source": "^1.4.
|
|
108
|
-
"@endo/test262-runner": "^0.1.
|
|
106
|
+
"@endo/compartment-mapper": "^2.1.0",
|
|
107
|
+
"@endo/module-source": "^1.4.1",
|
|
108
|
+
"@endo/test262-runner": "^0.1.50",
|
|
109
109
|
"ava": "catalog:dev",
|
|
110
110
|
"c8": "catalog:dev",
|
|
111
111
|
"core-js": "^3.31.0",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"hermes-engine-cli": "^0.12.0",
|
|
114
114
|
"terser": "^5.16.6",
|
|
115
115
|
"tsd": "catalog:dev",
|
|
116
|
-
"typescript": "
|
|
116
|
+
"typescript": "catalog:dev"
|
|
117
117
|
},
|
|
118
118
|
"files": [
|
|
119
119
|
"./*.d.ts",
|
|
@@ -143,5 +143,5 @@
|
|
|
143
143
|
"typeCoverage": {
|
|
144
144
|
"atLeast": 81.17
|
|
145
145
|
},
|
|
146
|
-
"gitHead": "
|
|
146
|
+
"gitHead": "c3616c39c35f2d052f7083aba31054910951beb4"
|
|
147
147
|
}
|
package/src/commons.js
CHANGED
|
@@ -26,11 +26,14 @@ export const {
|
|
|
26
26
|
ArrayBuffer,
|
|
27
27
|
Date,
|
|
28
28
|
FinalizationRegistry,
|
|
29
|
-
|
|
29
|
+
// Renamed to FERAL_* because it enables the NaN side-channel
|
|
30
|
+
Float64Array: FERAL_FLOAT64_ARRAY,
|
|
31
|
+
DataView,
|
|
30
32
|
JSON,
|
|
31
33
|
Map,
|
|
32
34
|
Math,
|
|
33
35
|
Number,
|
|
36
|
+
BigInt,
|
|
34
37
|
Object,
|
|
35
38
|
Promise,
|
|
36
39
|
Proxy,
|
package/src/enablements.js
CHANGED
|
@@ -95,38 +95,39 @@ export const moderateEnablements = {
|
|
|
95
95
|
...minEnablements,
|
|
96
96
|
|
|
97
97
|
'%ObjectPrototype%': {
|
|
98
|
-
|
|
98
|
+
...minEnablements['%ObjectPrototype%'],
|
|
99
99
|
valueOf: true,
|
|
100
100
|
},
|
|
101
101
|
|
|
102
|
-
'%ArrayPrototype%': {
|
|
103
|
-
toString: true,
|
|
104
|
-
push: true, // set by "Google Analytics"
|
|
105
|
-
concat: true, // set by mobx generated code (old TS compiler?)
|
|
106
|
-
[iteratorSymbol]: true, // set by mobx generated code (old TS compiler?)
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
'%IteratorPrototype%': {
|
|
110
|
-
[iteratorSymbol]: true, // is sometimes used in custom iterators and generators implementations eg. @rive-app/canvas
|
|
111
|
-
},
|
|
112
|
-
|
|
113
102
|
// Function.prototype has no 'prototype' property to enable.
|
|
114
103
|
// Function instances have their own 'name' and 'length' properties
|
|
115
104
|
// which are configurable and non-writable. Thus, they are already
|
|
116
105
|
// non-assignable anyway.
|
|
117
106
|
'%FunctionPrototype%': {
|
|
107
|
+
...minEnablements['%FunctionPrototype%'],
|
|
118
108
|
constructor: true, // set by "regenerator-runtime"
|
|
119
109
|
bind: true, // set by "underscore", "express"
|
|
120
|
-
toString: true, // set by "rollup"
|
|
121
110
|
},
|
|
122
111
|
|
|
123
112
|
'%ErrorPrototype%': {
|
|
113
|
+
...minEnablements['%ErrorPrototype%'],
|
|
124
114
|
constructor: true, // set by "fast-json-patch", "node-fetch"
|
|
125
115
|
message: true,
|
|
126
|
-
name: true, // set by "precond", "ava", "node-fetch", "node 14"
|
|
127
116
|
toString: true, // set by "bluebird"
|
|
128
117
|
},
|
|
129
118
|
|
|
119
|
+
'%IteratorPrototype%': {
|
|
120
|
+
...minEnablements['%IteratorPrototype%'],
|
|
121
|
+
[iteratorSymbol]: true, // is sometimes used in custom iterators and generators implementations eg. @rive-app/canvas
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
'%ArrayPrototype%': {
|
|
125
|
+
toString: true,
|
|
126
|
+
push: true, // set by "Google Analytics"
|
|
127
|
+
concat: true, // set by mobx generated code (old TS compiler?)
|
|
128
|
+
[iteratorSymbol]: true, // set by mobx generated code (old TS compiler?)
|
|
129
|
+
},
|
|
130
|
+
|
|
130
131
|
'%TypeErrorPrototype%': {
|
|
131
132
|
constructor: true, // set by "readable-stream"
|
|
132
133
|
message: true, // set by "tape"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FERAL_FUNCTION,
|
|
3
|
-
|
|
3
|
+
FERAL_FLOAT64_ARRAY,
|
|
4
4
|
Map,
|
|
5
5
|
Set,
|
|
6
6
|
String,
|
|
@@ -72,7 +72,7 @@ export const getAnonymousIntrinsics = () => {
|
|
|
72
72
|
|
|
73
73
|
// 22.2.1 The %TypedArray% Intrinsic Object
|
|
74
74
|
|
|
75
|
-
const TypedArray = getPrototypeOf(
|
|
75
|
+
const TypedArray = getPrototypeOf(FERAL_FLOAT64_ARRAY);
|
|
76
76
|
|
|
77
77
|
// 23.1.5.2 The %MapIteratorPrototype% Object
|
|
78
78
|
|
package/src/lockdown.js
CHANGED
|
@@ -36,6 +36,7 @@ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
|
|
|
36
36
|
import tameFunctionConstructors from './tame-function-constructors.js';
|
|
37
37
|
import tameDateConstructor from './tame-date-constructor.js';
|
|
38
38
|
import tameMathObject from './tame-math-object.js';
|
|
39
|
+
import { tameNaNSideChannel } from './tame-nan-sidechannel.js';
|
|
39
40
|
import tameRegExpConstructor from './tame-regexp-constructor.js';
|
|
40
41
|
import enablePropertyOverrides from './enable-property-overrides.js';
|
|
41
42
|
import tameLocaleMethods from './tame-locale-methods.js';
|
|
@@ -353,6 +354,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
353
354
|
addIntrinsics(tameDateConstructor());
|
|
354
355
|
addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
|
|
355
356
|
addIntrinsics(tameMathObject());
|
|
357
|
+
tameNaNSideChannel();
|
|
356
358
|
addIntrinsics(tameRegExpConstructor(regExpTaming));
|
|
357
359
|
addIntrinsics(tameSymbolConstructor());
|
|
358
360
|
addIntrinsics(shimArrayBufferTransfer());
|
package/src/module-load.js
CHANGED
|
@@ -510,7 +510,7 @@ const memoizedLoadWithErrorAnnotation = (
|
|
|
510
510
|
/**
|
|
511
511
|
* If `aggregateErrors` is `false`, the `errors` property of the fulfilled object
|
|
512
512
|
* will always be empty.
|
|
513
|
-
* @param {{errors?: Error[], noAggregateErrors?: boolean}} [options]
|
|
513
|
+
* @param {{errors?: Error[], noAggregateErrors?: boolean | undefined}} [options]
|
|
514
514
|
*/
|
|
515
515
|
const asyncJobQueue = ({ errors = [], noAggregateErrors = false } = {}) => {
|
|
516
516
|
/** @type {Set<Promise<undefined>>} */
|
|
@@ -552,7 +552,7 @@ const asyncJobQueue = ({ errors = [], noAggregateErrors = false } = {}) => {
|
|
|
552
552
|
/**
|
|
553
553
|
* If `aggregateErrors` is `false`, the `errors` property of the returned object
|
|
554
554
|
* will always be empty.
|
|
555
|
-
* @param {{errors?: Error[], noAggregateErrors?: boolean}} [options]
|
|
555
|
+
* @param {{errors?: Error[], noAggregateErrors?: boolean | undefined}} [options]
|
|
556
556
|
*/
|
|
557
557
|
const syncJobQueue = ({ errors = [], noAggregateErrors = false } = {}) => {
|
|
558
558
|
let current = [];
|
|
@@ -625,7 +625,7 @@ const preferAsync = (asyncImpl, _syncImpl) => asyncImpl;
|
|
|
625
625
|
* @param {WeakMap<object, object>} moduleAliases
|
|
626
626
|
* @param {Compartment} compartment
|
|
627
627
|
* @param {string} moduleSpecifier - The module specifier to load.
|
|
628
|
-
* @param {{ noAggregateErrors?: boolean}} options
|
|
628
|
+
* @param {{ noAggregateErrors?: boolean | undefined}} options
|
|
629
629
|
*/
|
|
630
630
|
export const load = async (
|
|
631
631
|
compartmentPrivateFields,
|
|
@@ -676,7 +676,7 @@ export const load = async (
|
|
|
676
676
|
* @param {WeakMap<object, object>} moduleAliases
|
|
677
677
|
* @param {Compartment} compartment
|
|
678
678
|
* @param {string} moduleSpecifier - The module specifier to load.
|
|
679
|
-
* @param {{ noAggregateErrors?: boolean}} options
|
|
679
|
+
* @param {{ noAggregateErrors?: boolean | undefined}} options
|
|
680
680
|
*/
|
|
681
681
|
|
|
682
682
|
export const loadNow = (
|
package/src/permits.js
CHANGED
|
@@ -59,10 +59,7 @@ export const universalPropertyNames = {
|
|
|
59
59
|
Boolean: 'Boolean',
|
|
60
60
|
DataView: 'DataView',
|
|
61
61
|
EvalError: 'EvalError',
|
|
62
|
-
|
|
63
|
-
Float16Array: 'Float16Array',
|
|
64
|
-
Float32Array: 'Float32Array',
|
|
65
|
-
Float64Array: 'Float64Array',
|
|
62
|
+
|
|
66
63
|
Int8Array: 'Int8Array',
|
|
67
64
|
Int16Array: 'Int16Array',
|
|
68
65
|
Int32Array: 'Int32Array',
|
|
@@ -144,6 +141,18 @@ export const initialGlobalPropertyNames = {
|
|
|
144
141
|
|
|
145
142
|
Math: '%InitialMath%',
|
|
146
143
|
|
|
144
|
+
// We move these from universalPropertyNames because the NaN side channel
|
|
145
|
+
// means that they are not quite harmless.
|
|
146
|
+
// We move them to initialGlobalPropertyNames so that they'll still be
|
|
147
|
+
// included in the primordials, repaired, and hardened. Thus, they
|
|
148
|
+
// can be endowed into compartments without hazard beyond the
|
|
149
|
+
// NaN side channel.
|
|
150
|
+
//
|
|
151
|
+
// // https://github.com/tc39/proposal-float16array
|
|
152
|
+
Float16Array: 'Float16Array',
|
|
153
|
+
Float32Array: 'Float32Array',
|
|
154
|
+
Float64Array: 'Float64Array',
|
|
155
|
+
|
|
147
156
|
// ESNext
|
|
148
157
|
|
|
149
158
|
// From Error-stack proposal
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Object, DataView, Reflect, Number } from './commons.js';
|
|
2
|
+
|
|
3
|
+
const { is, defineProperty, entries } = Object;
|
|
4
|
+
const { apply } = Reflect;
|
|
5
|
+
|
|
6
|
+
const { prototype: dataViewPrototype } = DataView;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* These `FERAL*` methods open up the NaN side-channel on some platforms,
|
|
10
|
+
* like v8. Thus, we need to encapsulate them and replace them with wrappers
|
|
11
|
+
* that canonicaize NaNs.
|
|
12
|
+
*/
|
|
13
|
+
const {
|
|
14
|
+
setFloat16: FERAL_SET_FLOAT16,
|
|
15
|
+
setFloat32: FERAL_SET_FLOAT32,
|
|
16
|
+
setFloat64: FERAL_SET_FLOAT64,
|
|
17
|
+
|
|
18
|
+
setUint16,
|
|
19
|
+
setUint32,
|
|
20
|
+
setBigUint64,
|
|
21
|
+
} = dataViewPrototype;
|
|
22
|
+
|
|
23
|
+
// See https://webidl.spec.whatwg.org/#js-unrestricted-double which implies
|
|
24
|
+
// that this is the canonical NaN for web standards.
|
|
25
|
+
// Casual googling stongly suggests that this is also the cosmWasm
|
|
26
|
+
// canonical NaN. But I have not yet found an authoritative page stating this.
|
|
27
|
+
const canonicalNaN = 0x7ff8000000000000n;
|
|
28
|
+
|
|
29
|
+
// Use method shorthand syntax to be this-sensitive but now be constructable
|
|
30
|
+
// nor have a `prototype` property.
|
|
31
|
+
const methods = {
|
|
32
|
+
/**
|
|
33
|
+
* @param {number} byteOffset
|
|
34
|
+
* @param {number} value
|
|
35
|
+
* @param {boolean} [littleEndian]
|
|
36
|
+
*/
|
|
37
|
+
setFloat16(byteOffset, value, littleEndian = undefined) {
|
|
38
|
+
if (is(value, NaN)) {
|
|
39
|
+
return apply(setUint16, this, [
|
|
40
|
+
byteOffset,
|
|
41
|
+
Number(canonicalNaN),
|
|
42
|
+
littleEndian,
|
|
43
|
+
]);
|
|
44
|
+
} else {
|
|
45
|
+
return apply(FERAL_SET_FLOAT16, this, [byteOffset, value, littleEndian]);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* @param {number} byteOffset
|
|
50
|
+
* @param {number} value
|
|
51
|
+
* @param {boolean} [littleEndian]
|
|
52
|
+
*/
|
|
53
|
+
setFloat32(byteOffset, value, littleEndian = undefined) {
|
|
54
|
+
if (is(value, NaN)) {
|
|
55
|
+
return apply(setUint32, this, [
|
|
56
|
+
byteOffset,
|
|
57
|
+
Number(canonicalNaN),
|
|
58
|
+
littleEndian,
|
|
59
|
+
]);
|
|
60
|
+
} else {
|
|
61
|
+
return apply(FERAL_SET_FLOAT32, this, [byteOffset, value, littleEndian]);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* @param {number} byteOffset
|
|
66
|
+
* @param {number} value
|
|
67
|
+
* @param {boolean} [littleEndian]
|
|
68
|
+
*/
|
|
69
|
+
setFloat64(byteOffset, value, littleEndian = undefined) {
|
|
70
|
+
if (is(value, NaN)) {
|
|
71
|
+
return apply(setBigUint64, this, [
|
|
72
|
+
byteOffset,
|
|
73
|
+
canonicalNaN,
|
|
74
|
+
littleEndian,
|
|
75
|
+
]);
|
|
76
|
+
} else {
|
|
77
|
+
return apply(FERAL_SET_FLOAT64, this, [byteOffset, value, littleEndian]);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Replaces the dangerous `setFloat*` methods on `DataView.prototype`
|
|
84
|
+
* with safe wrappers that first canonicalize NaNs before calling the
|
|
85
|
+
* original hidden methods.
|
|
86
|
+
* By itself, this does not make us safe against the NaN side channel.
|
|
87
|
+
* Separately, we do not include the `Float*Array` constructors on the
|
|
88
|
+
* list of universal safe globals. Thus, constructed compartments do not
|
|
89
|
+
* get these by default.
|
|
90
|
+
*
|
|
91
|
+
* These replacement `setFloat*` methods canonicalize NaN, but they
|
|
92
|
+
* do not canonicalize `-0` to `0`. If callers wish to do so, they should do
|
|
93
|
+
* it themselves before calling these
|
|
94
|
+
*/
|
|
95
|
+
export const tameNaNSideChannel = () => {
|
|
96
|
+
for (const [name, method] of entries(methods)) {
|
|
97
|
+
defineProperty(dataViewPrototype, name, {
|
|
98
|
+
// Since we're redefining properties that already exist, by omitting the
|
|
99
|
+
// other descriptor attributes here, they are unchanged.
|
|
100
|
+
value: method,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|