CVE-2019-17626
ReportLab (up to v3.5.26) RCE via crafted XML color attribute
- CVSS 9.8
- CWE-91 XML Injection (aka Blind XPath Injection)
- Input Validation and Sanitization
- Remote
ReportLab through 3.5.26 allows remote code execution because of toColor(eval(arg)) in colors.py, as demonstrated by a crafted XML document with '<span color="' followed by arbitrary Python code.
- CVSS base score
- 9.8
- Published
- 2019-10-16
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- ReportLab
- Fixed by upgrading
- Yes
Solution
Update ReportLab to version 3.5.27 or higher.
Vulnerable code sample
import xml.etree.ElementTree as ET
def to_color(arg):
# Vulnerable code: using eval on user input
return eval(arg)
def parse_xml(xml_string):
root = ET.fromstring(xml_string)
for span in root.findall('.//span'):
color = span.get('color')
if color:
# This line is vulnerable to remote code execution
safe_color = to_color(color)
# Proceed with using safe_color
# Example usage
xml_input = '<root><span color="__import__(\'os\').system(\'ls\')">Hello</span></root>'
parse_xml(xml_input)Patched code sample
import xml.etree.ElementTree as ET
def safe_to_color(color_string):
# Implement a safe parsing mechanism to prevent code execution
# For example, validate against a list of allowed colors
allowed_colors = {'red', 'green', 'blue', 'black', 'white'}
if color_string in allowed_colors:
return color_string
else:
raise ValueError("Invalid color specified")
def parse_xml(xml_string):
root = ET.fromstring(xml_string)
for span in root.findall('.//span'):
color = span.get('color')
if color:
try:
safe_color = safe_to_color(color)
# Proceed with using safe_color
except ValueError as e:
print(f"Error: {e}")
# Example usage
xml_input = '<root><span color="red">Hello</span></root>'
parse_xml(xml_input)Cite this entry
@misc{vaitp:cve201917626,
title = {{ReportLab (up to v3.5.26) RCE via crafted XML color attribute}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2019},
note = {VAITP Python Vulnerability Dataset, entry CVE-2019-17626},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2019-17626/}}
}
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 ::
