# CVE-2021-43837: Template injection in vault-cli

> Attackers can execute arbitrary code via Jinja2 template injection in vault-cli if they control secret values, requiring an upgrade or disabling rendering.

- **Severity:** High 8.4 (`CVSS:3.1/AV:A/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 16 Dec 2021
- **Updated:** 4 Aug 2024
- **Also known as:** GHSA-q34h-97wf-8r8j, PYSEC-2021-853

## What is CVE-2021-43837?

CVE-2021-43837 is a high-severity code injection vulnerability in peopledoc vault-cli, published on 16 Dec 2021. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

vault-cli is a configurable command-line interface tool (and python library) to interact with Hashicorp Vault. In versions before 3.0.0 vault-cli features the ability for rendering templated values. When a secret starts with the prefix `!template!`, vault-cli interprets the rest of the contents of the secret as a Jinja2 template. Jinja2 is a powerful templating engine and is not designed to safely render arbitrary templates. An attacker controlling a jinja2 template rendered on a machine can trigger arbitrary code, making this a Remote Code Execution (RCE) risk. If the content of the vault can be completely trusted, then this is not a problem. Otherwise, if your threat model includes cases where an attacker can manipulate a secret value read from the vault using vault-cli, then this vulnerability may impact you. In 3.0.0, the code related to interpreting vault templated secrets has been removed entirely. Users are advised to upgrade as soon as possible. For users unable to upgrade a workaround does exist. Using the environment variable `VAULT_CLI_RENDER=false` or the flag `--no-render` (placed between `vault-cli` and the subcommand, e.g. `vault-cli --no-render get-all`) or adding `render: false` to the vault-cli configuration yaml file disables rendering and removes the vulnerability. Using the python library, you can use: `vault_cli.get_client(render=False)` when creating your client to get a client that will not render templated secrets and thus operates securely.

Weakness: CWE-94 (Improper Control of Generation of Code), CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component)

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

3 open source packages ship an affected version, including vault-cli. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `vault-cli` | PyPI | All versions | 3.0.0 |
| `vault-cli` | PyPI | From 0.7.0 | 3.0.0 |
| `vault-cli` | PyPI | From 0.7.0 | 3.0.0 |

Products: Vault-Cli Project Vault-Cli.

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

Upgrade vault-cli to 3.0.0 or later.

## Is CVE-2021-43837 being exploited?

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

## Fix prompt for AI coding agents

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

What it is: CVE-2021-43837 is a high-severity code injection vulnerability in peopledoc vault-cli, published on 16 Dec 2021. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-43837 in the wild and no public exploit code.

Affected packages and fixed versions:
- vault-cli (PyPI): affected all versions; fixed in 3.0.0
- vault-cli (PyPI): affected from 0.7.0; fixed in 3.0.0
- vault-cli (PyPI): affected from 0.7.0; fixed in 3.0.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-43837/ (Markdown: https://insights.sbomify.com/CVE-2021-43837/index.md)
```

## Sources

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

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