{"id":846,"cve":"CVE-2023-27476","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2023-27476","cwe":"CWE-611 Improper Restriction of XML External Entity Reference","cwe_number":611,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/611","cvss_score":7.5,"published":"2023-03-08","owasp":"A08 Software and Data Integrity Failures","odc":"Function","cdc":"Incorrect Functionality","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Information Disclosure","summary":"OWSLib Python package XML entity resolution vulnerability","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2023-27476\/","description":"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.","solution":"Update OWSLib to version 0.28.1 or higher.","affected_component":"OWSLib","fixed_by_upgrading":true,"vulnerable_code":"import requests\nfrom owslib.wms import WebMapService\n\n# Vulnerable code using OWSLib without disabling entity resolution\ndef fetch_wms_capabilities(url):\n    wms = WebMapService(url)\n    return wms.getcapabilities()\n\n# Example of an attacker-controlled XML payload\nmalicious_xml = \"\"\"<?xml version=\"1.0\"?>\n<!DOCTYPE foo [\n  <!ENTITY xxe SYSTEM \"file:\/\/\/etc\/passwd\">\n]>\n<request>\n  <data>&xxe;<\/data>\n<\/request>\n\"\"\"\n\n# Simulating fetching capabilities with a malicious XML payload\ntry:\n    response = fetch_wms_capabilities('http:\/\/example.com\/wms?service=WMS&request=GetCapabilities')\n    print(response)\nexcept Exception as e:\n    print(\"An error occurred:\", e)","patched_code":"import lxml.etree as ET\n\n# Function to parse XML securely by disabling entity resolution\ndef secure_parse(xml_content):\n    parser = ET.XMLParser(resolve_entities=False)  # Disable entity resolution\n    return ET.fromstring(xml_content, parser)\n\n# Example usage\nxml_data = \"\"\"<?xml version=\"1.0\"?>\n<!DOCTYPE root [\n    <!ENTITY example SYSTEM \"file:\/\/\/etc\/passwd\">\n]>\n<root>\n    <data>&example;<\/data>\n<\/root>\"\"\"\n\ntry:\n    root = secure_parse(xml_data)\n    print(ET.tostring(root, pretty_print=True).decode())\nexcept Exception as e:\n    print(f\"Error: {e}\")","payload_needed":false,"payload":null,"payload_status":"none","published_fix":[{"repository":"geopython\/OWSLib","commit_url":"https:\/\/github.com\/geopython\/OWSLib\/commit\/b92687702be9576c0681bb11cad21eb631b9122f","commit_subject":"use only lxml for XML handling","units":[{"file":"owslib\/catalogue\/csw2.py","function":"CatalogueServiceWeb.getrecords"},{"file":"owslib\/catalogue\/csw2.py","function":"CatalogueServiceWeb.getrecords2"},{"file":"owslib\/catalogue\/csw2.py","function":"CatalogueServiceWeb._setrootelement"},{"file":"owslib\/catalogue\/csw3.py","function":"CatalogueServiceWeb.getrecords"},{"file":"owslib\/etree.py","function":null},{"file":"owslib\/etree.py","function":"patch_well_known_namespaces"},{"file":"owslib\/feature\/schema.py","function":null},{"file":"owslib\/util.py","function":null},{"file":"owslib\/util.py","function":"add_namespaces"},{"file":"owslib\/util.py","function":"cleanup_namespaces"},{"file":"owslib\/util.py","function":"element_to_string"}]}],"references":null}