Vulnerability · Published Mar 5, 2025 · Assigned by GitHub_M
CVE-2025-27516Jinja sandbox breakout through attr filter selecting format method
Medium 5.4
In plain English
A medium-severity security flaw in jinja from pallets. There are no confirmed reports of exploitation so far. The chance it is exploited in the next 30 days is estimated at 0.5% (higher than 43% of all known vulnerabilities). Fixed versions are available - upgrade the affected package.
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.
Affected packages & fixed versions
| Ecosystem | Package | Fixed in | Advisory |
|---|---|---|---|
| AlmaLinux:10 | python3-jinja2 | 3.1.6-1.el10_0 | ALSA-2025:7476 |
| AlmaLinux:8 | python3-jinja2 | 2.10.1-7.el8_10 | ALSA-2025:3388 |
| AlmaLinux:9 | python3-jinja2 | 2.11.3-8.el9_5 | ALSA-2025:3406 |
| AlmaLinux:10 | python3-jinja2+i18n | 3.1.6-1.el10_0 | ALSA-2025:7476 |
| Alpine:v3.20 | py3-jinja2 | 3.1.6-r0 | ALPINE-CVE-2025-27516 |
| Alpine:v3.21 | py3-jinja2 | 3.1.6-r0 | ALPINE-CVE-2025-27516 |
| Alpine:v3.22 | py3-jinja2 | 3.1.6-r0 | ALPINE-CVE-2025-27516 |
| Alpine:v3.23 | py3-jinja2 | 3.1.6-r0 | ALPINE-CVE-2025-27516 |
| Alpine:v3.24 | py3-jinja2 | 3.1.6-r0 | ALPINE-CVE-2025-27516 |
| Debian:12 | jinja2 | 3.1.2-1+deb12u3 | DEBIAN-CVE-2025-27516 |
| Debian:13 | jinja2 | 3.1.6-1 | DEBIAN-CVE-2025-27516 |
| Debian:14 | jinja2 | 3.1.6-1 | DEBIAN-CVE-2025-27516 |
| PyPI | jinja2 | 3.1.6 | PYSEC-2026-1471 |
| PyPI | jinja2 | 3.1.6 | GHSA-cpwx-vrp4-4pq7 |
| Rocky Linux:9 | fence-agents | 0:4.10.0-76.el9_5.6 | RLSA-2025:3113 |
| Rocky Linux:10 | python-jinja2 | 0:3.1.6-1.el10_0 | RLSA-2025:7476 |
| Rocky Linux:8 | python-jinja2 | 0:2.10.1-7.el8_10 | RLSA-2025:3388 |
| Rocky Linux:9 | python-jinja2 | 0:2.11.3-8.el9_5 | RLSA-2025:3406 |
| Ubuntu:22.04:LTS | jinja2 | 3.0.3-1ubuntu0.4 | USN-7343-1 |
| Ubuntu:22.04:LTS | jinja2 | 3.0.3-1ubuntu0.4 | UBUNTU-CVE-2025-27516 |
| Ubuntu:24.04:LTS | jinja2 | 3.1.2-1ubuntu1.3 | USN-7343-1 |
| Ubuntu:24.04:LTS | jinja2 | 3.1.2-1ubuntu1.3 | UBUNTU-CVE-2025-27516 |
Affected products (as reported)
Weakness: CWE-1336 · Vector: 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
References
- https://github.com/pallets/jinja/security/advisories/GHSA-cpwx-vrp4-4pq7 x_refsource_CONFIRM
- https://github.com/pallets/jinja/commit/90457bbf33b8662926ae65cdde4c4c32e756e403 x_refsource_MISC
- https://lists.debian.org/debian-lts-announce/2025/04/msg00045.html
- https://lists.debian.org/debian-lts-announce/2025/04/msg00022.html