VAITP Dataset

← Back to the dataset

CVE-2023-27476

OWSLib Python package XML entity resolution vulnerability

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

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service interface standards, and their related content models. OWSLib's XML parser (which supports both `lxml` and `xml.etree`) does not disable entity resolution, and could lead to arbitrary file reads from an attacker-controlled XML payload. This affects all XML parsing in the codebase. This issue has been addressed in version 0.28.1. All users are advised to upgrade. The only known workaround is to patch the library manually. See `GHSA-8h9c-r582-mggc` for details.

CVSS base score
7.5
Published
2023-03-08
OWASP
A08 Software and Data Integrity Failures
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
OWSLib
Fixed by upgrading
Yes

Solution

Update OWSLib to version 0.28.1 or higher.

Vulnerable code sample

import requests
from owslib.wms import WebMapService

# Vulnerable code using OWSLib without disabling entity resolution
def fetch_wms_capabilities(url):
    wms = WebMapService(url)
    return wms.getcapabilities()

# Example of an attacker-controlled XML payload
malicious_xml = """<?xml version="1.0"?>
<!DOCTYPE foo [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<request>
  <data>&xxe;</data>
</request>
"""

# Simulating fetching capabilities with a malicious XML payload
try:
    response = fetch_wms_capabilities('http://example.com/wms?service=WMS&request=GetCapabilities')
    print(response)
except Exception as e:
    print("An error occurred:", e)

Patched code sample

import lxml.etree as ET

# Function to parse XML securely by disabling entity resolution
def secure_parse(xml_content):
    parser = ET.XMLParser(resolve_entities=False)  # Disable entity resolution
    return ET.fromstring(xml_content, parser)

# Example usage
xml_data = """<?xml version="1.0"?>
<!DOCTYPE root [
    <!ENTITY example SYSTEM "file:///etc/passwd">
]>
<root>
    <data>&example;</data>
</root>"""

try:
    root = secure_parse(xml_data)
    print(ET.tostring(root, pretty_print=True).decode())
except Exception as e:
    print(f"Error: {e}")

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.

  • use only lxml for XML handling (geopython/OWSLib)
    owslib/catalogue/csw2.py · CatalogueServiceWeb.getrecords, owslib/catalogue/csw2.py · CatalogueServiceWeb.getrecords2, owslib/catalogue/csw2.py · CatalogueServiceWeb._setrootelement, owslib/catalogue/csw3.py · CatalogueServiceWeb.getrecords, owslib/etree.py, owslib/etree.py · patch_well_known_namespaces, owslib/feature/schema.py, owslib/util.py, owslib/util.py · add_namespaces, owslib/util.py · cleanup_namespaces, owslib/util.py · element_to_string

Cite this entry

@misc{vaitp:cve202327476,
  title        = {{OWSLib Python package XML entity resolution vulnerability}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2023-27476},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-27476/}}
}

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.