Jinja2 vulnerable to sandbox breakout through attr filter selecting format method
Published 5 Mar 2025 · Updated 18 Nov 2026
Is your project on an affected jinja2?
Look after several Python apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <3.1.6
- Fixed in
- 3.1.6
pip install 'jinja2>=3.1.6'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.
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.
Is GHSA-cpwx-vrp4-4pq7 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected jinja2, and gives you the command that fixes it.
More advisories for jinja2
- MediumCVE-2024-56326Jinja has a sandbox breakout through indirect reference to format method · 23 Dec 2024
- MediumCVE-2024-56201Jinja has a sandbox breakout through malicious filenames · 23 Dec 2024
- MediumCVE-2024-34064Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter · 6 May 2024
- MediumCVE-2024-22195Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter · 11 Jan 2024
- MediumCVE-2014-0012Insecure Temporary File in Jinja2 · 17 May 2022
- HighCVE-2014-1402Incorrect Privilege Assignment in Jinja2 · 14 May 2022
References
- Linkgithub.com/pallets/jinja/security/advisories/GHSA-cpwx-vrp4-4pq7
- Advisorynvd.nist.gov/vuln/detail/CVE-2025-27516
- Linkgithub.com/pallets/jinja/commit/90457bbf33b8662926ae65cdde4c4c32e756e403
- Packagegithub.com/pallets/jinja
- Linkgithub.com/pallets/jinja/releases/tag/3.1.6
- Linkgithub.com/pypa/advisory-database/tree/main/vulns/jinja2/PYSEC-2026-1471.yaml
- Linklists.debian.org/debian-lts-announce/2025/04/msg00022.html
- Linklists.debian.org/debian-lts-announce/2025/04/msg00045.html
- Linkpypi.org/project/jinja2
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.