CVE-2020-26709
Py-XML v1.0 XXE vulnerability allows arbitrary code execution via crafted XML
- CVSS 7.5
- CWE-611 Improper Restriction of XML External Entity Reference
- Input Validation and Sanitization
- Remote
py-xml v1.0 was discovered to contain an XML External Entity Injection (XXE) vulnerability which allows attackers to execute arbitrary code via a crafted XML file.
- CVSS base score
- 7.5
- Published
- 2023-06-29
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- py-xml
- Fixed by upgrading
- Yes
Solution
Update py-xml to version 1.1.0 or higher.
Vulnerable code sample
import xml.etree.ElementTree as ET
def vulnerable_parse_xml(xml_string):
# This parser is vulnerable to XXE attacks
return ET.fromstring(xml_string)
# Example of a crafted XML that could exploit the vulnerability
xml_data = """<?xml version="1.0"?>
<!DOCTYPE root [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
<element>&xxe;</element>
</root>"""
try:
parsed_xml = vulnerable_parse_xml(xml_data)
print(ET.tostring(parsed_xml).decode())
except ET.ParseError as e:
print(f"Error parsing XML: {e}")Patched code sample
import xml.etree.ElementTree as ET
def safe_parse_xml(xml_string):
# Use the default parser which does not support external entities
return ET.fromstring(xml_string)
# Example usage
xml_data = """<root>
<element>Some data</element>
</root>"""
try:
parsed_xml = safe_parse_xml(xml_data)
print(ET.tostring(parsed_xml).decode())
except ET.ParseError as e:
print(f"Error parsing XML: {e}")Cite this entry
@misc{vaitp:cve202026709,
title = {{Py-XML v1.0 XXE vulnerability allows arbitrary code execution via crafted XML}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-26709},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-26709/}}
}
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 ::
