CVE-2023-40185: Shescape Shescape On Windows Escaping May Vulnerability
HIGHCVE-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
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).
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.
npm install shescape@1.7.4
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
CVE-2023-40185 Affected Shescape Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
shescape
|
npm |
< 1.7.4
|
1.7.4
|
References
Frequently Asked Questions
What is CVE-2023-40185?
Which Shescape versions are affected?
What version fixes CVE-2023-40185?
Is shescape affected?
What is the CVSS score of CVE-2023-40185?
What CWE is associated with CVE-2023-40185?
How can I check npm dependencies for CVE-2023-40185?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}