Cloudanix VulnDB

CVE-2021-42740

Critical · 9.8

CVSS

9.8

EPSS

4.2%

Published

Oct 21, 2021

CISA due date

—

Cloudanix analysis

Next patch cycle SSVC: Track

A flaw in a widely used software building block could allow an attacker to run malicious commands on an application's server, potentially leading to a complete system takeover.

Chainable
Exploitation
Remote Unauthenticated
Attacker needs
None
Complexity
Low
Impact
Remote Code Execution
Component
Library
Class
Command Injection
Remediation
Upgrade
Effort
Medium
Patch risk
Low

What it actually does

The vulnerability in the shell-quote Node.js package is a command injection flaw caused by an improper regular expression used for sanitization. The regex `{A-z]` was intended to match Windows drive letters but incorrectly allows shell metacharacters (such as the backtick `) that fall between 'Z' and 'a' in the ASCII table to pass through without being escaped. If an application uses this library to quote user-provided input and then passes the result to a shell execution function like `exec()`, an attacker can inject and execute arbitrary commands with the permissions of the Node.js application process.

Why it matters to the business

An attacker can gain full control over the server running the vulnerable application, leading to remote code execution. This can result in the theft of sensitive data, such as customer information or intellectual property, service disruption, or using the compromised server to launch further attacks against the internal network. Given the critical CVSS score of 9.8, this vulnerability poses a severe risk to the confidentiality, integrity, and availability of the affected system.

How an attack unfolds

An unauthenticated, remote attacker identifies an application that uses a vulnerable version of the `shell-quote` library to process user input before passing it to a system shell. The attacker crafts a malicious string containing shell metacharacters, such as backticks enclosing a command (e.g., `` `whoami` ``). This string is submitted to the application. The vulnerable library fails to properly escape the backticks. When the application concatenates this improperly sanitized string into a command and executes it via a function like `child_process.exec()`, the operating system's shell interprets the backticks, executes the attacker's embedded command, and substitutes its output, leading to a full command injection.

How to fix it

The vulnerability is patched in version 1.7.3 of the `shell-quote` package. Update the dependency to version 1.7.3 or later. Use your package manager to perform the upgrade, for example, by running `npm install shell-quote@latest` or `yarn upgrade shell-quote`. Ensure that your `package-lock.json` or `yarn.lock` file is updated and committed to reflect the fixed version.

How to confirm the fix worked

To confirm remediation, verify that the version of `shell-quote` in your project's dependency tree is 1.7.3 or higher. You can check the installed version by running `npm ls shell-quote` or `yarn list --pattern shell-quote` in your project's root directory. Additionally, use a Software Composition Analysis (SCA) tool to scan your application's dependencies for this and other known vulnerabilities to ensure all direct and transitive dependencies are secure.

Typical attack path

  1. An attacker identifies a target application using a vulnerable version of the Node.js `shell-quote` library.
  2. The attacker crafts a malicious input string containing unescaped shell metacharacters, such as `` `id` ``, designed to exploit the flawed regex.
  3. The attacker sends this malicious string to an application endpoint that processes it with the vulnerable library.
  4. The `shell-quote` library fails to properly sanitize the input, leaving the metacharacters intact.
  5. The application passes the malformed string to a shell execution function.
  6. The underlying system shell executes the injected command, giving the attacker code execution on the server.

How to detect it

Monitor process execution logs on servers running Node.js applications for anomalous activity. Look for the `node` process spawning unexpected child processes, particularly common shell utilities like `sh`, `bash`, `whoami`, `id`, `uname`, `wget`, `curl`, or `nc`. Examine application and web server logs for inbound requests containing unusual characters like backticks (`) within parameters that are likely passed to shell commands.

  • Process execution event where parent process is `node` and child process is `sh` or `bash` with suspicious arguments.
  • Process execution event where parent process is `node` and child process is `whoami`, `id`, `uname`, `wget`, `curl`, or `nc`.
  • Application log entries containing input strings with backticks, such as `` `...` ``.

What your security team should do

  • Immediately identify all Node.js applications using `shell-quote` and prioritize patching for internet-facing systems.
  • Update the `shell-quote` package to version 1.7.3 or newer across all affected codebases.
  • Run Software Composition Analysis (SCA) scans to discover all instances of the vulnerable package, including as a transitive dependency.
  • As a defense-in-depth measure, review code for any use of shell execution functions (`exec`, `spawn`) and avoid passing user-controllable data to them whenever possible.

The record

The shell-quote package before 1.7.3 for Node.js allows command injection. An attacker can inject unescaped shell metacharacters through a regex designed to support Windows drive letters. If the output of this package is passed to a real shell as a quoted argument to a command with exec(), an attacker can inject arbitrary commands. This is because the Windows drive letter regex character class is {A-z] instead of the correct {A-Za-z]. Several shell metacharacters exist in the space between capital letter Z and lower case letter a, such as the backtick character.

Affected packages

Ecosystem Package Introduced Fixed
npm shell-quote 0 1.7.3
npm shell-quote 1.6.3 1.7.3
Chainguard jitsucom-jitsu 0 0
Chainguard jitsucom-jitsu-console 0 0
Chainguard jitsucom-jitsu-rotor 0 0
Debian:12 node-shell-quote 0 1.7.3+~1.7.1-1
Debian:13 node-shell-quote 0 1.7.3+~1.7.1-1
SUSE:Manager Proxy 4.2 release-notes-susemanager-proxy 0 4.2.9-150300.3.43.1
SUSE:Manager Proxy 4.3 release-notes-susemanager-proxy 0 4.3.2-150400.3.9.3
SUSE:Manager Proxy Module 4.2 mgr-daemon 0 4.2.10-150300.2.9.4
SUSE:Manager Proxy Module 4.2 mgr-osad 0 4.2.9-150300.2.12.2
SUSE:Manager Proxy Module 4.2 patterns-suse-manager 0 4.2-150300.4.12.2
SUSE:Manager Proxy Module 4.2 rhnlib 0 4.2.7-150300.4.12.2
SUSE:Manager Proxy Module 4.2 spacecmd 0 4.2.21-150300.4.33.2
SUSE:Manager Proxy Module 4.2 spacecmd 0 4.2.19-150300.4.27.2
SUSE:Manager Proxy Module 4.2 spacewalk-backend 0 4.2.26-150300.4.35.6
SUSE:Manager Proxy Module 4.2 spacewalk-backend 0 4.2.24-150300.4.29.5
SUSE:Manager Proxy Module 4.2 spacewalk-certs-tools 0 4.2.19-150300.3.27.4
SUSE:Manager Proxy Module 4.2 spacewalk-certs-tools 0 4.2.18-150300.3.24.3
SUSE:Manager Proxy Module 4.2 spacewalk-client-tools 0 4.2.22-150300.4.30.2
SUSE:Manager Proxy Module 4.2 spacewalk-client-tools 0 4.2.20-150300.4.24.3
SUSE:Manager Proxy Module 4.2 spacewalk-proxy 0 4.2.13-150300.3.24.2
SUSE:Manager Proxy Module 4.2 spacewalk-proxy 0 4.2.12-150300.3.21.3
SUSE:Manager Proxy Module 4.2 spacewalk-proxy-installer 0 4.2.11-150300.3.14.2
SUSE:Manager Proxy Module 4.2 spacewalk-web 0 4.2.32-150300.3.36.4
SUSE:Manager Proxy Module 4.2 spacewalk-web 0 4.2.29-150300.3.27.3
SUSE:Manager Proxy Module 4.2 susemanager-build-keys 0 15.3.6-150300.3.6.2
SUSE:Manager Proxy Module 4.2 susemanager-tftpsync-recv 0 4.2.5-150300.3.6.2
SUSE:Manager Proxy Module 4.2 uyuni-common-libs 0 4.2.9-150300.3.14.1
SUSE:Manager Proxy Module 4.2 uyuni-common-libs 0 4.2.7-150300.3.9.2
SUSE:Manager Retail Branch Server 4.2 release-notes-susemanager-proxy 0 4.2.9-150300.3.43.1
SUSE:Manager Retail Branch Server 4.3 release-notes-susemanager-proxy 0 4.3.2-150400.3.9.3
SUSE:Manager Server 4.2 release-notes-susemanager 0 4.2.9-150300.3.54.1
SUSE:Manager Server 4.3 release-notes-susemanager 0 4.3.2-150400.3.15.1
SUSE:Manager Server Module 4.2 cobbler 0 3.1.2-150300.5.19.1
SUSE:Manager Server Module 4.2 drools 0 7.17.0-150300.4.9.2
SUSE:Manager Server Module 4.2 drools 0 7.17.0-150300.4.6.2
SUSE:Manager Server Module 4.2 grafana-formula 0 0.8.1-150300.3.9.2
SUSE:Manager Server Module 4.2 httpcomponents-asyncclient 0 4.1.4-150300.3.3.2
SUSE:Manager Server Module 4.2 image-sync-formula 0 0.1.1661440526.b08d95b-150300.3.3.2
SUSE:Manager Server Module 4.2 inter-server-sync 0 0.2.7-150300.8.28.2
SUSE:Manager Server Module 4.2 inter-server-sync 0 0.2.3-150300.8.22.2
SUSE:Manager Server Module 4.2 mgr-osad 0 4.2.9-150300.2.12.2
SUSE:Manager Server Module 4.2 patterns-suse-manager 0 4.2-150300.4.12.2
SUSE:Manager Server Module 4.2 prometheus-formula 0 0.7.0-150300.3.17.2
SUSE:Manager Server Module 4.2 py27-compat-salt 0 3000.3-150300.7.7.29.2
SUSE:Manager Server Module 4.2 py27-compat-salt 0 3000.3-150300.7.7.23.2
SUSE:Manager Server Module 4.2 rhnlib 0 4.2.7-150300.4.12.2
SUSE:Manager Server Module 4.2 salt-netapi-client 0 0.21.0-150300.3.12.4
SUSE:Manager Server Module 4.2 salt-netapi-client 0 0.20.0-150300.3.9.4
SUSE:Manager Server Module 4.2 saltboot-formula 0 0.1.1676908681.e90e0b1-150300.3.15.1
SUSE:Manager Server Module 4.2 saltboot-formula 0 0.1.1661440526.b08d95b-150300.3.12.2
SUSE:Manager Server Module 4.2 smdba 0 1.7.11-0.150300.3.12.2
SUSE:Manager Server Module 4.2 spacecmd 0 4.2.21-150300.4.33.2
SUSE:Manager Server Module 4.2 spacecmd 0 4.2.19-150300.4.27.2
SUSE:Manager Server Module 4.2 spacewalk-admin 0 4.2.13-150300.3.18.1
SUSE:Manager Server Module 4.2 spacewalk-admin 0 4.2.12-150300.3.15.3
SUSE:Manager Server Module 4.2 spacewalk-backend 0 4.2.26-150300.4.35.6
SUSE:Manager Server Module 4.2 spacewalk-backend 0 4.2.24-150300.4.29.5
SUSE:Manager Server Module 4.2 spacewalk-certs-tools 0 4.2.19-150300.3.27.4
SUSE:Manager Server Module 4.2 spacewalk-certs-tools 0 4.2.18-150300.3.24.3
SUSE:Manager Server Module 4.2 spacewalk-client-tools 0 4.2.22-150300.4.30.2
SUSE:Manager Server Module 4.2 spacewalk-client-tools 0 4.2.20-150300.4.24.3
SUSE:Manager Server Module 4.2 spacewalk-java 0 4.2.47-150300.3.58.1
SUSE:Manager Server Module 4.2 spacewalk-java 0 4.2.41-150300.3.43.5
SUSE:Manager Server Module 4.2 spacewalk-search 0 4.2.9-150300.3.15.2
SUSE:Manager Server Module 4.2 spacewalk-search 0 4.2.8-150300.3.12.2
SUSE:Manager Server Module 4.2 spacewalk-web 0 4.2.32-150300.3.36.4
SUSE:Manager Server Module 4.2 spacewalk-web 0 4.2.29-150300.3.27.3
SUSE:Manager Server Module 4.2 subscription-matcher 0 0.29-150300.6.12.2
SUSE:Manager Server Module 4.2 supportutils-plugin-susemanager 0 4.2.5-150300.3.9.2
SUSE:Manager Server Module 4.2 susemanager 0 4.2.40-150300.3.49.1
SUSE:Manager Server Module 4.2 susemanager 0 4.2.37-150300.3.41.1
SUSE:Manager Server Module 4.2 susemanager-build-keys 0 15.3.6-150300.3.6.2
SUSE:Manager Server Module 4.2 susemanager-doc-indexes 0 4.2-150300.12.39.4
SUSE:Manager Server Module 4.2 susemanager-doc-indexes 0 4.2-150300.12.33.4
SUSE:Manager Server Module 4.2 susemanager-docs_en 0 4.2-150300.12.39.2
SUSE:Manager Server Module 4.2 susemanager-docs_en 0 4.2-150300.12.33.2
SUSE:Manager Server Module 4.2 susemanager-schema 0 4.2.27-150300.3.35.1
SUSE:Manager Server Module 4.2 susemanager-schema 0 4.2.24-150300.3.27.3
SUSE:Manager Server Module 4.2 susemanager-sls 0 4.2.31-150300.3.43.1
SUSE:Manager Server Module 4.2 susemanager-sls 0 4.2.27-150300.3.33.4
SUSE:Manager Server Module 4.2 uyuni-common-libs 0 4.2.9-150300.3.14.1
SUSE:Manager Server Module 4.2 uyuni-common-libs 0 4.2.7-150300.3.9.2
SUSE:Manager Server Module 4.2 virtual-host-gatherer 0 1.0.24-150300.3.9.2
SUSE:Manager Server Module 4.2 woodstox 0 4.4.2-150300.3.6.2
Ubuntu:18.04:LTS node-shell-quote 0 No fix
Ubuntu:22.04:LTS node-shell-quote 0 1.7.3+~1.7.1-1
Ubuntu:Pro:18.04:LTS node-shell-quote 0 No fix
Wolfi jitsucom-jitsu 0 0
Wolfi jitsucom-jitsu-console 0 0
Wolfi jitsucom-jitsu-rotor 0 0

Related vulnerabilities