CVE-2025-27516: Jinja2 Jinja2 Vulnerable To Sandbox Breakout Vulnerability
MODERATECVE-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
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.
pip install Jinja2>=3.1.6
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
CVE-2025-27516 Affected Jinja2 Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
Jinja2
|
PyPI |
< 3.1.6
|
3.1.6
|
References
Frequently Asked Questions
What is CVE-2025-27516?
Which Jinja2 versions are affected?
What version fixes CVE-2025-27516?
Is Jinja2 affected?
What CWE is associated with CVE-2025-27516?
How can I check PyPI dependencies for CVE-2025-27516?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}