# CVE-2021-21316: Arbitrary code execution in less-openui5

> Attackers can execute arbitrary code during the build process by providing malicious Less files to the less-openui5 library.

- **Severity:** Medium 6.3 (`CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 16 Feb 2021
- **Updated:** 3 Aug 2024
- **Also known as:** GHSA-3crj-w4f5-gwh4

## What is CVE-2021-21316?

CVE-2021-21316 is a medium-severity code injection vulnerability in SAP less-openui5, published on 16 Feb 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

less-openui5 is an npm package which enables building OpenUI5 themes with Less.js. In less-openui5 before version 0.10., when processing theming resources (i.e. `*.less` files) with less-openui5 that originate from an untrusted source, those resources might contain JavaScript code which will be executed in the context of the build process. While this is a feature of the Less.js library it is an unexpected behavior in the context of OpenUI5 and SAPUI5 development. Especially in the context of UI5 Tooling which relies on less-openui5. An attacker might create a library or theme-library containing a custom control or theme, hiding malicious JavaScript code in one of the .less files. Refer to the referenced GHSA-3crj-w4f5-gwh4 for examples. Starting with Less.js version 3.0.0, the Inline JavaScript feature is disabled by default. less-openui5 however currently uses a fork of Less.js v1.6.3. Note that disabling the Inline JavaScript feature in Less.js versions 1.x, still evaluates code has additional double codes around it. We decided to remove the inline JavaScript evaluation feature completely from the code of our Less.js fork. This fix is available in less-openui5 version 0.10.0.

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

## Which versions are affected by CVE-2021-21316?

2 open source packages ship an affected version, including less-openui5. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `less-openui5` | npm | All versions | 0.10.0 |
| `less-openui5` | npm | All versions | 0.10.0 |

Products: Less-Openui5 Project Less-Openui5.

## How do I fix CVE-2021-21316?

Upgrade less-openui5 to 0.10.0 or later.

## Is CVE-2021-21316 being exploited?

There is no known exploitation of CVE-2021-21316 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-21316 and fix it if it is affected.

What it is: CVE-2021-21316 is a medium-severity code injection vulnerability in SAP less-openui5, published on 16 Feb 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-21316 in the wild and no public exploit code.

Affected packages and fixed versions:
- less-openui5 (npm): affected all versions; fixed in 0.10.0
- less-openui5 (npm): affected all versions; fixed in 0.10.0

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-2021-21316/ (Markdown: https://insights.sbomify.com/CVE-2021-21316/index.md)
```

## Sources

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

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