NodeJS/shell-quote/0.0.1


quote and parse shell commands

https://www.npmjs.com/package/shell-quote
MIT

3 Security Vulnerabilities

Improper Neutralization of Special Elements used in a Command in Shell-quote

Published date: 2022-05-24T19:18:27Z
CVE: CVE-2021-42740
Links:

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 versions: ["0.0.0", "0.0.1", "0.1.0", "0.1.1", "1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0", "1.4.1", "1.4.2", "1.4.3", "1.5.0", "1.6.0", "1.6.1", "1.6.2", "1.6.3", "1.7.0", "1.7.1", "1.7.2"]
Secure versions: [1.7.3, 1.7.4, 1.8.0, 1.8.1]
Recommendation: Update to version 1.8.1.

Potential Command Injection in shell-quote

Published date: 2019-02-18T23:58:29Z
CVE: CVE-2016-10541
Links:

Affected versions of shell-quote do not properly escape command line arguments, which may result in command injection if the library is used to escape user input destined for use as command line arguments.

Proof of Concept:

The following characters are not escaped properly: >,;,{,}

Bash has a neat but not well known feature known as Bash Brace Expansion, wherein a sub-command can be executed without spaces by running it between a set of {} and using the , instead of to seperate arguments. Because of this, full command injection is possible even though it was initially thought to be impossible.

   const quote = require('shell-quote').quote;
   console.log(quote(['a;{echo,test,123,234}']));
   // Actual                    "a;{echo,test,123,234}"
   // Expected                  "a\;\{echo,test,123,234\}"
   // Functional Equivalent     "a; echo 'test' '123' '1234'"

Recommendation

Update to version 1.6.1 or later.

Affected versions: ["0.0.0", "0.0.1", "0.1.0", "0.1.1", "1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0", "1.4.1", "1.4.2", "1.4.3", "1.5.0", "1.6.0"]
Secure versions: [1.7.3, 1.7.4, 1.8.0, 1.8.1]
Recommendation: Update to version 1.8.1.

Potential Command Injection

Published date: 2016-06-21
CVSS Score: 8.4
CVSS Vector: CVSS:3.0/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Coordinating vendor: ^Lift Security

The npm module shell-quote cannot correctly escape > and < operator used for redirection in shell. I'm wondering if this might be possible vulnerability for many application which depends on shell-quote.

For example:

const quote = require('shell-quote').quote; console.log(quote(['foo>bar']));

will print foo>bar, where foo\>bar is desirable.

This module is downloaded more than 1M times per month and many other modules are depending on this. If an application is escaping command-line args with this module, they might be vulnerable from malicious user input.

For example: ``` var sq = require('../tests/get/shell-quote-1.6.0'); var exec = require('child_process').exec;

var pattern = process.argv[2];

command = sq.quote(['grep', pattern])); exec('cat file | ' + command, function ( err, stdout, stderr) { console.log(command, stdout);
}); ``` will be vulnerable when user input something like pattern = ':</etc/passwd', which causes the content of /etc/passwd to be leaked.

Internally, (Jon Lamendola, Nick Starke, Jacob Waddell) found that the ;, {, and } characters weren't escaped properly either. This allows for full command injection. A malicious user could input 'a;{echo,test,123,234}' to execute echo fully.

Affected versions: ["0.0.0", "0.0.1", "0.1.0", "0.1.1", "1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0", "1.4.1", "1.4.2", "1.4.3", "1.5.0", "1.6.0"]
Secure versions: [1.7.3, 1.7.4, 1.8.0, 1.8.1]
Recommendation: Upgrade to at least version 1.6.1

27 Other Versions

Version License Security Released
1.8.1 MIT 2023-04-07 - 20:56 about 1 year
1.8.0 MIT 2023-01-31 - 03:27 about 1 year
1.7.4 MIT 2022-10-13 - 16:52 over 1 year
1.7.3 MIT 2021-10-21 - 06:34 over 2 years
1.7.2 MIT 1 2019-09-01 - 07:46 over 4 years
1.7.1 MIT 1 2019-08-13 - 13:35 over 4 years
1.7.0 MIT 1 2019-08-13 - 07:52 over 4 years
1.6.3 MIT 1 2019-08-13 - 07:41 over 4 years
1.6.2 MIT 1 2019-08-13 - 07:15 over 4 years
1.6.1 MIT 1 2016-06-17 - 20:43 almost 8 years
1.6.0 MIT 3 2016-04-24 - 05:53 about 8 years
1.5.0 MIT 3 2016-03-16 - 17:58 about 8 years
1.4.3 MIT 3 2015-03-08 - 03:47 about 9 years
1.4.2 MIT 3 2014-07-20 - 21:27 almost 10 years
1.4.1 MIT 3 2013-12-25 - 01:00 over 10 years
1.4.0 MIT 3 2013-10-18 - 01:40 over 10 years
1.3.3 MIT 3 2013-06-24 - 12:01 almost 11 years
1.3.2 MIT 3 2013-06-24 - 11:50 almost 11 years
1.3.1 MIT 3 2013-05-13 - 13:48 almost 11 years
1.3.0 MIT 3 2013-05-13 - 13:42 almost 11 years
1.2.0 MIT 3 2013-05-13 - 12:10 almost 11 years
1.1.0 MIT 3 2013-05-13 - 10:35 almost 11 years
1.0.0 MIT 3 2013-05-13 - 10:27 almost 11 years
0.1.1 MIT 3 2013-04-17 - 08:06 about 11 years
0.1.0 MIT 3 2013-04-15 - 04:36 about 11 years
0.0.1 MIT 3 2012-05-18 - 18:25 almost 12 years
0.0.0 MIT 3 2012-05-18 - 10:42 almost 12 years