ses 0.14.2 → 0.15.1

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 (50) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/NEWS.md +60 -1
  3. package/README.md +0 -1
  4. package/dist/lockdown.cjs +1769 -992
  5. package/dist/lockdown.mjs +1769 -992
  6. package/dist/lockdown.umd.js +1769 -992
  7. package/dist/lockdown.umd.min.js +1 -1
  8. package/dist/ses.cjs +1769 -992
  9. package/dist/ses.mjs +1769 -992
  10. package/dist/ses.umd.js +1769 -992
  11. package/dist/ses.umd.min.js +1 -1
  12. package/index.d.ts +2 -1
  13. package/index.js +6 -13
  14. package/package.json +24 -11
  15. package/src/commons.js +44 -9
  16. package/src/compartment-evaluate.js +102 -0
  17. package/src/compartment-shim.js +78 -106
  18. package/src/enable-property-overrides.js +5 -4
  19. package/src/enablements.js +7 -2
  20. package/src/environment-options.js +125 -0
  21. package/src/error/assert.js +51 -39
  22. package/src/error/console.js +32 -14
  23. package/src/error/fatal-assert.js +2 -0
  24. package/src/error/stringify-utils.js +26 -3
  25. package/src/error/tame-console.js +12 -4
  26. package/src/error/tame-error-constructor.js +18 -17
  27. package/src/error/tame-v8-error-constructor.js +30 -14
  28. package/src/get-anonymous-intrinsics.js +11 -8
  29. package/src/get-source-url.js +4 -4
  30. package/src/global-object.js +33 -26
  31. package/src/intrinsics.js +76 -67
  32. package/src/lockdown-shim.js +111 -119
  33. package/src/make-eval-function.js +3 -5
  34. package/src/make-function-constructor.js +3 -4
  35. package/src/make-safe-evaluator.js +117 -0
  36. package/src/module-instance.js +31 -17
  37. package/src/module-link.js +11 -4
  38. package/src/module-load.js +169 -44
  39. package/src/module-proxy.js +12 -4
  40. package/src/scope-constants.js +6 -3
  41. package/src/scope-handler.js +41 -17
  42. package/src/tame-date-constructor.js +8 -2
  43. package/src/tame-domains.js +46 -0
  44. package/src/tame-function-constructors.js +1 -0
  45. package/src/tame-locale-methods.js +6 -6
  46. package/src/tame-math-object.js +2 -2
  47. package/src/tame-regexp-constructor.js +7 -7
  48. package/src/transforms.js +13 -6
  49. package/src/whitelist-intrinsics.js +9 -3
  50. package/src/evaluate.js +0 -98
@@ -1,6 +1,6 @@
1
1
  import {
2
- Error,
3
- RegExp as OriginalRegExp,
2
+ FERAL_REG_EXP,
3
+ TypeError,
4
4
  construct,
5
5
  defineProperties,
6
6
  getOwnPropertyDescriptor,
@@ -9,17 +9,17 @@ import {
9
9
 
10
10
  export default function tameRegExpConstructor(regExpTaming = 'safe') {
11
11
  if (regExpTaming !== 'safe' && regExpTaming !== 'unsafe') {
12
- throw new Error(`unrecognized regExpTaming ${regExpTaming}`);
12
+ throw new TypeError(`unrecognized regExpTaming ${regExpTaming}`);
13
13
  }
14
- const RegExpPrototype = OriginalRegExp.prototype;
14
+ const RegExpPrototype = FERAL_REG_EXP.prototype;
15
15
 
16
16
  const makeRegExpConstructor = (_ = {}) => {
17
17
  // RegExp has non-writable static properties we need to omit.
18
18
  const ResultRegExp = function RegExp(...rest) {
19
19
  if (new.target === undefined) {
20
- return OriginalRegExp(...rest);
20
+ return FERAL_REG_EXP(...rest);
21
21
  }
22
- return construct(OriginalRegExp, rest, new.target);
22
+ return construct(FERAL_REG_EXP, rest, new.target);
23
23
  };
24
24
 
25
25
  defineProperties(ResultRegExp, {
@@ -30,7 +30,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
30
30
  enumerable: false,
31
31
  configurable: false,
32
32
  },
33
- [speciesSymbol]: getOwnPropertyDescriptor(OriginalRegExp, speciesSymbol),
33
+ [speciesSymbol]: getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol),
34
34
  });
35
35
  return ResultRegExp;
36
36
  };
package/src/transforms.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // @ts-check
2
2
 
3
3
  import {
4
- RegExp,
4
+ FERAL_REG_EXP,
5
5
  SyntaxError,
6
+ stringReplace,
6
7
  stringSearch,
7
8
  stringSlice,
8
9
  stringSplit,
@@ -33,7 +34,7 @@ function getLineNumber(src, pattern) {
33
34
 
34
35
  // /////////////////////////////////////////////////////////////////////////////
35
36
 
36
- const htmlCommentPattern = new RegExp(`(?:${'<'}!--|--${'>'})`, 'g');
37
+ const htmlCommentPattern = new FERAL_REG_EXP(`(?:${'<'}!--|--${'>'})`, 'g');
37
38
 
38
39
  /**
39
40
  * Conservatively reject the source text if it may contain text that some
@@ -97,12 +98,15 @@ export const rejectHtmlComments = src => {
97
98
  */
98
99
  export const evadeHtmlCommentTest = src => {
99
100
  const replaceFn = match => (match[0] === '<' ? '< ! --' : '-- >');
100
- return src.replace(htmlCommentPattern, replaceFn);
101
+ return stringReplace(src, htmlCommentPattern, replaceFn);
101
102
  };
102
103
 
103
104
  // /////////////////////////////////////////////////////////////////////////////
104
105
 
105
- const importPattern = new RegExp('(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))', 'g');
106
+ const importPattern = new FERAL_REG_EXP(
107
+ '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
108
+ 'g',
109
+ );
106
110
 
107
111
  /**
108
112
  * Conservatively reject the source text if it may contain a dynamic
@@ -163,12 +167,15 @@ export const rejectImportExpressions = src => {
163
167
  */
164
168
  export const evadeImportExpressionTest = src => {
165
169
  const replaceFn = (_, p1, p2) => `${p1}__import__${p2}`;
166
- return src.replace(importPattern, replaceFn);
170
+ return stringReplace(src, importPattern, replaceFn);
167
171
  };
168
172
 
169
173
  // /////////////////////////////////////////////////////////////////////////////
170
174
 
171
- const someDirectEvalPattern = new RegExp('(^|[^.])\\beval(\\s*\\()', 'g');
175
+ const someDirectEvalPattern = new FERAL_REG_EXP(
176
+ '(^|[^.])\\beval(\\s*\\()',
177
+ 'g',
178
+ );
172
179
 
173
180
  /**
174
181
  * Heuristically reject some text that seems to contain a direct eval
@@ -45,7 +45,7 @@
45
45
 
46
46
  import { whitelist, FunctionInstance, isAccessorPermit } from './whitelist.js';
47
47
  import {
48
- Error,
48
+ String,
49
49
  TypeError,
50
50
  arrayIncludes,
51
51
  getOwnPropertyDescriptor,
@@ -53,6 +53,7 @@ import {
53
53
  isObject,
54
54
  objectHasOwnProperty,
55
55
  ownKeys,
56
+ stringSlice,
56
57
  } from './commons.js';
57
58
 
58
59
  /**
@@ -67,7 +68,7 @@ function asStringPropertyName(path, prop) {
67
68
  }
68
69
 
69
70
  if (typeof prop === 'symbol') {
70
- return `@@${prop.toString().slice(14, -1)}`;
71
+ return `@@${stringSlice(String(prop), 14, -1)}`;
71
72
  }
72
73
 
73
74
  throw new TypeError(`Unexpected property name type ${path} ${prop}`);
@@ -114,7 +115,9 @@ export default function whitelistIntrinsics(
114
115
  }
115
116
 
116
117
  // We can't clean [[prototype]], therefore abort.
117
- throw new Error(`Unexpected intrinsic ${path}.__proto__ at ${protoName}`);
118
+ throw new TypeError(
119
+ `Unexpected intrinsic ${path}.__proto__ at ${protoName}`,
120
+ );
118
121
  }
119
122
 
120
123
  /*
@@ -244,14 +247,17 @@ export default function whitelistIntrinsics(
244
247
  // This call to `console.log` is intentional. It is not a vestige
245
248
  // of a debugging attempt. See the comment at top of file for an
246
249
  // explanation.
250
+ // eslint-disable-next-line @endo/no-polymorphic-call
247
251
  console.log(`Removing ${subPath}`);
248
252
  }
249
253
  try {
250
254
  delete obj[prop];
251
255
  } catch (err) {
252
256
  if (prop in obj) {
257
+ // eslint-disable-next-line @endo/no-polymorphic-call
253
258
  console.error(`failed to delete ${subPath}`, err);
254
259
  } else {
260
+ // eslint-disable-next-line @endo/no-polymorphic-call
255
261
  console.error(`deleting ${subPath} threw`, err);
256
262
  }
257
263
  throw err;
package/src/evaluate.js DELETED
@@ -1,98 +0,0 @@
1
- // Portions adapted from V8 - Copyright 2016 the V8 project authors.
2
- // https://github.com/v8/v8/blob/master/src/builtins/builtins-function.cc
3
-
4
- import {
5
- WeakSet,
6
- apply,
7
- immutableObject,
8
- proxyRevocable,
9
- weaksetAdd,
10
- } from './commons.js';
11
- import { getScopeConstants } from './scope-constants.js';
12
- import { createScopeHandler } from './scope-handler.js';
13
- import { applyTransforms, mandatoryTransforms } from './transforms.js';
14
- import { makeEvaluateFactory } from './make-evaluate-factory.js';
15
- import { assert } from './error/assert.js';
16
-
17
- const { details: d } = assert;
18
-
19
- /**
20
- * performEval()
21
- * The low-level operation used by all evaluators:
22
- * eval(), Function(), Evalutator.prototype.evaluate().
23
- *
24
- * @param {string} source
25
- * @param {Object} globalObject
26
- * @param {Objeect} localObject
27
- * @param {Object} [options]
28
- * @param {Array<Transform>} [options.localTransforms]
29
- * @param {Array<Transform>} [options.globalTransforms]
30
- * @param {bool} [options.sloppyGlobalsMode]
31
- * @param {WeakSet} [options.knownScopeProxies]
32
- */
33
- export const performEval = (
34
- source,
35
- globalObject,
36
- localObject = {},
37
- {
38
- localTransforms = [],
39
- globalTransforms = [],
40
- sloppyGlobalsMode = false,
41
- knownScopeProxies = new WeakSet(),
42
- } = {},
43
- ) => {
44
- // Execute the mandatory transforms last to ensure that any rewritten code
45
- // meets those mandatory requirements.
46
- source = applyTransforms(source, [
47
- ...localTransforms,
48
- ...globalTransforms,
49
- mandatoryTransforms,
50
- ]);
51
-
52
- const {
53
- scopeHandler,
54
- admitOneUnsafeEvalNext,
55
- resetOneUnsafeEvalNext,
56
- } = createScopeHandler(globalObject, localObject, {
57
- sloppyGlobalsMode,
58
- });
59
- const scopeProxyRevocable = proxyRevocable(immutableObject, scopeHandler);
60
-
61
- const constants = getScopeConstants(globalObject, localObject);
62
- const evaluateFactory = makeEvaluateFactory(constants);
63
- const evaluate = apply(evaluateFactory, scopeProxyRevocable.proxy, []);
64
-
65
- admitOneUnsafeEvalNext();
66
- let err;
67
- try {
68
- // Ensure that "this" resolves to the safe global.
69
- weaksetAdd(knownScopeProxies, scopeProxyRevocable.proxy);
70
- return apply(evaluate, globalObject, [source]);
71
- } catch (e) {
72
- // stash the child-code error in hopes of debugging the internal failure
73
- err = e;
74
- throw e;
75
- } finally {
76
- if (resetOneUnsafeEvalNext()) {
77
- // Barring a defect in the SES shim, the scope proxy should allow the
78
- // powerful, unsafe `eval` to be used by `evaluate` exactly once, as the
79
- // very first name that it attempts to access from the lexical scope.
80
- // A defect in the SES shim could throw an exception after our call to
81
- // `admitOneUnsafeEvalNext()` and before `evaluate` calls `eval`
82
- // internally.
83
- // If we get here, SES is very broken.
84
- // This condition is one where this vat is now hopelessly confused, and
85
- // the vat as a whole should be aborted.
86
- // No further code should run.
87
- // All immediately reachable state should be abandoned.
88
- // However, that is not yet possible, so we at least prevent further
89
- // variable resolution via the scopeHandler, and throw an error with
90
- // diagnostic info including the thrown error if any from evaluating the
91
- // source code.
92
- scopeProxyRevocable.revoke();
93
- // TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
94
- // See https://github.com/Agoric/SES-shim/issues/490
95
- assert.fail(d`handler did not reset allowNextEvalToBeUnsafe ${err}`);
96
- }
97
- }
98
- };