CVE-2024-56326 Jinja has a sandbox breakout through indirect reference to format method

Medium 5.4 Published Updated

Attackers controlling template content can execute arbitrary Python code via sandbox bypass if custom filters are present.

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-2024-56326?

CVE-2024-56326 is a medium-severity code injection vulnerability in pallets jinja, published on 23 Dec 2024. 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.5, An oversight in how the Jinja sandboxed environment detects calls to str.format 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 store a reference to a malicious string's format method, then pass that to a filter that calls it. No such filters are built-in to Jinja, but could be present through custom filters in an application. After the fix, such indirect calls are also handled by the sandbox. This vulnerability is fixed in 3.1.5.

Weakness: CWE-693, CWE-1336

Which versions are affected by CVE-2024-56326?

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

PackageAffectedFixed in
jinja2 PyPIAll versions3.1.5
jinja2 PyPIAll versions3.1.5
jinja2 PyPIAll versions3.1.5
Linux distribution packages (37)
python3-jinja2 AlmaLinux:8All versions2.10.1-6.el8_10
python3-jinja2 AlmaLinux:9All versions2.11.3-7.el9_5
python-jinja2 Red Hat:enterprise_linux:8::appstreamAll versions0:2.10.1-6.el8_10
python3-jinja2 Red Hat:enterprise_linux:8::appstreamAll versions0:2.10.1-6.el8_10
python-jinja2 Red Hat:enterprise_linux:9::appstreamAll versions0:2.11.3-7.el9_5
python3-jinja2 Red Hat:enterprise_linux:9::appstreamAll versions0:2.11.3-7.el9_5
python-jinja2 Red Hat:rhel_aus:8.2::appstreamAll versions0:2.10.1-2.el8_2.3
python3-jinja2 Red Hat:rhel_aus:8.2::appstreamAll versions0:2.10.1-2.el8_2.3
python-jinja2 Red Hat:rhel_aus:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python3-jinja2 Red Hat:rhel_aus:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python-jinja2 Red Hat:rhel_aus:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python3-jinja2 Red Hat:rhel_aus:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python-jinja2 Red Hat:rhel_e4s:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python3-jinja2 Red Hat:rhel_e4s:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python-jinja2 Red Hat:rhel_e4s:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python3-jinja2 Red Hat:rhel_e4s:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python-jinja2 Red Hat:rhel_e4s:9.0::appstreamAll versions0:2.11.3-4.el9_0.1
python3-jinja2 Red Hat:rhel_e4s:9.0::appstreamAll versions0:2.11.3-4.el9_0.1
python-jinja2 Red Hat:rhel_els:7All versions0:2.7.2-5.el7_9
python-jinja2 Red Hat:rhel_eus:8.8::appstreamAll versions0:2.10.1-4.el8_8.1
python3-jinja2 Red Hat:rhel_eus:8.8::appstreamAll versions0:2.10.1-4.el8_8.1
python-jinja2 Red Hat:rhel_eus:9.2::appstreamAll versions0:2.11.3-4.el9_2.1
python3-jinja2 Red Hat:rhel_eus:9.2::appstreamAll versions0:2.11.3-4.el9_2.1
python-jinja2 Red Hat:rhel_eus:9.4::appstreamAll versions0:2.11.3-6.el9_4
python3-jinja2 Red Hat:rhel_eus:9.4::appstreamAll versions0:2.11.3-6.el9_4
python-jinja2 Red Hat:rhel_tus:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python3-jinja2 Red Hat:rhel_tus:8.4::appstreamAll versions0:2.10.1-2.el8_4.1
python-jinja2 Red Hat:rhel_tus:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python3-jinja2 Red Hat:rhel_tus:8.6::appstreamAll versions0:2.10.1-4.el8_6.1
python-jinja2 Rocky Linux:8All versions0:2.10.1-6.el8_10
python-jinja2 Rocky Linux:9All versions0:2.11.3-7.el9_5
python-Jinja2 SUSE:Enterprise Storage 7.1All versions2.10.1-150000.3.18.1
python-Jinja2 SUSE:Linux Enterprise High Performance Computing 15 SP3-LTSSAll versions2.10.1-150000.3.18.1
python-Jinja2 SUSE:Linux Enterprise High Performance Computing 15 SP4-ESPOSAll versions2.10.1-150000.3.18.1
python-Jinja2 SUSE:Linux Enterprise High Performance Computing 15 SP4-LTSSAll versions2.10.1-150000.3.18.1
python-Jinja2 SUSE:Linux Enterprise High Performance Computing 15 SP5-ESPOSAll versions2.10.1-150000.3.18.1
python-Jinja2 SUSE:Linux Enterprise High Performance Computing 15 SP5-LTSSAll versions2.10.1-150000.3.18.1

Products include Palletsprojects Jinja.

How do I fix CVE-2024-56326?

Upgrade jinja2 to 3.1.5 or later.

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

Is CVE-2024-56326 being exploited?

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

Sources

Also known as ALPINE-CVE-2024-56326, ALSA-2025:0667, ALSA-2025:0711, AZL-54647, AZL-54654, BELL-CVE-2024-56326 and 29 more.

Is CVE-2024-56326 in your software?

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

Check your SBOMs for free