CVE-2024-22195
Jinja xmlattr filter abuse XSS
- CVSS 6.1
- CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
- Configuration Issues
- Remote
Jinja is an extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. It is possible to inject arbitrary HTML attributes into the rendered HTML template, potentially leading to Cross-Site Scripting (XSS). The Jinja `xmlattr` filter can be abused to inject arbitrary HTML attribute keys and values, bypassing the auto escaping mechanism and potentially leading to XSS. It may also be possible to bypass attribute validation checks if they are blacklist-based.
- CVSS base score
- 6.1
- Published
- 2024-01-11
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Configuration Issues
- Subcategory
- Cross-Site Scripting (XSS)
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update pallets/jinja to version 3.1.3 or later
Vulnerable code sample
from jinja2 import Environment
env = Environment(autoescape=False)
template = env.from_string("""
<div {{ attributes | xmlattr }}></div>
""")
attributes = {
'onclick': 'alert("XSS Attack!")',
'style': 'background-color: red;'
}
rendered = template.render(attributes=attributes)
print(rendered)Patched code sample
from jinja2 import Environment, escape
env = Environment(autoescape=True)
template = env.from_string("""
<div {{ attributes | xmlattr }}></div>
""")
attributes = {
'onclick': 'alert("XSS Attack!")',
'style': 'background-color: red;'
}
rendered = template.render(attributes=' '.join(f'{key}="{value}"' for key, value in attributes.items()))
print(rendered)Cite this entry
@misc{vaitp:cve202422195,
title = {{Jinja xmlattr filter abuse XSS}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-22195},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-22195/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
