VAITP Dataset

← Back to the dataset

CVE-2021-23418

XXE Injection in glances < 3.2.1 via Fault in XML parsing

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

The package glances before 3.2.1 are vulnerable to XML External Entity (XXE) Injection via the use of Fault to parse untrusted XML data, which is known to be vulnerable to XML attacks.

CVSS base score
9.8
Published
2021-07-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
Information Disclosure
Affected component
glances
Fixed by upgrading
Yes

Solution

Update to glances version 3.2.1 or higher.

Vulnerable code sample

import xml.etree.ElementTree as ET

def vulnerable_parse_xml(xml_data):
    # This code is vulnerable to XXE attacks
    try:
        # Parsing XML without any protection against XXE
        root = ET.fromstring(xml_data)
        return root
    except ET.ParseError as e:
        print("Failed to parse XML:", e)
        return None

# Example usage with potential malicious XML
xml_data = """<?xml version="1.0"?>
<!DOCTYPE root [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
  <element>&xxe;</element>
</root>"""
result = vulnerable_parse_xml(xml_data)
print(result)

Patched code sample

import xml.etree.ElementTree as ET

def safe_parse_xml(xml_data):
    # Use the default XML parser which is safe against XXE
    try:
        root = ET.fromstring(xml_data)
        return root
    except ET.ParseError as e:
        print("Failed to parse XML:", e)
        return None

# Example usage
xml_data = """<root><element>Test</element></root>"""
result = safe_parse_xml(xml_data)
print(result)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • Security audit – B411 #1025 (nicolargo/glances)
    glances/actions.py, glances/actions.py · GlancesActions.run, glances/config.py · Config.get_value, unitest.py
  • Security audit – B411 #1025 (nicolargo/glances)
    glances/compat.py, setup.py · get_install_extras_require, setup.py · get_install_requires

Cite this entry

@misc{vaitp:cve202123418,
  title        = {{XXE Injection in glances < 3.2.1 via Fault in XML parsing}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-23418},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-23418/}}
}

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.