ses 0.18.4 → 0.18.7

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 (45) hide show
  1. package/NEWS.md +20 -0
  2. package/README.md +105 -47
  3. package/dist/lockdown.cjs +7742 -7477
  4. package/dist/lockdown.mjs +7742 -7477
  5. package/dist/lockdown.umd.js +7742 -7477
  6. package/dist/lockdown.umd.min.js +1 -1
  7. package/dist/ses.cjs +7742 -7477
  8. package/dist/ses.mjs +7742 -7477
  9. package/dist/ses.umd.js +7742 -7477
  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 +2 -3
  14. package/src/compartment-evaluate.js +1 -1
  15. package/src/compartment-shim.js +9 -9
  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/stringify-utils.js +25 -1
  20. package/src/error/tame-console.js +1 -1
  21. package/src/error/tame-error-constructor.js +3 -3
  22. package/src/error/types.js +1 -0
  23. package/src/get-anonymous-intrinsics.js +23 -0
  24. package/src/global-object.js +2 -2
  25. package/src/intrinsics.js +10 -10
  26. package/src/lockdown-shim.js +13 -26
  27. package/src/make-hardener.js +1 -1
  28. package/src/module-instance.js +5 -9
  29. package/src/module-link.js +2 -2
  30. package/src/module-load.js +4 -6
  31. package/src/module-proxy.js +12 -12
  32. package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +22 -21
  33. package/src/{whitelist.js → permits.js} +137 -11
  34. package/src/strict-scope-terminator.js +10 -4
  35. package/src/tame-date-constructor.js +1 -1
  36. package/src/tame-domains.js +2 -2
  37. package/src/tame-function-constructors.js +2 -2
  38. package/src/tame-harden.js +1 -1
  39. package/src/tame-locale-methods.js +2 -2
  40. package/src/tame-math-object.js +1 -1
  41. package/src/tame-regexp-constructor.js +2 -2
  42. package/src/tame-symbol-constructor.js +65 -0
  43. package/src/transforms.js +4 -4
  44. package/types.d.ts +1 -0
  45. package/src/environment-options.js +0 -117
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  export function tameDomains(domainTaming = 'safe') {
11
11
  if (domainTaming !== 'safe' && domainTaming !== 'unsafe') {
12
- throw new TypeError(`unrecognized domainTaming ${domainTaming}`);
12
+ throw TypeError(`unrecognized domainTaming ${domainTaming}`);
13
13
  }
14
14
 
15
15
  if (domainTaming === 'unsafe') {
@@ -27,7 +27,7 @@ export function tameDomains(domainTaming = 'safe') {
27
27
  // The domain descriptor on Node.js initially has value: null, which
28
28
  // becomes a get, set pair after domains initialize.
29
29
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_DOMAINS.md
30
- throw new TypeError(
30
+ throw TypeError(
31
31
  `SES failed to lockdown, Node.js domains have been initialized (SES_NO_DOMAINS)`,
32
32
  );
33
33
  }
@@ -30,7 +30,7 @@ import {
30
30
  // list must be updated to match.
31
31
  //
32
32
  // In addition, the standard needs to define four new intrinsics for the safe
33
- // replacement functions. See [./whitelist intrinsics].
33
+ // replacement functions. See [./permits-intrinsics.js].
34
34
  //
35
35
  // Adapted from SES/Caja
36
36
  // Copyright (C) 2011 Google Inc.
@@ -84,7 +84,7 @@ export default function tameFunctionConstructors() {
84
84
  // prototype of functions.
85
85
  // eslint-disable-next-line func-names
86
86
  const InertConstructor = function () {
87
- throw new TypeError(
87
+ throw TypeError(
88
88
  'Function.prototype.constructor is not a valid constructor.',
89
89
  );
90
90
  };
@@ -3,7 +3,7 @@ import { TypeError, freeze } from './commons.js';
3
3
 
4
4
  export const tameHarden = (safeHarden, hardenTaming) => {
5
5
  if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
6
- throw new TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
6
+ throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
7
7
  }
8
8
 
9
9
  if (hardenTaming === 'safe') {
@@ -19,7 +19,7 @@ const tamedMethods = {
19
19
  // See https://tc39.es/ecma262/#sec-string.prototype.localecompare
20
20
  localeCompare(arg) {
21
21
  if (this === null || this === undefined) {
22
- throw new TypeError(
22
+ throw TypeError(
23
23
  'Cannot localeCompare with null or undefined "this" value',
24
24
  );
25
25
  }
@@ -45,7 +45,7 @@ const numberToString = tamedMethods.toString;
45
45
 
46
46
  export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
47
47
  if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
48
- throw new TypeError(`unrecognized localeTaming ${localeTaming}`);
48
+ throw TypeError(`unrecognized localeTaming ${localeTaming}`);
49
49
  }
50
50
  if (localeTaming === 'unsafe') {
51
51
  return;
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  export default function tameMathObject(mathTaming = 'safe') {
10
10
  if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
11
- throw new TypeError(`unrecognized mathTaming ${mathTaming}`);
11
+ throw TypeError(`unrecognized mathTaming ${mathTaming}`);
12
12
  }
13
13
  const originalMath = Math;
14
14
  const initialMath = originalMath; // to follow the naming pattern
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  export default function tameRegExpConstructor(regExpTaming = 'safe') {
11
11
  if (regExpTaming !== 'safe' && regExpTaming !== 'unsafe') {
12
- throw new TypeError(`unrecognized regExpTaming ${regExpTaming}`);
12
+ throw TypeError(`unrecognized regExpTaming ${regExpTaming}`);
13
13
  }
14
14
  const RegExpPrototype = FERAL_REG_EXP.prototype;
15
15
 
@@ -27,7 +27,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
27
27
 
28
28
  const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
29
29
  if (!speciesDesc) {
30
- throw new TypeError('no RegExp[Symbol.species] descriptor');
30
+ throw TypeError('no RegExp[Symbol.species] descriptor');
31
31
  }
32
32
 
33
33
  defineProperties(ResultRegExp, {
@@ -0,0 +1,65 @@
1
+ import {
2
+ Symbol,
3
+ entries,
4
+ fromEntries,
5
+ getOwnPropertyDescriptors,
6
+ defineProperties,
7
+ arrayMap,
8
+ } from './commons.js';
9
+
10
+ /**
11
+ * This taming provides a tamed alternative to the original `Symbol` constructor
12
+ * that starts off identical, except that all its properties are "temporarily"
13
+ * configurable. The original `Symbol` constructor remains unmodified on
14
+ * the start compartment's global. The tamed alternative is used as the shared
15
+ * `Symbol` constructor on constructed compartments.
16
+ *
17
+ * Starting these properties as configurable assumes two succeeding phases of
18
+ * processing: A whitelisting phase, that
19
+ * removes all properties not on the whitelist (which requires them to be
20
+ * configurable) and a global hardening step that freezes all primordials,
21
+ * returning these properties to their expected non-configurable status.
22
+ *
23
+ * The ses shim is constructed to eventually enable vetted shims to run between
24
+ * repair and global hardening. However, such vetted shims would normally
25
+ * run in the start compartment, which continues to use the original unmodified
26
+ * `Symbol`, so they should not normally be affected by the temporary
27
+ * configurability of these properties.
28
+ *
29
+ * Note that the spec refers to the global `Symbol` function as the
30
+ * ["Symbol Constructor"](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-symbol-constructor)
31
+ * even though it has a call behavior (can be called as a function) and does not
32
+ * not have a construct behavior (cannot be called with `new`). Accordingly,
33
+ * to tame it, we must replace it with a function without a construct
34
+ * behavior.
35
+ */
36
+ export const tameSymbolConstructor = () => {
37
+ const OriginalSymbol = Symbol;
38
+ const SymbolPrototype = OriginalSymbol.prototype;
39
+
40
+ const SharedSymbol = {
41
+ Symbol(description) {
42
+ return OriginalSymbol(description);
43
+ },
44
+ }.Symbol;
45
+
46
+ defineProperties(SymbolPrototype, {
47
+ constructor: {
48
+ value: SharedSymbol,
49
+ // leave other `constructor` attributes as is
50
+ },
51
+ });
52
+
53
+ const originalDescsEntries = entries(
54
+ getOwnPropertyDescriptors(OriginalSymbol),
55
+ );
56
+ const descs = fromEntries(
57
+ arrayMap(originalDescsEntries, ([name, desc]) => [
58
+ name,
59
+ { ...desc, configurable: true },
60
+ ]),
61
+ );
62
+ defineProperties(SharedSymbol, descs);
63
+
64
+ return { '%SharedSymbol%': SharedSymbol };
65
+ };
package/src/transforms.js CHANGED
@@ -71,7 +71,7 @@ export const rejectHtmlComments = src => {
71
71
  }
72
72
  const name = getSourceURL(src);
73
73
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md
74
- throw new SyntaxError(
74
+ throw SyntaxError(
75
75
  `Possible HTML comment rejected at ${name}:${lineNumber}. (SES_HTML_COMMENT_REJECTED)`,
76
76
  );
77
77
  };
@@ -106,7 +106,7 @@ export const evadeHtmlCommentTest = src => {
106
106
  // /////////////////////////////////////////////////////////////////////////////
107
107
 
108
108
  const importPattern = new FERAL_REG_EXP(
109
- '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
109
+ '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
110
110
  'g',
111
111
  );
112
112
 
@@ -147,7 +147,7 @@ export const rejectImportExpressions = src => {
147
147
  }
148
148
  const name = getSourceURL(src);
149
149
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_IMPORT_REJECTED.md
150
- throw new SyntaxError(
150
+ throw SyntaxError(
151
151
  `Possible import expression rejected at ${name}:${lineNumber}. (SES_IMPORT_REJECTED)`,
152
152
  );
153
153
  };
@@ -219,7 +219,7 @@ export const rejectSomeDirectEvalExpressions = src => {
219
219
  }
220
220
  const name = getSourceURL(src);
221
221
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_EVAL_REJECTED.md
222
- throw new SyntaxError(
222
+ throw SyntaxError(
223
223
  `Possible direct eval expression rejected at ${name}:${lineNumber}. (SES_EVAL_REJECTED)`,
224
224
  );
225
225
  };
package/types.d.ts CHANGED
@@ -199,6 +199,7 @@ export interface Assert {
199
199
  ): DetailsToken;
200
200
  Fail(template: TemplateStringsArray | string[], ...args: any): never;
201
201
  quote(payload: any, spaces?: string | number): ToStringable;
202
+ bare(payload: any, spaces?: string | number): ToStringable;
202
203
  makeAssert: MakeAssert;
203
204
  }
204
205
 
@@ -1,117 +0,0 @@
1
- // @ts-check
2
-
3
- // environment-options needs to be imported quite early, and so should
4
- // avoid importing from anything but commons.js and assert.js
5
- import { arrayPush, freeze } from './commons.js';
6
- import { assert } from './error/assert.js';
7
-
8
- const { Fail, quote: q } = assert;
9
-
10
- /**
11
- * JavaScript module semantics resists attempts to parameterize a module's
12
- * initialization behavior. A module initializes in order according to
13
- * the path by which it is first imported, and then the initialized module
14
- * is reused by all the other times it is imported. Compartments give us
15
- * the opportunity to bind the same import name to different imported
16
- * modules, depending on the package/compartment doing the import. Compartments
17
- * also address the difficulty of parameterizing a module's initialization
18
- * logic, but not in a pleasant manner.
19
- *
20
- * A pleasant parameterization would be for a static module to be function-like
21
- * with explicit parameters, and for the parameterization to be like
22
- * calling the static module with parameters in order to derive from it a
23
- * module instance. Compartments instead lets us parameterize the meaning
24
- * of a module instance derived from a static module according to the
25
- * three namespaces provided by the JavaScript semantics, affecting the
26
- * meaning of a module instance.
27
- * * The global variable namespaces.
28
- * * The global scope, aliased to properties of the global object.
29
- * This is necessarily compartment-wide, and therefore in our
30
- * recommened usage pattern, package-wide.
31
- * * The global lexical scope. The SES-shim compartments support
32
- * these both compartment-wide as well as per-module. But it is
33
- * not yet clear what we will propose in the Compartment proposal.
34
- * * The import namespace.
35
- * * The host hooks.
36
- *
37
- * This `environment-options.js` module looks for a setting of an
38
- * `optionName` parameter rooted in the global scope. If follows the Node
39
- * precedent for finding Unix environment variable settings, looking for a
40
- * global `process` object holding an `env` object,
41
- * optionally holding a property named for the `optionName` whose value is the
42
- * configuration setting of that option. For example, for the optionName
43
- * `FOO_BAR` it would look in
44
- * `globalThis.process.env.FOO_BAR`.
45
- *
46
- * If setting is either absent or `undefined`, that indicates that
47
- * this configuration option should have its default behavior, whatever that is.
48
- * Otherwise, reflecting Unix environment variables, the setting must be a
49
- * string. This also helps ensure that this channel is used only to pass data,
50
- * not authority beyond the ability to read this global state.
51
- */
52
-
53
- /**
54
- * makeEnvironmentCaptor provides a mechanism for getting environment
55
- * variables, if they are needed, and a way to catalog the names of all
56
- * the environment variables that were captured.
57
- *
58
- * @param {object} aGlobal
59
- */
60
- export const makeEnvironmentCaptor = aGlobal => {
61
- const capturedEnvironmentOptionNames = [];
62
-
63
- /**
64
- * Gets an environment option by name and returns the option value or the
65
- * given default.
66
- *
67
- * @param {string} optionName
68
- * @param {string} defaultSetting
69
- * @returns {string}
70
- */
71
- const getEnvironmentOption = (optionName, defaultSetting) => {
72
- // eslint-disable-next-line @endo/no-polymorphic-call
73
- typeof optionName === 'string' ||
74
- Fail`Environment option name ${q(optionName)} must be a string.`;
75
- // eslint-disable-next-line @endo/no-polymorphic-call
76
- typeof defaultSetting === 'string' ||
77
- Fail`Environment option default setting ${q(
78
- defaultSetting,
79
- )} must be a string.`;
80
-
81
- /** @type {string} */
82
- let setting = defaultSetting;
83
- const globalProcess = aGlobal.process;
84
- if (globalProcess && typeof globalProcess === 'object') {
85
- const globalEnv = globalProcess.env;
86
- if (globalEnv && typeof globalEnv === 'object') {
87
- if (optionName in globalEnv) {
88
- arrayPush(capturedEnvironmentOptionNames, optionName);
89
- const optionValue = globalEnv[optionName];
90
- // eslint-disable-next-line @endo/no-polymorphic-call
91
- typeof optionValue === 'string' ||
92
- Fail`Environment option named ${q(
93
- optionName,
94
- )}, if present, must have a corresponding string value, got ${q(
95
- optionValue,
96
- )}`;
97
- setting = optionValue;
98
- }
99
- }
100
- }
101
- setting === undefined ||
102
- typeof setting === 'string' ||
103
- Fail`Environment option value ${q(
104
- setting,
105
- )}, if present, must be a string.`;
106
- return setting;
107
- };
108
- freeze(getEnvironmentOption);
109
-
110
- const getCapturedEnvironmentOptionNames = () => {
111
- return freeze([...capturedEnvironmentOptionNames]);
112
- };
113
- freeze(getCapturedEnvironmentOptionNames);
114
-
115
- return freeze({ getEnvironmentOption, getCapturedEnvironmentOptionNames });
116
- };
117
- freeze(makeEnvironmentCaptor);