CVE-2020-11888
python-markdown2 (up to v2.3.8) XSS due to mishandling element names
- CVSS 6.1
- CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
- Configuration Issues
- Remote
python-markdown2 through 2.3.8 allows XSS because element names are mishandled unless a \w+ match succeeds. For example, an attack might use elementname@ or elementname- with an onclick attribute.
- CVSS base score
- 6.1
- Published
- 2020-04-20
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Configuration Issues
- Subcategory
- Cross-Site Scripting (XSS)
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- python-markdown2
- Fixed by upgrading
- Yes
Solution
Update python-markdown2 to version 2.3.9 or higher.
Vulnerable code sample
import markdown2
def vulnerable_markdown(input_text):
# Directly convert input text to HTML without sanitization
return markdown2.markdown(input_text)
# Example usage
input_text = "<elementname onclick='alert(1)'>Hello</elementname>"
output = vulnerable_markdown(input_text)
print(output)Patched code sample
import re
import markdown2
def sanitize_element_name(name):
# Allow only valid element names (alphanumeric and underscores)
if re.match(r'^\w+$', name):
return name
raise ValueError("Invalid element name")
def safe_markdown(input_text):
# Replace element names with sanitized versions
def replacement(match):
element_name = match.group(1)
sanitized_name = sanitize_element_name(element_name)
return f"<{sanitized_name}>"
# Regex to find potential element names
pattern = r'<(\w+)>|<\/(\w+)>'
sanitized_text = re.sub(pattern, replacement, input_text)
return markdown2.markdown(sanitized_text)
# Example usage
input_text = "<elementname onclick='alert(1)'>Hello</elementname>"
output = safe_markdown(input_text)
print(output)Cite this entry
@misc{vaitp:cve202011888,
title = {{python-markdown2 (up to v2.3.8) XSS due to mishandling element names}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2020},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-11888},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-11888/}}
}
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 ::
