Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter
Published 6 May 2024 · Updated 10 Sept 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.4
- Fixed in
- 3.1.4
pip install 'jinja2>=3.1.4'Details
The xmlattr filter in affected versions of Jinja accepts keys containing non-attribute characters. XML/HTML attributes cannot contain spaces, /, >, or =, as each would then be interpreted as starting a separate attribute. If an application accepts keys (as opposed to only values) as user input, and renders these in pages that other users see as well, an attacker could use this to inject other attributes and perform XSS. The fix for the previous GHSA-h5c8-rqwp-cp95 CVE-2024-22195 only addressed spaces but not other characters.
Accepting keys as user input is now explicitly considered an unintended use case of the xmlattr filter, and code that does so without otherwise validating the input should be flagged as insecure, regardless of Jinja version. Accepting _values_ as user input continues to be safe.
Is GHSA-h75v-3vvj-5mfj 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-2025-27516Jinja2 vulnerable to sandbox breakout through attr filter selecting format method · 5 Mar 2025
- 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-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-h75v-3vvj-5mfj
- Advisorynvd.nist.gov/vuln/detail/CVE-2024-34064
- Linkgithub.com/pallets/jinja/commit/0668239dc6b44ef38e7a6c9f91f312fd4ca581cb
- Packagegithub.com/pallets/jinja
- Linklists.debian.org/debian-lts-announce/2024/12/msg00009.html
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/567XIGSZMABG6TSMYWD7MIYNJSUQQRUC
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/GCLF44KY43BSVMTE6S53B4V5WP3FRRSE
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SSCBHIL6BYKR5NRCBXP4XMP2CEEKGFVS
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/ZALNWE3TXPPHVPSI3AZ5CTMSTAVN5UMS
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.