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

Medium 5.4 Published Updated

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

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

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

Which versions are affected by CVE-2025-27516?

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

PackageAffectedFixed in
jinja2 PyPIAll versions3.1.6
jinja2 PyPIAll versions3.1.6
Jinja2 PyPIAll versions3.1.6
Linux distribution packages (37)
python3-jinja2 AlmaLinux:10All versions3.1.6-1.el10_0
python3-jinja2+i18n AlmaLinux:10All versions3.1.6-1.el10_0
python3-jinja2 AlmaLinux:8All versions2.10.1-7.el8_10
python3-jinja2 AlmaLinux:9All versions2.11.3-8.el9_5
automation-controller-venv-tower Red Hat:ansible_automation_platform:2.4::el8All versions0:4.5.20-1.el8ap
python39-jinja2 Red Hat:ansible_automation_platform:2.4::el8All versions0:3.1.6-1.el8ap
python3x-jinja2 Red Hat:ansible_automation_platform:2.4::el8All versions0:3.1.6-1.el8ap
automation-controller-venv-tower Red Hat:ansible_automation_platform:2.4::el9All versions0:4.5.20-1.el9ap
python-jinja2 Red Hat:ansible_automation_platform:2.4::el9All versions0:3.1.6-1.el9ap
python3-jinja2 Red Hat:ansible_automation_platform:2.4::el9All versions0:3.1.6-1.el9ap
python39-jinja2 Red Hat:ansible_automation_platform_developer:2.4::el8All versions0:3.1.6-1.el8ap
python3x-jinja2 Red Hat:ansible_automation_platform_developer:2.4::el8All versions0:3.1.6-1.el8ap
python-jinja2 Red Hat:ansible_automation_platform_developer:2.4::el9All versions0:3.1.6-1.el9ap
python3-jinja2 Red Hat:ansible_automation_platform_developer:2.4::el9All versions0:3.1.6-1.el9ap
python39-jinja2 Red Hat:ansible_automation_platform_inside:2.4::el8All versions0:3.1.6-1.el8ap
python3x-jinja2 Red Hat:ansible_automation_platform_inside:2.4::el8All versions0:3.1.6-1.el8ap
python-jinja2 Red Hat:ansible_automation_platform_inside:2.4::el9All versions0:3.1.6-1.el9ap
python3-jinja2 Red Hat:ansible_automation_platform_inside:2.4::el9All versions0:3.1.6-1.el9ap
python-jinja2 Red Hat:enterprise_linux:10.0All versions0:3.1.6-1.el10_0
python3-jinja2 Red Hat:enterprise_linux:10.0All versions0:3.1.6-1.el10_0
python3-jinja2+i18n Red Hat:enterprise_linux:10.0All versions0:3.1.6-1.el10_0
python-jinja2 Red Hat:enterprise_linux:8::appstreamAll versions0:2.10.1-7.el8_10
python3-jinja2 Red Hat:enterprise_linux:8::appstreamAll versions0:2.10.1-7.el8_10
fence-agents Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-common Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-compute Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-debuginfo Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-debugsource Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-ibm-powervs Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-ibm-vpc Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-kdump-debuginfo Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-kubevirt Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-kubevirt-debuginfo Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-agents-virsh Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-virt Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-virt-debuginfo Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6
fence-virtd Red Hat:enterprise_linux:9::appstreamAll versions0:4.10.0-76.el9_5.6

Products include Debian Debian Linux, Palletsprojects Jinja.

How do I fix CVE-2025-27516?

Upgrade jinja2 to 3.1.6 or later.

Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.

Is CVE-2025-27516 being exploited?

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

All Debian Debian Linux vulnerabilities

Sources

Also known as ALPINE-CVE-2025-27516, ALSA-2025:3388, ALSA-2025:3406, ALSA-2025:7476, AZL-57800, AZL-57878 and 46 more.

Is CVE-2025-27516 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free