VAITP Dataset

← Back to the dataset

CVE-2016-5851

python-docx < 0.8.6 vulnerable to XXE attacks

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

python-docx before 0.8.6 allows context-dependent attackers to conduct XML External Entity (XXE) attacks via a crafted document.

CVSS base score
8.8
Published
2016-12-21
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
python-docx
Fixed by upgrading
Yes

Solution

Update python-docx to version 0.8.6 or higher.

Vulnerable code sample

import zipfile
import xml.etree.ElementTree as ET

def load_docx(file_path):
    # Open the DOCX file as a zip file
    with zipfile.ZipFile(file_path) as docx:
        # Read the document.xml file
        with docx.open('word/document.xml') as document_xml:
            # Parse the XML without restrictions, allowing DTDs and external entities
            tree = ET.parse(document_xml)
            return tree

# Example usage
# tree = load_docx('path/to/document.docx')

Patched code sample

import zipfile
import xml.etree.ElementTree as ET

def safe_load_docx(file_path):
    # Open the DOCX file as a zip file
    with zipfile.ZipFile(file_path) as docx:
        # Read the document.xml file
        with docx.open('word/document.xml') as document_xml:
            # Parse the XML without DTDs or external entities
            parser = ET.XMLParser(resolve_entities=False)
            tree = ET.parse(document_xml, parser)
            return tree

# Example usage
# tree = safe_load_docx('path/to/document.docx')

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.

Cite this entry

@misc{vaitp:cve20165851,
  title        = {{python-docx < 0.8.6 vulnerable to XXE attacks}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2016},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2016-5851},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2016-5851/}}
}

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.