Summary
NLTK versions before 3.10.3 parse XML with an XML processor that honors entity declarations in document DTDs. An attacker who can submit or cause processing of crafted XML may trigger excessive entity expansion, consuming large amounts of memory and causing denial of service.
Affected context
The vulnerability occurs in NLTK modules that process attacker-influenced XML using xml.etree.ElementTree. It becomes risky when untrusted XML is accepted from external sources or indirectly processed through documents, feeds, datasets, or other application inputs, and when entity expansion is not restricted before parsing.
Exploit preconditions
- Attack surface: NLTK functionality that parses XML documents
- Required access: Ability to provide, influence, or cause processing of XML input
- Trigger point: XML parsing of a document containing nested entity declarations
- Why exploitation is possible: The parser expands entities recursively, allowing a compact document to consume disproportionate memory during processing
Why this happens
The underlying issue is resource exhaustion caused by unrestricted XML entity expansion. XML parsers that honor DTD entity declarations can recursively replace nested entities, allowing input size to grow dramatically in memory.
This maps to CWE-776: Improper Restriction of Recursive Entity References in DTDs, where an application processes recursive or deeply nested entity references without adequate limits or safe-parser controls.
Potential impact
- Affected processes may consume excessive memory
- Applications may become unresponsive or terminate unexpectedly
- Shared workers or services may experience resource starvation
- Availability of XML-processing features could be reduced
- Repeated requests could amplify operational disruption
General mitigation guidance
Mitigation generally focuses on preventing untrusted XML from using expansive DTD features and reducing the parser's trust in document-provided instructions.
Common defensive patterns include:
- Using XML parsers configured to disable DTD processing and entity expansion
- Applying bounded parsing limits for document size, nesting, and resource consumption
- Validating XML against a restrictive schema or accepted document model
- Treating externally supplied XML as untrusted regardless of its source system
- Isolating XML-processing workloads and assigning only the privileges and resources they require
- Applying request, queue, timeout, and memory policies to limit denial-of-service impact
How teams detect issues like this
Detection can include static analysis for XML parser calls that permit DTDs or entity expansion, along with code review of NLTK data-ingestion paths and any XML input boundaries.
Runtime monitoring may look for abnormal memory growth, parser timeouts, repeated XML-processing failures, unusually small documents producing large in-memory structures, and request patterns targeting XML endpoints. Policy enforcement can require hardened XML parser configurations and bounded resource usage. Automated code review and dependency analysis tools may help identify unsafe parser behavior and affected dependency ranges.

