CVE-2023-40185: Shescape on Windows escaping may be bypassed in threaded context

Published Aug 22, 2023
·
Updated

Impact

This may impact users that use Shescape on Windows in a threaded context (e.g. using Worker threads). 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:childprocess"; import { Worker, isMainThread } from 'node:workerthreads';

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 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 - Shescape commit 0b976da - Shescape release v1.7.4

For more information

- Comment on Pull Request #1142 - Comment on commit 0b976da - Open an issue at https://github.com/ericcornelissen/shescape/issues (New issue > Question > Get started)

Other sources

shescape is simple shell escape library for JavaScript. This may impact users that use Shescape on Windows in a threaded context. 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 bug has been patched in version 1.7.4.

Affected Software

3 affected componentsFixes available
npm/shescape<1.7.4
1.7.4
Shescape Project Shescape Node.js<1.7.4
Microsoft Windows

Event History

Aug 22, 2023
Advisory Published
06:00 PM
Aug 23, 2023
CVE Published
via MITRE·08:20 PM
Data Sourced
via MITRE·08:20 PM
DescriptionSeverityWeakness

Frequently Asked Questions

1

What is CVE-2023-40185?

CVE-2023-40185 is a vulnerability in the shescape library for JavaScript that can allow attackers to bypass protections in a threaded context on Windows systems.

2

Who is affected by CVE-2023-40185?

Users that use Shescape on Windows in a threaded context, such as with Worker threads in Node.js, are affected by CVE-2023-40185.

3

How does CVE-2023-40185 impact users?

CVE-2023-40185 can result in Shescape escaping or quoting for the wrong shell, which can allow attackers to bypass protections.

4

What is the severity of CVE-2023-40185?

CVE-2023-40185 has a severity of 8.6 (high).

5

How can I fix CVE-2023-40185?

You can fix CVE-2023-40185 by updating the shescape library to version 1.7.4 or higher.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203