# CVE-2016-10745: Jinja2 sandbox escape vulnerability

> Attackers can execute arbitrary code by exploiting a sandbox escape in the str.format method of the Jinja templating library.

- **Severity:** High 8.6 (`CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Apr 2019
- **Updated:** 6 Aug 2024
- **Also known as:** DEBIAN-CVE-2016-10745, GHSA-hj2j-77xm-mc5v, PYSEC-2019-220, RHSA-2019:1022, RHSA-2019:3964, RHSA-2019:4062, SUSE-SU-2019:1323-1, UBUNTU-CVE-2016-10745

## What is CVE-2016-10745?

CVE-2016-10745 is a high-severity code injection vulnerability in n/a, published on 8 Apr 2019. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

In Pallets Jinja before 2.8.1, str.format allows a sandbox escape.

Weakness: CWE-134 (Use of Externally-Controlled Format String)

## Which versions are affected by CVE-2016-10745?

3 open source packages ship an affected version, including jinja2 and Jinja2. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `jinja2` | PyPI | All versions | 2.8.1 |
| `jinja2` | PyPI | All versions | 2.8.1 |
| `Jinja2` | PyPI | All versions | 2.8.1 |
| `python-jinja2` | Red Hat:enterprise_linux:7::client | All versions | 0:2.7.2-3.el7_6 |
| `python-jinja2` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.7.2-3.el7_6 |
| `python-jinja2` | Red Hat:enterprise_linux:7::server | All versions | 0:2.7.2-3.el7_6 |
| `python-jinja2` | Red Hat:enterprise_linux:7::workstation | All versions | 0:2.7.2-3.el7_6 |
| `python-jinja2` | Red Hat:rhel_aus:7.4::server | All versions | 0:2.7.2-3.el7_4 |
| `python-jinja2` | Red Hat:rhel_e4s:7.4::server | All versions | 0:2.7.2-3.el7_4 |
| `python-jinja2` | Red Hat:rhel_eus:7.5::computenode | All versions | 0:2.7.2-3.el7_5 |
| `python-jinja2` | Red Hat:rhel_eus:7.5::server | All versions | 0:2.7.2-3.el7_5 |
| `python-jinja2` | Red Hat:rhel_tus:7.4::server | All versions | 0:2.7.2-3.el7_4 |
| `python-Jinja2` | SUSE:Linux Enterprise Module for Advanced Systems Management 12 | All versions | 2.8-19.17.1 |
| `python-Jinja2` | SUSE:Linux Enterprise Module for Public Cloud 12 | All versions | 2.8-19.17.1 |
| `python-Jinja2` | SUSE:Manager Client Tools 12 | All versions | 2.8-19.17.1 |

Products: Palletsprojects Jinja.

## How do I fix CVE-2016-10745?

Upgrade jinja2 to 2.8.1 or later.

## Is CVE-2016-10745 being exploited?

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

## Other vulnerabilities in n/a

- [CVE-2024-56201](https://insights.sbomify.com/CVE-2024-56201/): Jinja has a sandbox breakout through malicious filenames (medium 5.4)
- [CVE-2024-56326](https://insights.sbomify.com/CVE-2024-56326/): Jinja has a sandbox breakout through indirect reference to format method (medium 5.4)
- [CVE-2024-22195](https://insights.sbomify.com/CVE-2024-22195/): Jinja vulnerable to Cross-Site Scripting (XSS) (medium 5.4)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2016-10745 and fix it if it is affected.

What it is: CVE-2016-10745 is a high-severity code injection vulnerability in n/a, published on 8 Apr 2019. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2016-10745 in the wild and no public exploit code.

Affected packages and fixed versions:
- jinja2 (PyPI): affected all versions; fixed in 2.8.1
- jinja2 (PyPI): affected all versions; fixed in 2.8.1
- Jinja2 (PyPI): affected all versions; fixed in 2.8.1

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

## Sources

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

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