ses 0.18.3 → 0.18.5

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.
Files changed (49) hide show
  1. package/NEWS.md +16 -0
  2. package/README.md +105 -47
  3. package/dist/lockdown.cjs +6779 -6508
  4. package/dist/lockdown.mjs +6779 -6508
  5. package/dist/lockdown.umd.js +6779 -6508
  6. package/dist/lockdown.umd.min.js +1 -1
  7. package/dist/ses.cjs +6779 -6508
  8. package/dist/ses.mjs +6779 -6508
  9. package/dist/ses.umd.js +6779 -6508
  10. package/dist/ses.umd.min.js +1 -1
  11. package/index.js +1 -1
  12. package/package.json +17 -13
  13. package/src/commons.js +14 -11
  14. package/src/compartment-evaluate.js +1 -1
  15. package/src/compartment-shim.js +10 -14
  16. package/src/enable-property-overrides.js +4 -4
  17. package/src/error/assert.js +36 -9
  18. package/src/error/note-log-args.js +2 -4
  19. package/src/error/tame-console.js +1 -1
  20. package/src/error/tame-error-constructor.js +3 -3
  21. package/src/error/tame-v8-error-constructor.js +1 -1
  22. package/src/error/types.js +1 -0
  23. package/src/eval-scope.js +4 -2
  24. package/src/get-anonymous-intrinsics.js +25 -4
  25. package/src/global-object.js +2 -2
  26. package/src/intrinsics.js +14 -11
  27. package/src/lockdown-shim.js +13 -26
  28. package/src/make-hardener.js +8 -1
  29. package/src/make-safe-evaluator.js +6 -5
  30. package/src/module-instance.js +8 -11
  31. package/src/module-link.js +2 -2
  32. package/src/module-load.js +5 -7
  33. package/src/module-proxy.js +12 -12
  34. package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +24 -20
  35. package/src/{whitelist.js → permits.js} +135 -8
  36. package/src/scope-constants.js +1 -0
  37. package/src/strict-scope-terminator.js +10 -4
  38. package/src/tame-date-constructor.js +1 -1
  39. package/src/tame-domains.js +2 -2
  40. package/src/tame-function-constructors.js +2 -2
  41. package/src/tame-function-tostring.js +1 -1
  42. package/src/tame-harden.js +7 -1
  43. package/src/tame-locale-methods.js +2 -2
  44. package/src/tame-math-object.js +1 -1
  45. package/src/tame-regexp-constructor.js +11 -2
  46. package/src/tame-symbol-constructor.js +65 -0
  47. package/src/transforms.js +3 -3
  48. package/types.d.ts +1 -0
  49. package/src/environment-options.js +0 -117
package/NEWS.md CHANGED
@@ -1,5 +1,21 @@
1
1
  User-visible changes in SES:
2
2
 
3
+ # v0.18.5 (2023-07-14)
4
+
5
+ - Adds `assert.bare` for embedding unquoted strings in details.
6
+ - Permits new `dispose` symbols, other recent additions to JavaScript, and for
7
+ the anticipated iterator helpers.
8
+ - Tames `Symbol` so symbols can be preserved in the start compartment and
9
+ denied to shared compartments.
10
+ - Improves debugging in Safari.
11
+ - Adds missing native function markers.
12
+ All native functions should have a `toString` that says `[native code]`, even
13
+ if emulated.
14
+
15
+ # v0.18.4 (2023-04-20)
16
+
17
+ - Pass through the start compartment's `globalThis.harden` if defined.
18
+
3
19
  # v0.18.3 (2023-04-14)
4
20
 
5
21
  - New `__hardenTaming__: 'unsafe'` lockdown option to fake harden unsafely,
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  SES is *hardened JavaScript*. SES stands for *fearless cooperation*.
4
4
  This package is a SES [shim][define shim] for JavaScript features
5
- [proposed][SES proposal] to ECMA TC-39.
5
+ [proposed][SES proposal] to ECMA TC39.
6
6
  Hardened JavaScript is highly compatible with ordinary JavaScript.
7
7
  Most existing JavaScript libraries can run on hardened JavaScript.
8
8
 
@@ -70,7 +70,8 @@ tag.
70
70
  SES introduces the `lockdown()` function.
71
71
  Calling `lockdown()` alters the surrounding execution environment, or
72
72
  **realm**, such that no two programs running in the same realm can observe or
73
- interfere with each other until they have been introduced.
73
+ affect each other until they have been introduced, and even then can only
74
+ interact through their own exposed interfaces.
74
75
 
75
76
  To do this, `lockdown()` tamper-proofs all of the JavaScript intrinsics, to
76
77
  prevent **prototype pollution**.
@@ -80,10 +81,10 @@ Also, no program can use these mutable objects to pass notes to parties that
80
81
  haven't been expressly introduced (preventing some **covert communication
81
82
  channels**).
82
83
 
83
- Lockdown freezes all objects accessible to any program in the realm.
84
- The set of accessible objects includes but is not limited to: `globalThis`,
85
- `[].__proto__`, `{}.__proto__`, `(() => {}).__proto__` `(async () =>
86
- {}).__proto__`, and the properties of any accessible object.
84
+ Lockdown freezes all objects that are effectively undeniable to programs in the
85
+ realm. The set of such objects includes but is not limited to: `globalThis`,
86
+ prototype objects of Array, Function, GeneratorFunction, and Object, and objects
87
+ accessible from those objects (such as `Object.prototype.toString`).
87
88
 
88
89
  The `lockdown()` function also **tames** some objects including regular
89
90
  expressions, locale methods, and errors.
@@ -91,7 +92,7 @@ A tamed `RegExp` does not have the deprecated `compile` method.
91
92
  A tamed error does not have a V8 `stack`, but the `console` can still see the
92
93
  stack.
93
94
  Lockdown replaces locale methods like `String.prototype.localeCompare` with
94
- lexical versions that do not reveal the user locale.
95
+ generic versions that do not reveal the host locale.
95
96
 
96
97
  ```js
97
98
  import 'ses';
@@ -140,8 +141,8 @@ console.log(Object.isFrozen(capability.inc));
140
141
 
141
142
  Note that although the **surface** of the capability is frozen, the capability
142
143
  still closes over the mutable counter.
143
- Hardening an object graph makes the surface immutable, but does not make
144
- methods pure.
144
+ Hardening an object graph makes the surface immutable, but does not guarantee
145
+ that methods are free of side effects.
145
146
 
146
147
 
147
148
  ### Compartment
@@ -522,7 +523,7 @@ are standard or not.
522
523
 
523
524
  `lockdown()` adds new global `assert` and tames the global `console`. The error
524
525
  taming hides error stacks, accumulating them in side tables. The `assert`
525
- system generated other diagnostic information hidden in side tables. The tamed
526
+ system generates other diagnostic information hidden in side tables. The tamed
526
527
  console uses these side tables to output more informative diagnostics.
527
528
  [Logging Errors](./src/error/README.md) explains the design.
528
529
 
@@ -542,9 +543,12 @@ For the purposes of these claims and caveats, a "host program" is a program
542
543
  that arranges `ses`, calls `lockdown`, and orchestrates one or more "guest
543
544
  programs", providing limited access to its resources.
544
545
 
545
- Provided that the `ses` implementation and its trusted compute base are
546
- correct, we claim that a host program (Figure 1) can evaluate a guest program
547
- (`program`) in a compartment after `lockdown` and that the program:
546
+ ### Single-guest Compartment Isolation
547
+
548
+ Provided that the `ses` implementation and its
549
+ [trusted compute base](#trusted-compute-base) are correct, we claim that a host
550
+ program can evaluate a guest program (`program`) in a compartment after
551
+ `lockdown` and that the guest program:
548
552
 
549
553
  - will initially only have access to one mutable object, the compartment's
550
554
  `globalThis`,
@@ -567,15 +571,17 @@ However, such a program can:
567
571
  JavaScriptCore.
568
572
 
569
573
  ```js
570
- // Claims, Figure 1
571
574
  lockdown();
572
575
  const compartment = new Compartment();
573
576
  compartment.evaluate(program);
574
577
  ```
575
578
 
576
- If the host program (Figure 2) arranges for the compartment's `globalThis` to
579
+ ### Multi-guest Compartment Isolation
580
+
581
+ If the host program arranges for the compartment's `globalThis` to
577
582
  be frozen, we additionally claim that the host can evaluate any two guest
578
- programs (`program1` and `program2`) such that neither program will:
583
+ programs (`program1` and `program2`) in that compartment such that neither
584
+ guest program will:
579
585
 
580
586
  - initially share *any* mutable objects.
581
587
  - be able to observe the relative passage of time of the other program,
@@ -585,7 +591,6 @@ programs (`program1` and `program2`) such that neither program will:
585
591
  `Math.random()`.
586
592
 
587
593
  ```js
588
- // Claims, Figure 2
589
594
  lockdown();
590
595
  const compartment = new Compartment();
591
596
  harden(compartment.globaThis);
@@ -593,31 +598,30 @@ compartment.evaluate(program1);
593
598
  compartment.evaluate(program2);
594
599
  ```
595
600
 
596
- However such programs (`program`, `program1`, or `program2`) are only
597
- as useful as a calculator.
598
- A host program is therefore responsible for maintaining any of the desired
599
- invariants above when "endowing" a compartment with any of its own objects.
601
+ ### Endowment Protection
600
602
 
601
- For example, a host program (Figure 3) may run two programs in separate
602
- compartments, giving one program the ability to resolve a promise and the other
603
- program the ability to observe the settlement (fulfillment or rejection) of
603
+ The above `program`, `program1`, and `program2` guest programs are only useful
604
+ as glorified calculators.
605
+ When going beyond that by "endowing" a compartment with extra objects, a host
606
+ program is responsible for maintaining any of the invariants above that it
607
+ considers necessary.
608
+
609
+ For example, a host program may run two guest programs in separate
610
+ compartments, giving one the ability to resolve a promise and the other
611
+ the ability to observe the settlement (fulfillment or rejection) of
604
612
  that promise.
605
- The host program is responsible for hardening these objects.
613
+ The host program is responsible for hardening the objects implementing such
614
+ abilities.
606
615
 
607
616
  ```js
608
- // Claims, Figure 2
609
617
  lockdown();
610
618
 
611
619
  const promise = new Promise(resolve => {
612
- const compartmentA = new Compartment(harden({
613
- resolve,
614
- }));
615
- compartment.evaluate(programA);
620
+ const compartmentA = new Compartment(harden({ resolve }));
621
+ compartmentA.evaluate(programA);
616
622
  });
617
623
 
618
- const compartmentB = new Compartment(harden({
619
- promise,
620
- }));
624
+ const compartmentB = new Compartment(harden({ promise }));
621
625
  compartmentB.evaluate(programB);
622
626
  ```
623
627
 
@@ -625,13 +629,14 @@ With `ses`, guest programs are initially powerless.
625
629
  A host can explicitly share limited powers with guest programs
626
630
  and provide intentional communication channels between them.
627
631
 
632
+ ### Caveats
633
+
628
634
  Host programs must maintain the `ses` boundary with care in what they present
629
635
  as endowments.
630
636
  A host program should take care not to share mutable state with guests,
631
- or distribute mutable state to multiple guests, such as an unfrozen object (use
632
- `harden`), direct read and write access to a collection, like a `Map` or `Set`,
633
- even if hardened.
634
- Furthermore, typed arrays are collections and cannot be hardened.
637
+ or distribute mutable state to multiple guests, such as an object that has not
638
+ been frozen with `harden` or a collection like a `Map` or `Set` or typed array
639
+ (collections retain some mutability even if hardened).
635
640
 
636
641
  For the purposes of sharing state, pseudo-random number generators (PRNG) like
637
642
  `Math.random()` are equivalent to read and write access to shared state, and
@@ -647,8 +652,7 @@ buffer to construct a high resolution timer.
647
652
 
648
653
  The `ses` shim does not in itself isolate the stack of guest programs, even
649
654
  when evaluated in separate compartments.
650
- This is relevant when program created objects are shared between guest
651
- programs.
655
+ This is relevant when objects are shared between guest programs.
652
656
 
653
657
  When a program interacts with an object introduced by another program (as
654
658
  through the per-compartment `globalThis`, function arguments or returned
@@ -656,8 +660,8 @@ values), there are potential risks due to the synchronous nature of object
656
660
  access.
657
661
  Even interactions that are not explicit function calls may cause code from
658
662
  another program, like property accessors or proxy traps, to execute on the same
659
- stack, which may be able to call back into the program (reentrancy), throw, or
660
- detect the current stack height.
663
+ stack, which may be able to detect the stack height, throw an exception, or call
664
+ back into the program in pursuit of a reentrancy attack.
661
665
 
662
666
  A host object can defend itself from reentrancy attacks by ensuring that it
663
667
  interacts with guest objects on a clean stack through the use of promises.
@@ -666,6 +670,8 @@ Within these constraints, a host program can provide objects that grant limited
666
670
  I/O capabilities to guest programs, and even revoke or suspend those
667
671
  capabilities at runtime.
668
672
 
673
+ ### Trusted Compute Base
674
+
669
675
  The trusted compute base (TCB) for `ses` includes:
670
676
 
671
677
  - the host hardware,
@@ -697,10 +703,9 @@ results in security reviews.
697
703
  In July 2021, `ses` was the target of an intensive collaborative bug hunt lead by
698
704
  the MetaMask team.
699
705
  No critical flaws in the code surfaced during the review.
700
- As a result of the search for flaws, deficiencies, and weaknesses in the code
701
- (which is currently a Stage 1 proposal with the ECMA TC39 committee), a series
702
- of small code changes and documentation improvements were made. There is a
703
- report available on the
706
+ As a result of the search for flaws, deficiencies, and weaknesses in the code,
707
+ a series of small code changes and documentation improvements were made. There
708
+ is a report available on the
704
709
  [Agoric blog](https://agoric.com/blog/technology/purple-teaming-how-metamask-and-agoric-hunted-bugs-to-harden-javascript)
705
710
  that includes links to recordings of code walk-throughs and technical
706
711
  discussion, and issues are tagged
@@ -726,11 +731,64 @@ instructions in [SECURITY.md][] to report security-sensitive bugs privately.
726
731
 
727
732
  For non-security bugs, please use the [regular Issues page][SES Issues].
728
733
 
734
+ ## Ecosystem Compatibility
735
+
736
+ Most ordinary JavaScript can run without issues in a realm locked down by SES.
737
+ Exceptions are tracked at [issue #576][incompatibility tracking], and almost
738
+ always take the form of assignments that fail because the
739
+ "[override mistake][override mistake]" prevents overriding properties inherited
740
+ from a frozen intrinsic object in the prototype chain. When that is the case,
741
+ the code is often incompatible with *all* environments in which intrinsic
742
+ objects are frozen (such as in Node.js with the
743
+ [`--frozen-intrinsics`][Node frozen intrinsics] option) and can be fixed by
744
+ replacing `<lhs>.<propertyKey> = <rhs>;` or `<lhs>[<propertyKey>] = <rhs>;` with
745
+ ```js
746
+ Object.defineProperties(<lhs>, {
747
+ [<propertyKey>]: {
748
+ value: <rhs>,
749
+ writable: true,
750
+ enumerable: true,
751
+ configurable: true,
752
+ },
753
+ });
754
+ ```
755
+
756
+ Upon encountering an incompatibility, we recommend that you add a comment to
757
+ [issue #576][incompatibility tracking] and file an issue with the external
758
+ project referencing this section.
759
+ Projects often have their own unique issue reporting templates, but generally
760
+ provide some place to include text like
761
+
762
+ > ```
763
+ > This project has some assignments that break in an environment with frozen
764
+ > intrinsic objects, such as
765
+ > [Hardened JS (a.k.a. SES)](https://github.com/endojs/endo/blob/master/packages/ses#ecosystem-compatibility)
766
+ > or Node.js with the
767
+ > [`--frozen-intrinsics`](https://nodejs.org/docs/latest/api/cli.html#--frozen-intrinsics)
768
+ > option.
769
+ > Specifically, [link to source in the project] does not work correctly in such
770
+ > an environment.
771
+ >
772
+ > Please consider increasing support by replacing assignments to object
773
+ > properties inherited from intrinsics with use of `Object.defineProperties`
774
+ > (thereby working around the JavaScript "override mistake"), and if applicable
775
+ > also by avoiding mutation of intrinsic objects.
776
+ > If you don't have the capacity but would accept a PR, please comment to that
777
+ > effect so that a volunteer knows their efforts would be welcomed.
778
+ > ```
779
+
780
+ We find that library authors are generally amenable to making these small changes to increase
781
+ compatibility with any environment that protects itself from prototype pollution attacks by freezing
782
+ intrinsics, including `ses`.
783
+
729
784
  [define shim]: https://en.wikipedia.org/wiki/Shim_(computing)
730
- [SES proposal]: https://github.com/tc39/proposal-ses
785
+ [Endo Matrix]: https://matrix.to/#/#endojs:matrix.org
786
+ [incompatibility tracking]: https://github.com/endojs/endo/issues/576
787
+ [Node frozen intrinsics]: https://nodejs.org/docs/latest/api/cli.html#--frozen-intrinsics
788
+ [override mistake]: https://web.archive.org/web/20141230041441/http://wiki.ecmascript.org/doku.php?id=strawman:fixing_override_mistake
731
789
  [SECURITY.md]: https://github.com/endojs/endo/blob/master/packages/ses/SECURITY.md
732
790
  [SES Issues]: https://github.com/endojs/endo/issues
791
+ [SES proposal]: https://github.com/tc39/proposal-ses
733
792
  [SES Strategy Group]: https://groups.google.com/g/ses-strategy
734
793
  [SES Strategy Recordings]: https://www.youtube.com/playlist?list=PLzDw4TTug5O1jzKodRDp3qec8zl88oxGd
735
- [Endo Matrix]: https://matrix.to/#/#endojs:matrix.org
736
794