CVE-2024-56326: Jinja2 Jinja Has A Sandbox Breakout Vulnerability

MODERATE
Advisory Identifier: GHSA-q2x7-8rv6-6q7h
CVSS 7.8
CWE-693
Published
Advisory Summary

CVE-2024-56326 is a MODERATE (CVSS 7.8) jinja has a sandbox breakout vulnerability (CWE-693: Protection Mechanism Failure) affecting Jinja2 libraries in the PyPI ecosystem. The issue involves jinja has a sandbox breakout through indirect reference to format method. Remediation is available by upgrading affected packages to version 3.1.5.

CVE-2024-56326 at a Glance

CVE Identifier CVE-2024-56326
GHSA Identifier GHSA-q2x7-8rv6-6q7h
Severity MODERATE
CVSS v3.1 Base Score 7.8
CWE Classification CWE-693: Protection Mechanism Failure
Affected Product Jinja2
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-56326

To remediate this vulnerability, upgrade all affected Jinja2 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

jinja2 fixed: 3.1.5
pip install jinja2>=3.1.5
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show jinja2

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-56326, inspect your installed packages using pip:

pip show jinja2

Analyze the terminal output to locate any version of Jinja2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.1.5), your application is affected.

Note: The pip show jinja2 command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-693: Protection Mechanism Failure, where the product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product. In Jinja2, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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.

CVE-2024-56326 Affected Jinja2 Versions

1 component(s)
Fixed Versions:
3.1.5
Product / Package Ecosystem Affected Versions Fixed Version
jinja2
PyPI
< 3.1.5
3.1.5

References

Frequently Asked Questions

What is CVE-2024-56326?
CVE-2024-56326 is a security vulnerability in Jinja2 involving Jinja has a sandbox breakout through indirect reference to format method under CWE-693: Protection Mechanism Failure.
Which Jinja2 versions are affected?
Affected versions include releases prior to 3.1.5 across affected packages: jinja2.
What version fixes CVE-2024-56326?
Upgrading to 3.1.5 (or the latest patched release for your respective branch) resolves the vulnerability.
Is jinja2 affected?
Yes, jinja2 is affected in releases prior to 3.1.5. Upgrade your dependency to 3.1.5 or later.
What is the CVSS score of CVE-2024-56326?
CVE-2024-56326 has a CVSS v3.1 base score of 7.8 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-56326?
CVE-2024-56326 is classified under CWE-693: Protection Mechanism Failure (The product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product.).
How can I check PyPI dependencies for CVE-2024-56326?
Run the dependency tree command: 'pip show jinja2'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-q2x7-8rv6-6q7h",
  "modified" : "2025-11-03T22:50:50Z",
  "published" : "2024-12-23T17:56:08Z",
  "aliases" : [ "CVE-2024-56326" ],
  "summary" : "Jinja has a sandbox breakout through indirect reference to format method",
  "details" : "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.\n\nTo 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.\n\nJinja'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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "jinja2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.1.5"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.1.4"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/security/advisories/GHSA-q2x7-8rv6-6q7h"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-56326"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/commit/48b0687e05a5466a91cd5812d604fa37ad0943b4"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pallets/jinja"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/releases/tag/3.1.5"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2025/04/msg00022.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-693" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-12-23T17:56:08Z",
    "nvd_published_at" : "2024-12-23T16:15:07Z"
  }
}