# CVE-2025-27516: Jinja sandbox breakout through attr filter selecting format method

> Attackers controlling template content can execute arbitrary Python code by bypassing the Jinja sandbox via the attr filter.

- **Severity:** Medium 5.4 (`CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 5 Mar 2025
- **Updated:** 26 Feb 2026
- **Also known as:** ALPINE-CVE-2025-27516, ALSA-2025:3388, ALSA-2025:3406, ALSA-2025:7476, AZL-57800, AZL-57878, AZL-58063, AZL-58067, AZL-75804, BELL-CVE-2025-27516, CLEANSTART-2026-DG23203, CLEANSTART-2026-RA96776, CLSA-2026-1790708389, CLSA-2026-1790708982, DEBIAN-CVE-2025-27516, ECHO-d102-c54d-3424, GHSA-cpwx-vrp4-4pq7, MGASA-2025-0094, MINI-3jgv-65v6-p6xm, MINI-4c5h-cmcm-mv5q, OESA-2025-1529, OESA-2025-1530, OESA-2025-1531, OESA-2025-1532, PYSEC-2026-1471, RHSA-2025:2688, RHSA-2025:3017, RHSA-2025:3111, RHSA-2025:3113, RHSA-2025:3123, RHSA-2025:3371, RHSA-2025:3388, RHSA-2025:3406, RHSA-2025:3562, RHSA-2025:3580, RHSA-2025:3585, RHSA-2025:3586, RHSA-2025:3588, RHSA-2025:3622, RHSA-2025:3671, RHSA-2025:7476, RHSA-2026:43940, RLSA-2025:3113, RLSA-2025:3388, RLSA-2025:3406, RLSA-2025:7476, ROOT-APP-PYPI-CVE-2025-27516, SUSE-SU-2025:0956-1, SUSE-SU-2025:1004-1, SUSE-SU-2025:1004-2, SUSE-SU-2025:20156-1, UBUNTU-CVE-2025-27516

## What is CVE-2025-27516?

CVE-2025-27516 is a medium-severity code injection vulnerability in Debian Debian Linux, published on 5 Mar 2025. 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

Jinja is an extensible templating engine. Prior to 3.1.6, an oversight in how the Jinja sandboxed environment interacts with the |attr filter allows an attacker that controls the content of a template to execute arbitrary Python code. To exploit the vulnerability, an attacker needs to control the content of a template. Whether that is the case depends on the type of application using Jinja. This vulnerability impacts users of applications which execute untrusted templates. Jinja's sandbox does catch calls to str.format and ensures they don't escape the sandbox. However, it's possible to use the |attr filter to get a reference to a string's plain format method, bypassing the sandbox. After the fix, the |attr filter no longer bypasses the environment's attribute lookup. This vulnerability is fixed in 3.1.6.

Weakness: CWE-1336 (Improper Neutralization of Special Elements Used in a Template Engine)

## Which versions are affected by CVE-2025-27516?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `jinja2` | PyPI | All versions | 3.1.6 |
| `jinja2` | PyPI | All versions | 3.1.6 |
| `Jinja2` | PyPI | All versions | 3.1.6 |
| `python3-jinja2` | AlmaLinux:10 | All versions | 3.1.6-1.el10_0 |
| `python3-jinja2+i18n` | AlmaLinux:10 | All versions | 3.1.6-1.el10_0 |
| `python3-jinja2` | AlmaLinux:8 | All versions | 2.10.1-7.el8_10 |
| `python3-jinja2` | AlmaLinux:9 | All versions | 2.11.3-8.el9_5 |
| `automation-controller-venv-tower` | Red Hat:ansible_automation_platform:2.4::el8 | All versions | 0:4.5.20-1.el8ap |
| `python39-jinja2` | Red Hat:ansible_automation_platform:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `python3x-jinja2` | Red Hat:ansible_automation_platform:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `automation-controller-venv-tower` | Red Hat:ansible_automation_platform:2.4::el9 | All versions | 0:4.5.20-1.el9ap |
| `python-jinja2` | Red Hat:ansible_automation_platform:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python3-jinja2` | Red Hat:ansible_automation_platform:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python39-jinja2` | Red Hat:ansible_automation_platform_developer:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `python3x-jinja2` | Red Hat:ansible_automation_platform_developer:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `python-jinja2` | Red Hat:ansible_automation_platform_developer:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python3-jinja2` | Red Hat:ansible_automation_platform_developer:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python39-jinja2` | Red Hat:ansible_automation_platform_inside:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `python3x-jinja2` | Red Hat:ansible_automation_platform_inside:2.4::el8 | All versions | 0:3.1.6-1.el8ap |
| `python-jinja2` | Red Hat:ansible_automation_platform_inside:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python3-jinja2` | Red Hat:ansible_automation_platform_inside:2.4::el9 | All versions | 0:3.1.6-1.el9ap |
| `python-jinja2` | Red Hat:enterprise_linux:10.0 | All versions | 0:3.1.6-1.el10_0 |
| `python3-jinja2` | Red Hat:enterprise_linux:10.0 | All versions | 0:3.1.6-1.el10_0 |
| `python3-jinja2+i18n` | Red Hat:enterprise_linux:10.0 | All versions | 0:3.1.6-1.el10_0 |
| `python-jinja2` | Red Hat:enterprise_linux:8::appstream | All versions | 0:2.10.1-7.el8_10 |
| `python3-jinja2` | Red Hat:enterprise_linux:8::appstream | All versions | 0:2.10.1-7.el8_10 |
| `fence-agents` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-common` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-compute` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-debugsource` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-ibm-powervs` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-ibm-vpc` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-kdump-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-kubevirt` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-kubevirt-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-agents-virsh` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-virt` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-virt-debuginfo` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |
| `fence-virtd` | Red Hat:enterprise_linux:9::appstream | All versions | 0:4.10.0-76.el9_5.6 |

Products: Debian Debian Linux, Palletsprojects Jinja.

## How do I fix CVE-2025-27516?

Upgrade jinja2 to 3.1.6 or later.

## Is CVE-2025-27516 being exploited?

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

## Other vulnerabilities in Debian Debian Linux

- [CVE-2015-3306](https://insights.sbomify.com/CVE-2015-3306/): ProFTPD Improper Access Control (critical 10.0, exploited in the wild)
- [CVE-2025-49113](https://insights.sbomify.com/CVE-2025-49113/): RoundCube Webmail Deserialization of Untrusted Data (critical 9.9, exploited in the wild)
- [CVE-2026-24061](https://insights.sbomify.com/CVE-2026-24061/): GNU InetUtils Argument Injection (critical 9.8, exploited in the wild)
- [CVE-2025-39682](https://insights.sbomify.com/CVE-2025-39682/): Linux Kernel Improper Check for Unusual or Exceptional Conditions (critical 9.8, exploited in the wild)
- [CVE-2024-9680](https://insights.sbomify.com/CVE-2024-9680/): Mozilla Firefox Use-After-Free (critical 9.8, exploited in the wild)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-27516 and fix it if it is affected.

What it is: CVE-2025-27516 is a medium-severity code injection vulnerability in Debian Debian Linux, published on 5 Mar 2025. 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-2025-27516 in the wild and no public exploit code.

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

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

## Sources

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

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