ses 1.13.0 → 1.14.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 +68 -50
- package/dist/lockdown.cjs +1032 -714
- package/dist/lockdown.mjs +1032 -714
- package/dist/lockdown.umd.js +1032 -714
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +1010 -580
- package/dist/ses.cjs +1032 -714
- package/dist/ses.mjs +1032 -714
- package/dist/ses.umd.js +1032 -714
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +10 -0
- package/package.json +10 -86
- package/src/cauterize-property.js +2 -2
- package/src/commons.js +17 -16
- package/src/compartment.js +104 -36
- package/src/enable-property-overrides.js +4 -4
- package/src/error/assert.js +2 -2
- package/src/error/note-log-args.js +5 -4
- package/src/global-object.js +3 -3
- package/src/intrinsics.js +8 -8
- package/src/make-hardener.js +4 -4
- package/src/module-link.js +4 -4
- package/src/module-load.js +48 -13
- package/src/permits-intrinsics.js +8 -8
- package/src/permits.js +2 -0
- package/src/scope-constants.js +2 -2
- package/src/tame-locale-methods.js +2 -2
- package/src/tame-regenerator-runtime.js +2 -2
- package/types.d.ts +10 -0
- package/src/make-lru-cachemap.js +0 -221
package/README.md
CHANGED
|
@@ -32,12 +32,12 @@ systems.
|
|
|
32
32
|
[](https://agoric.com/)
|
|
33
33
|
[](https://metamask.io/)
|
|
34
34
|
|
|
35
|
-
See https://github.com/Agoric/Jessie to see how SES fits into the various
|
|
35
|
+
See <https://github.com/Agoric/Jessie> to see how SES fits into the various
|
|
36
36
|
flavors of confined JavaScript execution. And visit
|
|
37
|
-
https://ses-demo.agoric.app/demos
|
|
37
|
+
<https://ses-demo.agoric.app/demos/> for a demo.
|
|
38
38
|
|
|
39
39
|
SES starts where the Caja project left off
|
|
40
|
-
https://github.com/google/caja/wiki/SES
|
|
40
|
+
<https://github.com/google/caja/wiki/SES>, and goes on to introduce compartments
|
|
41
41
|
and modernize the permitted JavaScript features.
|
|
42
42
|
|
|
43
43
|
Please join the conversation on our [Mailing List][SES Strategy Group] and
|
|
@@ -45,11 +45,11 @@ Please join the conversation on our [Mailing List][SES Strategy Group] and
|
|
|
45
45
|
We record a [weekly conference call][SES Strategy Recordings] with the Hardened
|
|
46
46
|
JavaScript engineering community.
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
*Hardened JavaScript*, Kris Kowal:
|
|
49
49
|
|
|
50
50
|
[](https://www.youtube.com/watch?v=RZ7bBIU8DRc)
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
*Don't add Security, Remove Insecurity*, Mark Miller:
|
|
53
53
|
|
|
54
54
|
[](https://www.youtube.com/watch?v=u-XETUbxNUU)
|
|
55
55
|
|
|
@@ -152,7 +152,6 @@ still closes over the mutable counter.
|
|
|
152
152
|
Hardening an object graph makes the surface immutable, but does not guarantee
|
|
153
153
|
that methods are free of side effects.
|
|
154
154
|
|
|
155
|
-
|
|
156
155
|
### Compartment
|
|
157
156
|
|
|
158
157
|
SES introduces the `Compartment` constructor.
|
|
@@ -278,10 +277,10 @@ module descriptors.
|
|
|
278
277
|
A compartment can be configured with module descriptors, from highest to lowest
|
|
279
278
|
precedence:
|
|
280
279
|
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
* the `modules` map provided to the `Compartment` constructor,
|
|
281
|
+
* returned by a `moduleMapHook(specifier)` passed as an option to the
|
|
283
282
|
`Compartment` constructor.
|
|
284
|
-
|
|
283
|
+
* returned by either the `importHook(specifier)` or `importNowHook(specifier)`
|
|
285
284
|
option passed to the `Compartment` constructor. Calling
|
|
286
285
|
`compartment.import(specifier)` falls through to the `importHook` which may
|
|
287
286
|
return a promises, whereas `compartment.importNow(specifier)` falls through
|
|
@@ -341,13 +340,13 @@ forms.
|
|
|
341
340
|
|
|
342
341
|
##### Descriptors with `source` property
|
|
343
342
|
|
|
344
|
-
|
|
343
|
+
* If fhe value of the `source` property is a string, the parent compartment
|
|
345
344
|
loads the module but the compartment itself initializes the module.
|
|
346
345
|
|
|
347
|
-
|
|
346
|
+
* Otherwise, if the value of the `source` property is the module source, the
|
|
348
347
|
module is initialized from the module source.
|
|
349
348
|
|
|
350
|
-
|
|
349
|
+
* Otherwise, the value of the `source` property must be an object. The module
|
|
351
350
|
is loaded and initialized from the object according to the [virtual module
|
|
352
351
|
source](#VirtualModuleSource) pattern.
|
|
353
352
|
|
|
@@ -363,20 +362,20 @@ are resolved using the `resolveHook`.
|
|
|
363
362
|
|
|
364
363
|
##### Descriptors with `namespace` property
|
|
365
364
|
|
|
366
|
-
|
|
365
|
+
* If fhe value of the `namespace` property is a string, the descriptor shares a
|
|
367
366
|
module to be loaded and initialized by the compartment referred by the
|
|
368
367
|
`compartment` property.
|
|
369
368
|
|
|
370
|
-
|
|
369
|
+
* If the `compartment` property is present, its value must be a
|
|
371
370
|
compartment.
|
|
372
|
-
|
|
371
|
+
* If absent, the `compartment` property defaults to the compartment being
|
|
373
372
|
constructed in the `modules` option, or being hooked in the `loadHook`
|
|
374
373
|
and `loadNowHook` options.
|
|
375
374
|
|
|
376
|
-
|
|
375
|
+
* Otherwise, if the value of the `namespace` property is a module namepace, the
|
|
377
376
|
descriptor shares a module that is already available.
|
|
378
377
|
|
|
379
|
-
|
|
378
|
+
* Otherwise, the value of `namespace` property must be an object. The module is
|
|
380
379
|
loaded and initialized from the object according to the [virtual module
|
|
381
380
|
namespace](#VirtualModuleNamespace) pattern.
|
|
382
381
|
|
|
@@ -390,11 +389,11 @@ and return a module that has a different "response specifier" than the original
|
|
|
390
389
|
The `importHook` may return an "alias" object with `source`, `compartment`,
|
|
391
390
|
and `specifier` properties.
|
|
392
391
|
|
|
393
|
-
|
|
392
|
+
* `source` must be a module source, either a virtual module source
|
|
394
393
|
or a compiled module source.
|
|
395
|
-
|
|
394
|
+
* `compartment` is optional, to be specified if the alias transits to a
|
|
396
395
|
the specified different compartment, and
|
|
397
|
-
|
|
396
|
+
* `specifier` is the full module specifier of the module in its compartment.
|
|
398
397
|
This defaults to the request specifier, which is only useful if the
|
|
399
398
|
compartment is different.
|
|
400
399
|
|
|
@@ -556,45 +555,45 @@ using a particular calling convention to initialize a module instance.
|
|
|
556
555
|
|
|
557
556
|
A compiled module source record has the following shape:
|
|
558
557
|
|
|
559
|
-
|
|
558
|
+
* `imports` is a record that maps partial module specifiers to a list of
|
|
560
559
|
names imported from the corresponding module.
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
* `exports` is an array of all the names that the module will export.
|
|
561
|
+
* `reexports` is an array of partial module specifier for which this
|
|
563
562
|
module exports all imported names.
|
|
564
563
|
This field is optional.
|
|
565
|
-
|
|
564
|
+
* `__syncModuleProgram__` is a string that evaluates to a function that accepts
|
|
566
565
|
an initialization record and initializes the module.
|
|
567
566
|
This property distinguishes this type of module record.
|
|
568
567
|
The name implies a future record type that supports top-level await.
|
|
569
|
-
|
|
568
|
+
* An initialization record has the properties `imports`, `liveVar`, `importMeta` and
|
|
570
569
|
`onceVar`.
|
|
571
|
-
|
|
570
|
+
* `imports` is a function that accepts a map from partial import
|
|
572
571
|
module specifiers to maps from names that the corresponding module
|
|
573
572
|
exports to notifier functions.
|
|
574
573
|
A notifier function accepts an update function and registers
|
|
575
574
|
to receive updates for the value exported by the other module.
|
|
576
|
-
|
|
575
|
+
* `importMeta` is a null-prototype object with keys transferred from `importMeta`
|
|
577
576
|
property in the envelope returned by importHook and/or mutated by
|
|
578
577
|
calling `importMetaHook(moduleSpecifier, importMeta)`
|
|
579
|
-
|
|
578
|
+
* `liveVar` is a record that maps names exported by this module
|
|
580
579
|
to a function that may be called to initialize or update
|
|
581
580
|
the corresponding value in another module.
|
|
582
|
-
|
|
581
|
+
* `onceVar` is a record that maps constants exported by this
|
|
583
582
|
module to a function that may be called to initialize the
|
|
584
583
|
corresponding value in another module.
|
|
585
|
-
|
|
584
|
+
* `__syncModuleFunctor__` is an optional function that if present is used
|
|
586
585
|
instead of the evaluation of the `__syncModuleProgram__` string. It will be
|
|
587
586
|
called with the initialization record described above. It is intended to be
|
|
588
587
|
used in environments where eval is not available. Sandboxing of the functor is
|
|
589
588
|
the responsibility of the author of the ModuleSource.
|
|
590
|
-
|
|
589
|
+
* `__liveExportsMap__` is a record that maps import names or names in the lexical
|
|
591
590
|
scope of the module to export names, for variables that may change after
|
|
592
591
|
initialization. Any reexported name is assumed to possibly change.
|
|
593
592
|
The exported name is wrapped in a duple array like `["exportedName", true]`.
|
|
594
593
|
The second value, a boolean, indicates that the variable has a temporal
|
|
595
594
|
dead-zone (a time between creation and initialization) when access to that
|
|
596
595
|
name should throw a `ReferenceError`.
|
|
597
|
-
|
|
596
|
+
* `__fixedExportsMap__` is a record that maps import names to export names
|
|
598
597
|
for constants exported by this module.
|
|
599
598
|
The fixed exports map is an aesthetic subtype of the live exports map,
|
|
600
599
|
so the value is wrapped in a simple array like `["exportedName"]`
|
|
@@ -673,6 +672,24 @@ system generates other diagnostic information hidden in side tables. The tamed
|
|
|
673
672
|
console uses these side tables to output more informative diagnostics.
|
|
674
673
|
[Logging Errors](./src/error/README.md) explains the design.
|
|
675
674
|
|
|
675
|
+
### Controlling Module-Loading Errors
|
|
676
|
+
|
|
677
|
+
The `Compartment` constructor now accepts a `boolean` option, `noAggregateLoadErrors`, to control how module-loading errors are reported.
|
|
678
|
+
|
|
679
|
+
By default, its value is `false`, which causes all relevant errors to be collected and rejected or thrown in a single exception from `compartment.import()` or `compartment.importNow()`, respectively.
|
|
680
|
+
|
|
681
|
+
If set to `true`, this will cause the *first* module-loading error encountered to be thrown (or rejected) immediately; no further module-loading will be attempted, and no further errors will be collected.
|
|
682
|
+
|
|
683
|
+
This is mostly useful for supporting optional dependencies in CommonJS modules, for example:
|
|
684
|
+
|
|
685
|
+
```js
|
|
686
|
+
try {
|
|
687
|
+
require('something-optional')
|
|
688
|
+
} catch (err) {
|
|
689
|
+
// continue
|
|
690
|
+
}
|
|
691
|
+
```
|
|
692
|
+
|
|
676
693
|
## Security claims and caveats
|
|
677
694
|
|
|
678
695
|
The `ses` shim concerns boundaries between programs in the same process and
|
|
@@ -696,20 +713,20 @@ Provided that the `ses` implementation and its
|
|
|
696
713
|
program can evaluate a guest program (`program`) in a compartment after
|
|
697
714
|
`lockdown` and that the guest program:
|
|
698
715
|
|
|
699
|
-
|
|
716
|
+
* will initially only have access to one mutable object, the compartment's
|
|
700
717
|
`globalThis`,
|
|
701
|
-
|
|
718
|
+
* specifically cannot modify any shared primordial objects, which are part of
|
|
702
719
|
the default execution environment,
|
|
703
|
-
|
|
720
|
+
* cannot initially perform any I/O (except I/O necessarily performed by the
|
|
704
721
|
trusted compute base like paging virtual memory),
|
|
705
|
-
|
|
722
|
+
* and specifically cannot measure the passage of time at any resolution.
|
|
706
723
|
|
|
707
724
|
However, such a program can:
|
|
708
725
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
726
|
+
* execute for an indefinite amount of time,
|
|
727
|
+
* allocate arbitrary amounts of memory,
|
|
728
|
+
* detect the platform endianness,
|
|
729
|
+
* in some JavaScript engines, observe the contents of the stack.
|
|
713
730
|
This may include sensitive information about the layout of files on the host
|
|
714
731
|
disk.
|
|
715
732
|
In cases where the stack is data-dependent, a guest can infer the data.
|
|
@@ -729,10 +746,10 @@ be frozen, we additionally claim that the host can evaluate any two guest
|
|
|
729
746
|
programs (`program1` and `program2`) in that compartment such that neither
|
|
730
747
|
guest program will:
|
|
731
748
|
|
|
732
|
-
|
|
733
|
-
|
|
749
|
+
* initially share *any* mutable objects.
|
|
750
|
+
* be able to observe the relative passage of time of the other program,
|
|
734
751
|
as they would had they been given a reference to a working `Date.now()`.
|
|
735
|
-
|
|
752
|
+
* be able to communicate, as they would if they had shared access to mutable
|
|
736
753
|
state like an unfrozen object, a hardened collection like a `Map`, or even
|
|
737
754
|
`Math.random()`.
|
|
738
755
|
|
|
@@ -826,18 +843,18 @@ capabilities at runtime.
|
|
|
826
843
|
|
|
827
844
|
The trusted compute base (TCB) for `ses` includes:
|
|
828
845
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
846
|
+
* the host hardware,
|
|
847
|
+
* the host operating system,
|
|
848
|
+
* any intermediate virtual operating systems or hypervisors,
|
|
849
|
+
* the process memory manager,
|
|
850
|
+
* an implementation of JavaScript conforming to ECMAScript 262 as of
|
|
834
851
|
2021, providing no unspecified embedding host behavior like the introduction of syntax
|
|
835
852
|
that when evaluated reveals a mutable object.
|
|
836
853
|
`ses` accounts for one such host behavior provided by Node.js, namely the `domain`
|
|
837
854
|
property on promises, by preventing the use of `ses` in concert with the
|
|
838
855
|
`domain` module.
|
|
839
|
-
|
|
840
|
-
|
|
856
|
+
* Also, any attached debugger, and
|
|
857
|
+
* any JavaScript that has executed in the same realm before the host program calls
|
|
841
858
|
`lockdown`, including JavaScript that executes after `ses` initializes.
|
|
842
859
|
|
|
843
860
|
## Audits
|
|
@@ -894,6 +911,7 @@ the code is often incompatible with *all* environments in which intrinsic
|
|
|
894
911
|
objects are frozen (such as in Node.js with the
|
|
895
912
|
[`--frozen-intrinsics`][Node frozen intrinsics] option) and can be fixed by
|
|
896
913
|
replacing `<lhs>.<propertyKey> = <rhs>;` or `<lhs>[<propertyKey>] = <rhs>;` with
|
|
914
|
+
|
|
897
915
|
```js
|
|
898
916
|
Object.defineProperties(<lhs>, {
|
|
899
917
|
[<propertyKey>]: {
|