CVE-2024-56326: Jinja has a sandbox breakout through indirect reference to format method
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 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.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/jinja2to a version that resolves this vulnerability.Fixed in 3.1.5 - Upgrade
Upgrade
debian/jinja2to a version that resolves this vulnerability.Fixed in 2.11.3-1+deb11u4Fixed in 3.1.2-1+deb12u2Fixed in 3.1.6-1 - Upgrade
Upgrade
jinjato a version that resolves this vulnerability.Fixed in 3.1.5
Event History
Frequently Asked Questions
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.
How do I fix CVE-2024-56326?
To fix CVE-2024-56326, upgrade to Jinja2 version 3.1.5 or later.
Who is affected by CVE-2024-56326?
CVE-2024-56326 affects Jinja2 versions up to and including 3.1.4.
What type of attack does CVE-2024-56326 enable?
CVE-2024-56326 enables attackers to execute arbitrary Python code through a compromised template.
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.