CVE-2025-27516: Jinja2 Jinja2 Vulnerable To Sandbox Breakout Vulnerability

MODERATE
Advisory Identifier: GHSA-cpwx-vrp4-4pq7
CWE-1336
Published
Advisory Summary

CVE-2025-27516 is a MODERATE jinja2 vulnerable to sandbox breakout vulnerability (CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine) affecting Jinja2 libraries in the PyPI ecosystem. The issue involves jinja2 vulnerable to sandbox breakout through attr filter selecting format method. Remediation is available by upgrading affected packages to version 3.1.6.

CVE-2025-27516 at a Glance

CVE Identifier CVE-2025-27516
GHSA Identifier GHSA-cpwx-vrp4-4pq7
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine
Affected Product Jinja2
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2025-27516

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.6
pip install Jinja2>=3.1.6
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-2025-27516, 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.6), 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-1336: Improper Neutralization of Special Elements Used in a Template Engine, where the product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine. 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 interacts with the `|attr` filter 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 use the `|attr` filter to get a reference to a string's plain format method, bypassing the sandbox. After the fix, the `|attr` filter no longer bypasses the environment's attribute lookup.

CVE-2025-27516 Affected Jinja2 Versions

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

References

Frequently Asked Questions

What is CVE-2025-27516?
CVE-2025-27516 is a security vulnerability in Jinja2 involving Jinja2 vulnerable to sandbox breakout through attr filter selecting format method under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine.
Which Jinja2 versions are affected?
Affected versions include releases prior to 3.1.6 across affected packages: Jinja2.
What version fixes CVE-2025-27516?
Upgrading to 3.1.6 (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.6. Upgrade your dependency to 3.1.6 or later.
What CWE is associated with CVE-2025-27516?
CVE-2025-27516 is classified under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine (The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine.).
How can I check PyPI dependencies for CVE-2025-27516?
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-cpwx-vrp4-4pq7",
  "modified" : "2025-11-03T22:54:41Z",
  "published" : "2025-03-05T20:40:14Z",
  "aliases" : [ "CVE-2025-27516" ],
  "summary" : "Jinja2 vulnerable to sandbox breakout through attr filter selecting format method",
  "details" : "An oversight in how the Jinja sandboxed environment interacts with the `|attr` filter 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 use the `|attr` filter to get a reference to a string's plain format method, bypassing the sandbox. After the fix, the `|attr` filter no longer bypasses the environment's attribute lookup.",
  "severity" : [ {
    "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.6"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.1.5"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/security/advisories/GHSA-cpwx-vrp4-4pq7"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-27516"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/commit/90457bbf33b8662926ae65cdde4c4c32e756e403"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pallets/jinja"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2025/04/msg00022.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2025/04/msg00045.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-03-05T20:40:14Z",
    "nvd_published_at" : "2025-03-05T21:15:20Z"
  }
}