Skip to main content

CVE-2022-31180: CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') in ericcornelissen shescape

Medium
Published: Mon Aug 01 2022 (08/01/2022, 19:15:16 UTC)
Source: CVE
Vendor/Project: ericcornelissen
Product: shescape

Description

Shescape is a simple shell escape package for JavaScript. Affected versions were found to have insufficient escaping of white space when interpolating output. This issue only impacts users that use the `escape` or `escapeAll` functions with the `interpolation` option set to `true`. The result is that if an attacker is able to include whitespace in their input they can: 1. Invoke shell-specific behaviour through shell-specific special characters inserted directly after whitespace. 2. Invoke shell-specific behaviour through shell-specific special characters inserted or appearing after line terminating characters. 3. Invoke arbitrary commands by inserting a line feed character. 4. Invoke arbitrary commands by inserting a carriage return character. Behaviour number 1 has been patched in [v1.5.7] which you can upgrade to now. No further changes are required. Behaviour number 2, 3, and 4 have been patched in [v1.5.8] which you can upgrade to now. No further changes are required. The best workaround is to avoid having to use the `interpolation: true` option - in most cases using an alternative is possible, see [the recipes](https://github.com/ericcornelissen/shescape#recipes) for recommendations. Alternatively, users may strip all whitespace from user input. Note that this is error prone, for example: for PowerShell this requires stripping `'\u0085'` which is not included in JavaScript's definition of `\s` for Regular Expressions.

AI-Powered Analysis

AILast updated: 06/22/2025, 00:10:59 UTC

Technical Analysis

CVE-2022-31180 is a vulnerability in the JavaScript package 'shescape', which is designed to provide shell escaping functionality. The affected versions range from 1.4.0 up to but not including 1.5.8. The core issue arises from improper neutralization of special elements in output when the 'escape' or 'escapeAll' functions are used with the 'interpolation' option set to true. Specifically, the package insufficiently escapes whitespace characters during output interpolation. This allows an attacker who can control input containing whitespace to inject shell-specific special characters immediately following whitespace or line-terminating characters (such as line feeds or carriage returns). Such injection can lead to the execution of arbitrary shell commands. The vulnerability manifests in four behaviors: (1) invoking shell-specific behavior through special characters after whitespace, (2) invoking shell-specific behavior after line terminators, (3) arbitrary command execution via line feed insertion, and (4) arbitrary command execution via carriage return insertion. Behaviors (1) were patched in version 1.5.7, and behaviors (2), (3), and (4) were patched in version 1.5.8. The recommended mitigation is upgrading to version 1.5.8 or later. Alternatively, avoiding the use of the 'interpolation: true' option or sanitizing input by stripping all whitespace can reduce risk, though the latter is error-prone due to complex whitespace definitions in different shells (e.g., PowerShell's inclusion of Unicode character '\u0085'). No known exploits are reported in the wild, but the vulnerability poses a risk where untrusted input is passed through vulnerable versions of shescape with interpolation enabled, potentially leading to command injection and remote code execution.

Potential Impact

For European organizations, the impact of this vulnerability can be significant if they use JavaScript applications or services that rely on the vulnerable versions of shescape with the interpolation option enabled. Successful exploitation could lead to arbitrary command execution on affected systems, compromising confidentiality, integrity, and availability. This could result in unauthorized data access, system manipulation, or disruption of services. The risk is heightened in environments where user input is directly passed to shell commands without proper sanitization. Sectors such as finance, healthcare, critical infrastructure, and government agencies in Europe that deploy Node.js applications or automation scripts using shescape may be particularly vulnerable. Although no active exploits are known, the ease of exploitation through crafted input and the potential for remote code execution make this a medium to high risk if left unpatched. Additionally, the vulnerability could be leveraged as an initial access vector or lateral movement tool in targeted attacks against European enterprises.

Mitigation Recommendations

1. Upgrade all instances of shescape to version 1.5.8 or later immediately to ensure all injection vectors are patched. 2. Audit codebases and dependencies to identify usage of the 'escape' or 'escapeAll' functions with 'interpolation: true' and refactor to avoid this option where possible, using recommended alternative patterns from the official shescape recipes. 3. Implement strict input validation and sanitization on all user-supplied data, especially focusing on removing or encoding whitespace and special shell characters before passing input to shell commands. 4. For environments where input sanitization is complex (e.g., PowerShell), consider using safer command execution methods such as parameterized commands or dedicated APIs that avoid shell interpretation. 5. Employ runtime monitoring and alerting for anomalous shell command executions that could indicate exploitation attempts. 6. Incorporate this vulnerability into organizational threat modeling and patch management processes to ensure timely updates. 7. Educate developers on secure coding practices related to shell command construction and the risks of improper escaping.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-05-18T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9849c4522896dcbf6742

Added to database: 5/21/2025, 9:09:29 AM

Last enriched: 6/22/2025, 12:10:59 AM

Last updated: 8/11/2025, 7:29:52 PM

Views: 10

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats