CVE-2023-40185: Shescape Shescape On Windows Escaping May Vulnerability

HIGH
Advisory Identifier: GHSA-j55r-787p-m549
CVSS 8.6
CWE-150
Published
Advisory Summary

CVE-2023-40185 is a HIGH (CVSS 8.6) shescape on windows escaping may vulnerability (CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences) affecting Shescape libraries in the npm ecosystem. The issue involves shescape on windows escaping may be bypassed in threaded context. Remediation is available by upgrading affected packages to version 1.7.4.

CVE-2023-40185 at a Glance

CVE Identifier CVE-2023-40185
GHSA Identifier GHSA-j55r-787p-m549
Severity HIGH
CVSS v3.1 Base Score 8.6
CWE Classification CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences
Affected Product Shescape
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.6

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:C/C:N/I:H/A:N).

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

How to Fix CVE-2023-40185

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

shescape fixed: 1.7.4
npm install shescape@1.7.4
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 shescape

How to Check if You Are Affected

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

npm ls shescape

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

Note: The npm ls shescape 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-150: Improper Neutralization of Escape, Meta, or Control Sequences, where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component. In Shescape, 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 may impact users that use Shescape on Windows in a threaded context (e.g. using [Worker threads](https://nodejs.org/api/worker_threads.html)). The vulnerability can result in Shescape escaping (or quoting) for the wrong shell, thus allowing attackers to bypass protections depending on the combination of expected and used shell. This snippet demonstrates a vulnerable use of Shescape: ```javascript // vulnerable.js import { exec } from "node:child_process"; import { Worker, isMainThread } from 'node:worker_threads'; import * as shescape from "shescape"; if (isMainThread) { // 1. Something like a worker thread must be used. The reason being that they // unexpectedly change environment variable names on Windows. new Worker("./vulnerable.js"); } else { // 2. Example configuration that's problematic. In this setup example the // expected default system shell is CMD. We configure the use of PowerShell. // Shescape will fail to look up PowerShell and default to escaping for CMD // instead, resulting in the vulnerability. const options = { shell: "powershell", interpolation: true, }; // 3. Using shescape to protect against attacks, this is correct. const escaped = shescape.escape("&& ls", options); // 4. Invoking a command with the escaped user input, this is vulnerable in // this case. exec(`echo Hello ${escaped}`, options, (error, stdout) => { if (error) { console.error(`An error occurred: ${error}`); } else { console.log(stdout); } }); } ``` ### Patches This bug has been patched in [v1.7.4](https://github.com/ericcornelissen/shescape/releases/tag/v1.7.4) which you can upgrade to now. No further changes are required. ### Workarounds If you are impacted there is no workaround possible. ### References - Shescape Pull Request [#1142](https://github.com/ericcornelissen/shescape/pull/1142) - Shescape commit [`0b976da`](https://github.com/ericcornelissen/shescape/commit/0b976dab645abf45ffd85e74a8c6e51ee2f42d63) - Shescape release [v1.7.4](https://github.com/ericcornelissen/shescape/releases/tag/v1.7.4) ### For more information - Comment on Pull Request [#1142](https://github.com/ericcornelissen/shescape/pull/1142) - Comment on commit [`0b976da`](https://github.com/ericcornelissen/shescape/commit/0b976dab645abf45ffd85e74a8c6e51ee2f42d63) - Open an issue at [https://github.com/ericcornelissen/shescape/issues](https://github.com/ericcornelissen/shescape/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) (New issue > Question > Get started)

CVE-2023-40185 Affected Shescape Versions

1 component(s)
Fixed Versions:
1.7.4
Product / Package Ecosystem Affected Versions Fixed Version
shescape
npm
< 1.7.4
1.7.4

References

Frequently Asked Questions

What is CVE-2023-40185?
CVE-2023-40185 is a security vulnerability in Shescape involving Shescape on Windows escaping may be bypassed in threaded context under CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences.
Which Shescape versions are affected?
Affected versions include releases prior to 1.7.4 across affected packages: shescape.
What version fixes CVE-2023-40185?
Upgrading to 1.7.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is shescape affected?
Yes, shescape is affected in releases prior to 1.7.4. Upgrade your dependency to 1.7.4 or later.
What is the CVSS score of CVE-2023-40185?
CVE-2023-40185 has a CVSS v3.1 base score of 8.6 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2023-40185?
CVE-2023-40185 is classified under CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component.).
How can I check npm dependencies for CVE-2023-40185?
Run the dependency tree command: 'npm ls shescape'. 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-j55r-787p-m549",
  "modified" : "2023-09-01T19:46:34Z",
  "published" : "2023-08-22T18:00:04Z",
  "aliases" : [ "CVE-2023-40185" ],
  "summary" : "Shescape on Windows escaping may be bypassed in threaded context",
  "details" : "### Impact\n\nThis may impact users that use Shescape on Windows in a threaded context (e.g. using [Worker threads](https://nodejs.org/api/worker_threads.html)). The vulnerability can result in Shescape escaping (or quoting) for the wrong shell, thus allowing attackers to bypass protections depending on the combination of expected and used shell.\n\nThis snippet demonstrates a vulnerable use of Shescape:\n\n```javascript\n// vulnerable.js\n\nimport { exec } from \"node:child_process\";\nimport { Worker, isMainThread } from 'node:worker_threads';\n\nimport * as shescape from \"shescape\";\n\nif (isMainThread) {\n  // 1. Something like a worker thread must be used. The reason being that they\n  // unexpectedly change environment variable names on Windows.\n  new Worker(\"./vulnerable.js\");\n} else {\n  // 2. Example configuration that's problematic. In this setup example the\n  // expected default system shell is CMD. We configure the use of PowerShell.\n  // Shescape will fail to look up PowerShell and default to escaping for CMD\n  // instead, resulting in the vulnerability.\n  const options = {\n    shell: \"powershell\",\n    interpolation: true,\n  };\n\n  // 3. Using shescape to protect against attacks, this is correct.\n  const escaped = shescape.escape(\"&& ls\", options);\n\n  // 4. Invoking a command with the escaped user input, this is vulnerable in\n  // this case.\n  exec(`echo Hello ${escaped}`, options, (error, stdout) => {\n    if (error) {\n      console.error(`An error occurred: ${error}`);\n    } else {\n      console.log(stdout);\n    }\n  });\n}\n```\n\n### Patches\n\nThis bug has been patched in [v1.7.4](https://github.com/ericcornelissen/shescape/releases/tag/v1.7.4) which you can upgrade to now. No further changes are required.\n\n### Workarounds\n\nIf you are impacted there is no workaround possible.\n\n### References\n\n- Shescape Pull Request [#1142](https://github.com/ericcornelissen/shescape/pull/1142)\n- Shescape commit [`0b976da`](https://github.com/ericcornelissen/shescape/commit/0b976dab645abf45ffd85e74a8c6e51ee2f42d63)\n- Shescape release [v1.7.4](https://github.com/ericcornelissen/shescape/releases/tag/v1.7.4)\n\n### For more information\n\n- Comment on Pull Request [#1142](https://github.com/ericcornelissen/shescape/pull/1142)\n- Comment on commit [`0b976da`](https://github.com/ericcornelissen/shescape/commit/0b976dab645abf45ffd85e74a8c6e51ee2f42d63)\n- Open an issue at [https://github.com/ericcornelissen/shescape/issues](https://github.com/ericcornelissen/shescape/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) (New issue > Question > Get started)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "shescape"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.7.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/security/advisories/GHSA-j55r-787p-m549"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-40185"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/pull/1142"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/commit/0b976dab645abf45ffd85e74a8c6e51ee2f42d63"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ericcornelissen/shescape"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ericcornelissen/shescape/releases/tag/v1.7.4"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-150" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-22T18:00:04Z",
    "nvd_published_at" : "2023-08-23T21:15:09Z"
  }
}