CVE-2023-39532: Ses SES's Dynamic Import And Spread Vulnerability

CRITICAL
Advisory Identifier: GHSA-9c4h-3f7h-322r
CVSS 9.8
CWE-20
Published
Advisory Summary

CVE-2023-39532 is a CRITICAL (CVSS 9.8) ses's dynamic import and spread vulnerability (CWE-20: Improper Input Validation) affecting Ses libraries in the npm ecosystem. The issue involves ses's dynamic import and spread operator provides possible path to arbitrary exfiltration and execution. Remediation is available by upgrading affected packages to version 0.13.5, 0.14.5, 0.15.24, 0.16.1, 0.17.1, 0.18.7.

CVE-2023-39532 at a Glance

CVE Identifier CVE-2023-39532
GHSA Identifier GHSA-9c4h-3f7h-322r
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-20: Improper Input Validation
Affected Product Ses
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2023-39532

To remediate this vulnerability, upgrade all affected Ses dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

ses fixed: 0.13.5
npm install ses@0.13.5
ses fixed: 0.14.5
npm install ses@0.14.5
ses fixed: 0.15.24
npm install ses@0.15.24
ses fixed: 0.16.1
npm install ses@0.16.1
ses fixed: 0.17.1
npm install ses@0.17.1
ses fixed: 0.18.7
npm install ses@0.18.7
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls ses

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-39532, inspect your project dependencies using npm:

npm ls ses

Analyze the terminal output to locate any version of Ses in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.13.5), your application is affected.

Note: The npm ls ses command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In Ses, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact This 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. ### Patches All affected `0.*` version trains have the following patch. Running `npm update` will obtain the patch on all affected projects using `^0.*` style dependency constraints in their `package.json`. ```diff From 33469e88bfb2bf34a161c265f10f808ce354a700 Mon Sep 17 00:00:00 2001 From: Kris Kowal <kris@agoric.com> Date: Thu, 27 Jul 2023 13:25:13 -0700 Subject: [PATCH] fix(fix): Censor spread import --- packages/ses/src/transforms.js | 2 +- packages/ses/test/test-transforms.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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 @@ -106,7 +106,7 @@ export const evadeHtmlCommentTest = src => { // ///////////////////////////////////////////////////////////////////////////// const importPattern = new FERAL_REG_EXP( - '(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))', + '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))', 'g', ); diff --git a/packages/ses/test/test-transforms.js b/packages/ses/test/test-transforms.js index cef0c02c1..8f6818b83 100644 --- a/packages/ses/test/test-transforms.js +++ b/packages/ses/test/test-transforms.js @@ -6,7 +6,7 @@ import { } from '../src/transforms.js'; test('no-import-expression regexp', t => { - t.plan(9); + t.plan(13); // 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. @@ -20,6 +20,7 @@ test('no-import-expression regexp', t => { 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')"; @@ -27,10 +28,14 @@ test('no-import-expression regexp', t => { 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 = "{\n...\nimport\n('exfil')}"; + const spread3 = "{\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 }, @@ -62,6 +67,21 @@ test('no-import-expression regexp', t => { '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', + ); }); test('no-html-comment-expression regexp', t => { -- 2.40.1 ``` ### Workarounds 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`. We highly advise applying the above patch for Node.js as there is no known work-around and Node.js’s module specifiers are exceedingly powerful, including support for `data:text/javascript,` style module specifier URLs. ### References No references at this time.

CVE-2023-39532 Affected Ses Versions

6 component(s)
Fixed Versions:
0.13.50.14.50.15.240.16.10.17.10.18.7
Product / Package Ecosystem Affected Versions Fixed Version
ses
npm
≥ 0.13.0
< 0.13.5
0.13.5
ses
npm
≥ 0.14.0
< 0.14.5
0.14.5
ses
npm
≥ 0.15.0
< 0.15.24
0.15.24
ses
npm
≥ 0.16.0
< 0.16.1
All 1 versions
0.16.0
0.16.1
ses
npm
≥ 0.17.0
< 0.17.1
All 1 versions
0.17.0
0.17.1
ses
npm
≥ 0.18.0
< 0.18.7
0.18.7

References

Frequently Asked Questions

What is CVE-2023-39532?
CVE-2023-39532 is a security vulnerability in Ses involving SES's dynamic import and spread operator provides possible path to arbitrary exfiltration and execution under CWE-20: Improper Input Validation.
Which Ses versions are affected?
Affected versions include releases prior to 0.13.5, 0.14.5, 0.15.24, 0.16.1, 0.17.1, 0.18.7 across affected packages: ses.
What version fixes CVE-2023-39532?
Upgrading to 0.13.5, 0.14.5, 0.15.24, 0.16.1, 0.17.1, 0.18.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is ses affected?
Yes, ses is affected in releases prior to 0.13.5, 0.14.5, 0.15.24, 0.16.1, 0.17.1, 0.18.7. Upgrade your dependency to 0.13.5, 0.14.5, 0.15.24, 0.16.1, 0.17.1, 0.18.7 or later.
What is the CVSS score of CVE-2023-39532?
CVE-2023-39532 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-39532?
CVE-2023-39532 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check npm dependencies for CVE-2023-39532?
Run the dependency tree command: 'npm ls ses'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-9c4h-3f7h-322r",
  "modified" : "2023-08-09T14:43:20Z",
  "published" : "2023-08-09T14:43:20Z",
  "aliases" : [ "CVE-2023-39532" ],
  "summary" : "SES's dynamic import and spread operator provides possible path to arbitrary exfiltration and execution",
  "details" : "### Impact\n\nThis 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.\n\nGuest 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)}`.\n\nOn 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.\n\nWithin 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.\n\nWithin 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.\n\n### Patches\n\nAll affected `0.*` version trains have the following patch. Running `npm update` will obtain the patch on all affected projects using `^0.*` style dependency constraints in their `package.json`.\n\n```diff\nFrom 33469e88bfb2bf34a161c265f10f808ce354a700 Mon Sep 17 00:00:00 2001\nFrom: Kris Kowal <kris@agoric.com>\nDate: Thu, 27 Jul 2023 13:25:13 -0700\nSubject: [PATCH] fix(fix): Censor spread import\n\n---\n packages/ses/src/transforms.js       |  2 +-\n packages/ses/test/test-transforms.js | 22 +++++++++++++++++++++-\n 2 files changed, 22 insertions(+), 2 deletions(-)\n\ndiff --git a/packages/ses/src/transforms.js b/packages/ses/src/transforms.js\nindex a0fc8d0ef..64a46cb53 100644\n--- a/packages/ses/src/transforms.js\n+++ b/packages/ses/src/transforms.js\n@@ -106,7 +106,7 @@ export const evadeHtmlCommentTest = src => {\n // /////////////////////////////////////////////////////////////////////////////\n \n const importPattern = new FERAL_REG_EXP(\n-  '(^|[^.])\\\\bimport(\\\\s*(?:\\\\(|/[/*]))',\n+  '(^|[^.]|\\\\.\\\\.\\\\.)\\\\bimport(\\\\s*(?:\\\\(|/[/*]))',\n   'g',\n );\n \ndiff --git a/packages/ses/test/test-transforms.js b/packages/ses/test/test-transforms.js\nindex cef0c02c1..8f6818b83 100644\n--- a/packages/ses/test/test-transforms.js\n+++ b/packages/ses/test/test-transforms.js\n@@ -6,7 +6,7 @@ import {\n } from '../src/transforms.js';\n \n test('no-import-expression regexp', t => {\n-  t.plan(9);\n+  t.plan(13);\n \n   // Note: we cannot define these as regular functions (and then stringify)\n   // because the 'esm' module loader that we use for running the tests (i.e.\n@@ -20,6 +20,7 @@ test('no-import-expression regexp', t => {\n   const safe = 'const a = 1';\n   const safe2 = \"const a = notimport('evil')\";\n   const safe3 = \"const a = importnot('evil')\";\n+  const safe4 = \"const a = compartment.import('name')\";\n \n   const obvious = \"const a = import('evil')\";\n   const whitespace = \"const a = import ('evil')\";\n@@ -27,10 +28,14 @@ test('no-import-expression regexp', t => {\n   const doubleSlashComment = \"const a = import // hah\\n('evil')\";\n   const newline = \"const a = import\\n('evil')\";\n   const multiline = \"\\nimport('a')\\nimport('b')\";\n+  const spread = \"{...import('exfil')}\";\n+  const spread2 = \"{\\n...\\nimport\\n('exfil')}\";\n+  const spread3 = \"{\\n...\\nimport/**/\\n('exfil')}\";\n \n   t.is(rejectImportExpressions(safe), safe, 'safe');\n   t.is(rejectImportExpressions(safe2), safe2, 'safe2');\n   t.is(rejectImportExpressions(safe3), safe3, 'safe3');\n+  t.is(rejectImportExpressions(safe4), safe4, 'safe4');\n   t.throws(\n     () => rejectImportExpressions(obvious),\n     { instanceOf: SyntaxError },\n@@ -62,6 +67,21 @@ test('no-import-expression regexp', t => {\n     'possible import expression rejected around line 2',\n     'multiline',\n   );\n+  t.throws(\n+    () => rejectImportExpressions(spread),\n+    { instanceOf: SyntaxError },\n+    'spread',\n+  );\n+  t.throws(\n+    () => rejectImportExpressions(spread2),\n+    { instanceOf: SyntaxError },\n+    'spread2',\n+  );\n+  t.throws(\n+    () => rejectImportExpressions(spread3),\n+    { instanceOf: SyntaxError },\n+    'spread3',\n+  );\n });\n \n test('no-html-comment-expression regexp', t => {\n-- \n2.40.1\n```\n\n### Workarounds\n\nOn the web, providing a suitably constrained Content-Security-Policy mitigates most of the threat.\n\nWith 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`.\n\nWe highly advise applying the above patch for Node.js as there is no known work-around and Node.js’s module specifiers are exceedingly powerful, including support for `data:text/javascript,` style module specifier URLs.\n\n### References\n\nNo references at this time.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.13.0"
      }, {
        "fixed" : "0.13.5"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.14.0"
      }, {
        "fixed" : "0.14.5"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.15.0"
      }, {
        "fixed" : "0.15.24"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.16.0"
      }, {
        "fixed" : "0.16.1"
      } ]
    } ],
    "versions" : [ "0.16.0" ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.17.0"
      }, {
        "fixed" : "0.17.1"
      } ]
    } ],
    "versions" : [ "0.17.0" ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ses"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.18.0"
      }, {
        "fixed" : "0.18.7"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/endojs/endo/security/advisories/GHSA-9c4h-3f7h-322r"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-39532"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/endojs/endo/commit/fc90c6429604dc79ce8e3355e236ccce2bada041"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/endojs/endo"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-09T14:43:20Z",
    "nvd_published_at" : "2023-08-08T17:15:09Z"
  }
}