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

Published Dec 23, 2024
·
Updated

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.

Other sources

Jinja has a sandbox breakout through indirect reference to format method

— Microsoft

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.

— IBM

Affected Software

25 affected componentsFixes available
pip/jinja2<=3.1.4
3.1.5
IBM Concert Software<=1.0.0-1.1.0
palletsprojects Jinja<3.1.5
debian/jinja2<3.1.2-1+deb12u2
3.1.2-1+deb12u2
debian/jinja2<3.1.5-1
3.1.5-1
debian/jinja2<3.1.5-1
3.1.5-1
debian/jinja2
3.1.2-1+deb12u33.1.6-13.1.6-4
ubuntu/jinja2<2.7.2-2ubuntu0.1~esm6
2.7.2-2ubuntu0.1~esm6
ubuntu/jinja2<2.8-1ubuntu0.1+esm5
2.8-1ubuntu0.1+esm5
ubuntu/jinja2<2.10-1ubuntu0.18.04.1+esm3
2.10-1ubuntu0.18.04.1+esm3
ubuntu/jinja2<2.10.1-2ubuntu0.4
2.10.1-2ubuntu0.4
ubuntu/jinja2<3.0.3-1ubuntu0.3
3.0.3-1ubuntu0.3
ubuntu/jinja2<3.1.2-1ubuntu1.2
3.1.2-1ubuntu1.2
All of the following
azurelinux/python-jinja2<3.0.3-5
3.0.3-5
Microsoft CBL-Mariner=2.0
All of the following
azurelinux/python-jinja2<3.1.2-2
3.1.2-2
Microsoft Azure Linux=3.0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0
alpine/py3-jinja2<3.1.5-r0
3.1.5-r0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.5
  2. Upgrade

    Upgrade alpine/py3-jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.5-r0
  3. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-1+deb12u2
  4. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.5-1
  5. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-1+deb12u3Fixed in 3.1.6-1Fixed in 3.1.6-4
  6. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.7.2-2ubuntu0.1~esm6
  7. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.8-1ubuntu0.1+esm5
  8. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.10-1ubuntu0.18.04.1+esm3
  9. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.10.1-2ubuntu0.4
  10. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.0.3-1ubuntu0.3
  11. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-1ubuntu1.2
  12. Upgrade

    Upgrade azurelinux/python-jinja2 to a version that resolves this vulnerability.

    Fixed in 3.0.3-5
  13. Upgrade

    Upgrade azurelinux/python-jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-2
  14. Upgrade

    Upgrade jinja to a version that resolves this vulnerability.

    Fixed in 3.1.5

Event History

Dec 23, 2024
CVE Published
via MITRE·03:43 PM
Data Sourced
via MITRE·03:43 PM
DescriptionWeakness
Data Sourced
via Red Hat·04:01 PM
DescriptionSeverityAffected Software
Data Sourced
via OSV·04:15 PM
DescriptionSeverityAffected Software
Data Sourced
via NVD·04:15 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·05:56 PM
Data Sourced
via GitHub·05:56 PM
DescriptionAffected Software
Advisory Published
via GitHub·05:56 PM
Data Sourced
via GitHub·08:55 PM
Weakness
Dec 24, 2024
Updated
via NVD·02:15 AM
Severity
Dec 26, 2024
Data Sourced
via GitHub·08:09 PM
Severity
Dec 27, 2024
Updated
via NVD·06:15 PM
Severity
Event
via NVD·06:15 PM
Updated
via GitHub·07:10 PM
Severity
Jan 15, 2025
Data Sourced
via Microsoft·08:00 AM
DescriptionSeverityWeakness
Data Sourced
via Microsoft·08:00 AM
Affected Software
Jan 31, 2025
Updated
via Red Hat·04:21 PM
Severity
May 6, 2025
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software
Aug 17, 2025
Updated
via IBM·12:00 AM
Affected Software
Sep 22, 2025
Data Sourced
via NVD·05:41 PM
RemedyAffected Software
Dec 3, 2026
Updated
via OSV·11:32 PM
Affected Software

Parent advisories

This vulnerability appears in the following advisories.

Peer vulnerabilities

Found alongside the following vulnerabilities.

Frequently Asked Questions

1

What is the severity of CVE-2024-56326?

CVE-2024-56326 is classified as a high severity vulnerability due to its potential for arbitrary code execution.

2

How do I fix CVE-2024-56326?

To fix CVE-2024-56326, upgrade to Jinja2 version 3.1.5 or later.

3

Who is affected by CVE-2024-56326?

CVE-2024-56326 affects Jinja2 versions up to and including 3.1.4.

4

What type of attack does CVE-2024-56326 enable?

CVE-2024-56326 enables attackers to execute arbitrary Python code through a compromised template.

5

Is there a workaround for CVE-2024-56326?

There are no officially recommended workarounds for CVE-2024-56326; the best action is to update to the latest version.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203