CVE-2023-39532: Insufficient Information (NVD-CWE-noinfo)
value: SES is a JavaScript environment that allows safe execution of arbitrary programs in Compartments. In version 0.18.0 prior to 0.18.7, 0.17.0 prior to 0.17.1, 0.16.0 prior to 0.16.1, 0.15.0 prior to 0.15.24, 0.14.0 prior to 0.14.5, an 0.13.0 prior to 0.13.5, there is a hole in the confinement of guest applications under SES that may manifest as either the ability to exfiltrate information or execute arbitrary code depending on the configuration and implementation of the surrounding host.

Guest program running inside a Compartment with as few as no endowments can gain access to the surrounding host’s dynamic import by using dynamic import after the spread operator, like `{...import(arbitraryModuleSpecifier)}`.

On the web or in web extensions, a Content-Security-Policy following ordinary best practices likely mitigates both the risk of exfiltration and execution of arbitrary code, at least limiting the modules that the attacker can import to those that are already part of the application. However, without a Content-Security-Policy, dynamic import can be used to issue HTTP requests for either communication through the URL or for the execution of code reachable from that origin.

Within an XS worker, an attacker can use the host’s module system to the extent that the host has been configured. This typically only allows access to module code on the host’s file system and is of limited use to an attacker.

Within Node.js, the attacker gains access to Node.js’s module system. Importing the powerful builtins is not useful except insofar as there are side-effects and tempered because dynamic import returns a promise. Spreading a promise into an object renders the promises useless. However, Node.js allows importing data URLs, so this is a clear path to arbitrary execution.

Versions 0.18.7, 0.17.1, 0.16.1, 0.15.24, 0.14.5, and 0.13.5 contain a patch for this issue. Some workarounds are available. On the web, providing a suitably constrained Content-Security-Policy mitigates most of the threat. With XS, building a binary that lacks the ability to load modules at runtime mitigates the entirety of the threat. That will look like an implementation of `fxFindModule` in a file like `xsPlatform.c` that calls `fxRejectModuleFile`.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
CVSS v3 base score: 9.8
Published: 2023-08-08T17:15Z
Repository: https://github.com/endojs/endo
Language: JavaScript
Files changed: packages/ses/NEWS.md, packages/ses/src/transforms.js, packages/ses/test/test-transforms.js
Commit date: 2023-08-07 14:35:51 -0700
Commit message: fix(fix): Censor spread import

Diff: diff --git a/packages/ses/NEWS.md b/packages/ses/NEWS.md
index c988c56be..4c805dbf1 100644
--- a/packages/ses/NEWS.md
+++ b/packages/ses/NEWS.md
@@ -1,7 +1,15 @@
 User-visible changes in SES:
 
+# Next
+
+- Censors the pattern `{...import(specifier)`}.
+  We previously censored `import(specifier)` and expressly allowed
+  `object.import(specifier)`.
+  The relaxation for the latter form in version 0.13.0 inadvertently allowed
+  import with the spread operator.
+
 # v0.18.5 (2023-07-14)
 
 - Adds `assert.bare` for embedding unquoted strings in details.
 - Permits new `dispose` symbols, other recent additions to JavaScript, and for
   the anticipated iterator helpers.
diff --git a/packages/ses/src/transforms.js b/packages/ses/src/transforms.js
index a0fc8d0ef..64a46cb53 100644
--- a/packages/ses/src/transforms.js
+++ b/packages/ses/src/transforms.js
@@ -104,11 +104,11 @@ export const evadeHtmlCommentTest = src => {
 };
 
 // /////////////////////////////////////////////////////////////////////////////
 
 const importPattern = new FERAL_REG_EXP(
-  '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
+  '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
   'g',
 );
 
 /**
  * Conservatively reject the source text if it may contain a dynamic
diff --git a/packages/ses/test/test-transforms.js b/packages/ses/test/test-transforms.js
index cef0c02c1..978ec3224 100644
--- a/packages/ses/test/test-transforms.js
+++ b/packages/ses/test/test-transforms.js
@@ -4,11 +4,11 @@ import {
   rejectHtmlComments,
   rejectSomeDirectEvalExpressions,
 } from '../src/transforms.js';
 
 test('no-import-expression regexp', t => {
-  t.plan(9);
+  t.plan(14);
 
   // Note: we cannot define these as regular functions (and then stringify)
   // because the 'esm' module loader that we use for running the tests (i.e.
   // 'tape -r esm ./shim/test/**/*.js') sees the 'import' statements and
   // rewrites them.
@@ -18,21 +18,27 @@ test('no-import-expression regexp', t => {
   // So we don't assert that behavior one way or the other
 
   const safe = 'const a = 1';
   const safe2 = "const a = notimport('evil')";
   const safe3 = "const a = importnot('evil')";
+  const safe4 = "const a = compartment.import('name')";
 
   const obvious = "const a = import('evil')";
   const whitespace = "const a = import ('evil')";
   const comment = "const a = import/*hah*/('evil')";
   const doubleSlashComment = "const a = import // hah\n('evil')";
   const newline = "const a = import\n('evil')";
   const multiline = "\nimport('a')\nimport('b')";
+  const spread = "{...import('exfil')}";
+  const spread2 = "{... import('exfil')}";
+  const spread3 = "{\n...\nimport\n('exfil')}";
+  const spread4 = "{\n...\nimport/**/\n('exfil')}";
 
   t.is(rejectImportExpressions(safe), safe, 'safe');
   t.is(rejectImportExpressions(safe2), safe2, 'safe2');
   t.is(rejectImportExpressions(safe3), safe3, 'safe3');
+  t.is(rejectImportExpressions(safe4), safe4, 'safe4');
   t.throws(
     () => rejectImportExpressions(obvious),
     { instanceOf: SyntaxError },
     'obvious',
   );
@@ -60,10 +66,30 @@ test('no-import-expression regexp', t => {
     () => rejectImportExpressions(multiline),
     { instanceOf: SyntaxError },
     'possible import expression rejected around line 2',
     'multiline',
   );
+  t.throws(
+    () => rejectImportExpressions(spread),
+    { instanceOf: SyntaxError },
+    'spread',
+  );
+  t.throws(
+    () => rejectImportExpressions(spread2),
+    { instanceOf: SyntaxError },
+    'spread2',
+  );
+  t.throws(
+    () => rejectImportExpressions(spread3),
+    { instanceOf: SyntaxError },
+    'spread3',
+  );
+  t.throws(
+    () => rejectImportExpressions(spread4),
+    { instanceOf: SyntaxError },
+    'spread4',
+  );
 });
 
 test('no-html-comment-expression regexp', t => {
   t.plan(6);
 

Vulnerable code:   '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
  t.plan(9);
Fixed code: # Next

- Censors the pattern `{...import(specifier)`}.
  We previously censored `import(specifier)` and expressly allowed
  `object.import(specifier)`.
  The relaxation for the latter form in version 0.13.0 inadvertently allowed
  import with the spread operator.

  '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
  t.plan(14);
  const safe4 = "const a = compartment.import('name')";
  const spread = "{...import('exfil')}";
  const spread2 = "{... import('exfil')}";
  const spread3 = "{\n...\nimport\n('exfil')}";
  const spread4 = "{\n...\nimport/**/\n('exfil')}";
  t.is(rejectImportExpressions(safe4), safe4, 'safe4');
  t.throws(
    () => rejectImportExpressions(spread),
    { instanceOf: SyntaxError },
    'spread',
  );
  t.throws(
    () => rejectImportExpressions(spread2),
    { instanceOf: SyntaxError },
    'spread2',
  );
  t.throws(
    () => rejectImportExpressions(spread3),
    { instanceOf: SyntaxError },
    'spread3',
  );
  t.throws(
    () => rejectImportExpressions(spread4),
    { instanceOf: SyntaxError },
    'spread4',
  );