Vulnerabilities in pkg:pypi/python-docx

PACKAGE
Advisory Identifier: GHSA-34wj-p5jm-2p96
Advisory Summary

CVE-2016-5851 is a HIGH (CVSS 8.8) improper restriction of xml external vulnerability (CWE-611: Improper Restriction of XML External Entity Reference) affecting Python docx libraries in the PyPI ecosystem. The issue involves improper restriction of xml external entity reference in python-docx. Remediation is available by upgrading affected packages to version 0.8.6.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/python-docx

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/python-docx. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-34wj-p5jm-2p96 CVE-2016-5851 HIGH Improper Restriction of XML External Entity Reference in python-docx

CVE-2016-5851 at a Glance

CVE Identifier CVE-2016-5851
GHSA Identifier GHSA-34wj-p5jm-2p96
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-611: Improper Restriction of XML External Entity Reference
Affected Product Python docx
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2016-5851

To remediate this vulnerability, upgrade all affected Python docx dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

python-docx fixed: 0.8.6
pip install python-docx>=0.8.6
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show python-docx

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2016-5851, inspect your installed packages using pip:

pip show python-docx

Analyze the terminal output to locate any version of Python docx in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.8.6), your application is affected.

Note: The pip show python-docx command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-611: Improper Restriction of XML External Entity Reference, where the product processes an xml document that can contain xml entities with uris that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output. In Python docx, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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

CVE-2016-5851 Affected Python docx Versions

1 component(s)
Fixed Versions:
0.8.6
Product / Package Ecosystem Affected Versions Fixed Version
python-docx
PyPI
< 0.8.6
0.8.6

References

NVD — CVE-2016-5851 NVD
https://nvd.nist.gov/vuln/detail/CVE-2016-5851
Security Fix Commit FIX COMMIT
https://github.com/python-openxml/python-docx/commit/61b40b161b64173ab8e362aec1fd197948431beb
GitHub Advisory / Wiki ADVISORY
https://github.com/advisories/GHSA-34wj-p5jm-2p96
Python docx Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/python-docx/PYSEC-2016-21.yaml
Python docx Source Repository REPOSITORY
https://github.com/python-openxml/python-docx
Python docx Source Repository REPOSITORY
https://github.com/python-openxml/python-docx/blob/v0.8.6/HISTORY.rst
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/6FFMOH7ZPOPQWNJGUZOS5LXX4MGNRXXT
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/XU2WSYRNB7CLBBFCGSX34XHACTA2SWDZ
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/6FFMOH7ZPOPQWNJGUZOS5LXX4MGNRXXT
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/XU2WSYRNB7CLBBFCGSX34XHACTA2SWDZ
Python docx Security Information SECURITY
https://web.archive.org/web/20170214030949/http://www.securityfocus.com/bid/91485
Python docx Security Information SECURITY
http://www.openwall.com/lists/oss-security/2016/06/28/7
Python docx Security Information SECURITY
http://www.openwall.com/lists/oss-security/2016/06/28/8
Python docx Security Information SECURITY
http://www.securityfocus.com/bid/91485

Frequently Asked Questions

What is CVE-2016-5851?
CVE-2016-5851 is a security vulnerability in Python docx involving Improper Restriction of XML External Entity Reference in python-docx under CWE-611: Improper Restriction of XML External Entity Reference.
Which Python docx versions are affected?
Affected versions include releases prior to 0.8.6 across affected packages: python-docx.
What version fixes CVE-2016-5851?
Upgrading to 0.8.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is python-docx affected?
Yes, python-docx is affected in releases prior to 0.8.6. Upgrade your dependency to 0.8.6 or later.
What is the CVSS score of CVE-2016-5851?
CVE-2016-5851 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2016-5851?
CVE-2016-5851 is classified under CWE-611: Improper Restriction of XML External Entity Reference (The product processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output.).
How can I check PyPI dependencies for CVE-2016-5851?
Run the dependency tree command: 'pip show python-docx'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-34wj-p5jm-2p96",
  "modified" : "2024-10-25T21:18:53Z",
  "published" : "2022-05-13T01:06:10Z",
  "aliases" : [ "CVE-2016-5851" ],
  "summary" : "Improper Restriction of XML External Entity Reference in python-docx",
  "details" : "python-docx before 0.8.6 allows context-dependent attackers to conduct XML External Entity (XXE) attacks via a crafted document.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "python-docx"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.8.6"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.8.5"
    }
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2016-5851"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-openxml/python-docx/commit/61b40b161b64173ab8e362aec1fd197948431beb"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-34wj-p5jm-2p96"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/python-docx/PYSEC-2016-21.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/python-openxml/python-docx"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-openxml/python-docx/blob/v0.8.6/HISTORY.rst"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/6FFMOH7ZPOPQWNJGUZOS5LXX4MGNRXXT"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/XU2WSYRNB7CLBBFCGSX34XHACTA2SWDZ"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/6FFMOH7ZPOPQWNJGUZOS5LXX4MGNRXXT"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/XU2WSYRNB7CLBBFCGSX34XHACTA2SWDZ"
  }, {
    "type" : "WEB",
    "url" : "https://web.archive.org/web/20170214030949/http://www.securityfocus.com/bid/91485"
  }, {
    "type" : "WEB",
    "url" : "http://www.openwall.com/lists/oss-security/2016/06/28/7"
  }, {
    "type" : "WEB",
    "url" : "http://www.openwall.com/lists/oss-security/2016/06/28/8"
  }, {
    "type" : "WEB",
    "url" : "http://www.securityfocus.com/bid/91485"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-611" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-07-06T19:44:36Z",
    "nvd_published_at" : "2016-12-21T22:59:00Z"
  }
}