CVE-2016-5851: XML External Entity (XXE) vulnerability in python-docx

python-docx Updated 02 Oct 2025

Summary

13/05/2022
Yes i
High
8.8

CVE-2016-5851: Improper Restriction of XML External Entity Reference in python-docx. Affects python-docx versions < 0.8.6. Fixed in 0.8.6. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

python-docx is a Python library used for creating and updating Microsoft Word (.docx) files. It provides an easy-to-use interface for manipulating various aspects of Word documents. However, versions prior to 0.8.6 are vulnerable to an XML External Entity (XXE) attack.

Vulnerability Detail

The vulnerability arises due to improper restriction of XML External Entity references. An attacker can exploit this vulnerability by crafting a malicious document that includes specially crafted XML content. When this document is processed by python-docx, it may allow the attacker to read arbitrary files on the system or conduct other malicious activities. This can lead to unauthorized access, data leakage, or even remote code execution.

How To Fix

Latest published version: 1.2.0 as of 23 Oct 2026

pip install --upgrade "python-docx==1.2.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.8.6

This is the first release that contains the fix.

pip install --upgrade "python-docx==0.8.6"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading python-docx is not immediately feasible, a temporary workaround is to disable external entity expansion in the XML parser used by python-docx. This can be achieved by modifying the code that processes the XML content. Here's an example of how to disable external entity expansion in python-docx:

import docx

# Disable external entity expansion
docx.opc.constants.PARSE_XML = False

# Process the document
document = docx.Document('path/to/document.docx')
# ...

Conclusion

The XML External Entity (XXE) vulnerability in python-docx versions prior to 0.8.6 can allow an attacker to conduct malicious activities, including unauthorized access, data leakage, or remote code execution. It is crucial to upgrade python-docx to version 0.8.6 or later to mitigate this vulnerability. If you have any further questions or need assistance with vulnerability remediation, please reach out to DevNack.com.

See every vulnerability recorded for python-docx →

Share this vulnerability

FAQ

python-docx is a Python library used for creating and updating Microsoft Word (.docx) files. It provides an easy-to-use interface for manipulating various aspects of Word documents.

An XML External Entity (XXE) attack is a type of vulnerability that allows an attacker to exploit the processing of XML content by including external entities. This can lead to unauthorized access, data leakage, or remote code execution.

You can check the version of python-docx installed by running the following command:

pip show python-docx

No, only versions prior to 0.8.6 are affected by this vulnerability. It is recommended to upgrade to version 0.8.6 or later to mitigate the risk.

The recommended workaround is to upgrade python-docx to the latest version. However, if upgrading is not immediately feasible, you can also consider implementing additional security measures such as input validation and sanitization to mitigate the risk.

How To Fix

Latest published version: 1.2.0 as of 23 Oct 2026

pip install --upgrade "python-docx==1.2.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.8.6

This is the first release that contains the fix.

pip install --upgrade "python-docx==0.8.6"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback