# CVE-2022-31180: Insufficient escaping of whitespace in shescape

> Attackers can execute arbitrary commands via whitespace injection in shescape when interpolation is enabled, requiring an upgrade to patched versions.

- **Severity:** Critical 9.8 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 1 Aug 2022
- **Updated:** 22 Apr 2025
- **Also known as:** GHSA-44vr-rwwj-p88h

## What is CVE-2022-31180?

CVE-2022-31180 is a critical command injection vulnerability in ericcornelissen shescape, published on 1 Aug 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official 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.

Weakness: CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component)

## Which versions are affected by CVE-2022-31180?

2 open source packages ship an affected version, including shescape. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `shescape` | npm | From 1.4.0 | 1.5.8 |
| `shescape` | npm | From 1.4.0 | 1.5.8 |

Products: Shescape Project Shescape.

## How do I fix CVE-2022-31180?

Upgrade shescape to 1.5.8 or later.

## Is CVE-2022-31180 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31180 exists.

## Other vulnerabilities in ericcornelissen shescape

- [CVE-2022-31179](https://insights.sbomify.com/CVE-2022-31179/): Insufficient escaping of line feeds for CMD in shescape (high 8.1)
- [CVE-2026-32094](https://insights.sbomify.com/CVE-2026-32094/): Shescape escape() leaves bracket glob expansion active on Bash, BusyBox, and Dash (medium 6.9)
- [CVE-2023-40185](https://insights.sbomify.com/CVE-2023-40185/): Shescape on Windows escaping may be bypassed in threaded context (medium 6.5)
- [CVE-2021-21384](https://insights.sbomify.com/CVE-2021-21384/): Null characters not escaped in shescape (medium 6.3)
- [CVE-2022-24725](https://insights.sbomify.com/CVE-2022-24725/): Exposure of home directory through shescape on Unix with Bash (medium 6.2)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-31180 and fix it if it is affected.

What it is: CVE-2022-31180 is a critical command injection vulnerability in ericcornelissen shescape, published on 1 Aug 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31180 exists.

Affected packages and fixed versions:
- shescape (npm): affected from 1.4.0; fixed in 1.5.8
- shescape (npm): affected from 1.4.0; fixed in 1.5.8

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-31180/ (Markdown: https://insights.sbomify.com/CVE-2022-31180/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-31180
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-31180
- OSV: https://osv.dev/vulnerability/CVE-2022-31180

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-31180/
Summaries are generated and may contain mistakes; the official description above is the record.
