VAITP Dataset

← Back to the dataset

CVE-2021-25951

XXE vulnerability in 'XML2Dict' 0.2.2 = Denial of Service

  • CVSS 5.0
  • CWE-611 Improper Restriction of XML External Entity Reference
  • Input Validation and Sanitization
  • Remote

XXE vulnerability in 'XML2Dict' version 0.2.2 allows an attacker to cause a denial of service.

CVSS base score
5.0
Published
2021-06-30
OWASP
A03 Injection
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
XML2Dict
Fixed by upgrading
Yes

Solution

Update 'XML2Dict' to a version that fixes the XXE vulnerability.

Vulnerable code sample

import xml.etree.ElementTree as ET

def unsafe_xml_to_dict(xml_string):
    # Using the default XML parser which can be vulnerable to XXE
    root = ET.fromstring(xml_string)

    def parse_element(element):
        return {element.tag: {child.tag: parse_element(child) for child in element} or element.text}

    return parse_element(root)

# Example usage
xml_data = '''<!DOCTYPE root [
    <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
    <child>&xxe;</child>
</root>'''

result = unsafe_xml_to_dict(xml_data)
print(result)

Patched code sample

import xml.etree.ElementTree as ET

def safe_xml_to_dict(xml_string):
    # Use the XML parser with a restricted set of features to prevent XXE
    parser = ET.XMLParser(resolve_entities=False)
    root = ET.fromstring(xml_string, parser=parser)

    def parse_element(element):
        return {element.tag: {child.tag: parse_element(child) for child in element} or element.text}

    return parse_element(root)

# Example usage
xml_data = '''<root>
    <child>value</child>
</root>'''

result = safe_xml_to_dict(xml_data)
print(result)

Cite this entry

@misc{vaitp:cve202125951,
  title        = {{XXE vulnerability in 'XML2Dict' 0.2.2 = Denial of Service}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-25951},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-25951/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.