# CVE-2021-42740: shell-quote command injection via Windows drive letter regex

Source: https://junglewise.ai/threats/cve-2021-42740-shell-quote-command-injection-via-windows-drive-letter-regex  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2022-05-24. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2021-42740 · Severity: low · CVSS 3.1 · Published 2022-05-24

The shell-quote Node.js library is responsible for escaping strings so they can be safely passed to shell commands. A flawed regular expression intended to detect Windows drive letters failed to properly escape special shell metacharacters (like backticks), allowing an attacker to inject arbitrary shell commands if the library's output is used in a real shell execution context.

Technologies: [shell-quote (npm)](https://junglewise.ai/threats/technologies/shell-quote). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2021-42740 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-42740 being exploited in the wild.

**How severe is CVE-2021-42740?** Low severity, with a CVSS score of 3.1, published 24 May 2022.

**Which products and versions are affected?** shell-quote (npm) 1.6.3 through 1.7.2.

**Is there a fix for CVE-2021-42740?** A patch was published on 2022-05-24: Advisory GHSA-g4rg-993r-mgx7 published with fix in version 1.7.3 Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2021-42740 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2021-42740?** Check whether you run shell-quote (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## Technical details

shell-quote contains an Improper Neutralization of Special Elements vulnerability (CWE-77) in its Windows drive letter detection regex. The regex uses [A-z] instead of the correct [A-Za-z], which fails to exclude shell metacharacters (such as backticks, brackets, and other characters) in the ASCII range between uppercase Z and lowercase a. If attacker-controlled input is passed to the quote function and the output is subsequently used in exec() or similar shell execution, arbitrary commands can be executed. The vulnerability was introduced in version 1.6.3 and fixed in version 1.7.3. No authentication or user interaction is required; network-reachable applications that process untrusted input through shell-quote are at risk.

## Affected products

- npm shell-quote 1.6.3 through 1.7.2

## Identifiers

- CVE-2021-42740
- GHSA-g4rg-993r-mgx7

## Timeline

- 2021-10-21: disclosed: CVE-2021-42740 published on NVD
- 2022-05-24: patched: Advisory GHSA-g4rg-993r-mgx7 published with fix in version 1.7.3
- 2022-06-21: other: GitHub security review completed

## References

- [https://github.com/ljharb/shell-quote/commit/5799416ed454aa4ec9afafc895b4e31760ea1abe](https://github.com/ljharb/shell-quote/commit/5799416ed454aa4ec9afafc895b4e31760ea1abe)

## Related threats

- [shell-quote quote() function code injection in comment handling](https://junglewise.ai/threats/cve-2026-102422-shell-quote-s-quote-function-emits-a-comment-token-as-followed)
- [ljharb shell-quote Denial of Service in parse function](https://junglewise.ai/threats/cve-2026-13311-ljharb-shell-quote-denial-of-service-in-parse-function)
- [ljharb shell-quote command injection in quote function](https://junglewise.ai/threats/cve-2026-9277-ljharb-shell-quote-command-injection-in-quote-function)
- [shell-quote command injection in argument escaping](https://junglewise.ai/threats/cve-2016-10541-shell-quote-command-injection-in-argument-escaping)
