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

MODERATE
Advisory Identifier: GHSA-gmj6-6f8f-6699
CVSS 8.8
CWE-150
Published
Advisory Summary

CVE-2024-56201 is a MODERATE (CVSS 8.8) jinja has a sandbox breakout vulnerability (CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences) affecting Jinja2 libraries in the PyPI ecosystem. The issue involves jinja has a sandbox breakout through malicious filenames. Remediation is available by upgrading affected packages to version 3.1.5.

CVE-2024-56201 at a Glance

CVE Identifier CVE-2024-56201
GHSA Identifier GHSA-gmj6-6f8f-6699
Severity MODERATE
CVSS v3.1 Base Score 8.8
CWE Classification CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences
Affected Product Jinja2
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.8

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

Attack Vector Network (AV:N)
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-56201

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-56201, 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-150: Improper Neutralization of Escape, Meta, or Control Sequences, where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component. 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

A bug in the Jinja compiler allows an attacker that controls both the content and filename of a template to execute arbitrary Python code, regardless of if Jinja's sandbox is used. To exploit the vulnerability, an attacker needs to control both the filename and the contents 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 where the template author can also choose the template filename.

CVE-2024-56201 Affected Jinja2 Versions

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

References

Frequently Asked Questions

What is CVE-2024-56201?
CVE-2024-56201 is a security vulnerability in Jinja2 involving Jinja has a sandbox breakout through malicious filenames under CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences.
Which Jinja2 versions are affected?
Affected versions include releases prior to 3.1.5 across affected packages: jinja2.
What version fixes CVE-2024-56201?
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-56201?
CVE-2024-56201 has a CVSS v3.1 base score of 8.8 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2024-56201?
CVE-2024-56201 is classified under CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component.).
How can I check PyPI dependencies for CVE-2024-56201?
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-gmj6-6f8f-6699",
  "modified" : "2025-01-08T16:06:01Z",
  "published" : "2024-12-23T17:54:12Z",
  "aliases" : [ "CVE-2024-56201" ],
  "summary" : "Jinja has a sandbox breakout through malicious filenames",
  "details" : "A bug in the Jinja compiler allows an attacker that controls both the content and filename of a template to execute arbitrary Python code, regardless of if Jinja's sandbox is used.\n\nTo exploit the vulnerability, an attacker needs to control both the filename and the contents 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 where the template author can also choose the template filename.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/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" : "3.0.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-gmj6-6f8f-6699"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-56201"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/issues/1792"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/commit/767b23617628419ae3709ccfb02f9602ae9fe51f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pallets/jinja"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/releases/tag/3.1.5"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-150" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-12-23T17:54:12Z",
    "nvd_published_at" : "2024-12-23T16:15:07Z"
  }
}