Executive brief
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.
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
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