CVE-2026-78681: NLTK before 3.10.3 Entity Expansion DoS via ElementTree

Published Aug 25, 2026
·
Updated

NLTK versions before 3.10.3 use xml.etree.ElementTree to parse XML in multiple modules, which honors entity declarations in document DTDs. Attackers can craft XML payloads with nested entity declarations that expand from hundreds of bytes to megabytes in memory, causing denial of service.

Other sources

Several XML parsing sites in NLTK still used xml.etree.ElementTree directly, which honours <!ENTITY> declarations in a document's internal DTD subset. A crafted document a few hundred bytes long can expand to megabytes in memory (each nesting level multiplies by ten), a denial-of-service.

Affected call sites (<= 3.10.2): - nltk.chunk.namedentity.loadacefile — parses ACE annotation XML - nltk.internals.ElementWrapper — converts any given string to an Element - nltk.downloader — Package.fromxml, Collection.fromxml, findcollections, findpackages

libexpat 2.6.0 added an input-amplification cap, but it only engages above an activation threshold (~8 MiB output) and depends on whichever libexpat the interpreter links; builds against older libexpat have no cap at all. External entities are not resolved by ElementTree, so this is a memory-amplification DoS (CWE-776), not XXE/file disclosure.

This completes the earlier defusedxml adoption that these sites were missed by. Fix routes all of them through a new nltk.xmlsec module that refuses entity declarations, preferring defusedxml and falling back to a standard-library xml.parsers.expat pre-scan when defusedxml is absent.

---

Attack demonstration

Reproducible PoC against a real affected entry point (nltk.internals.ElementWrapper). Every number below is captured output, not illustrative.

1. The amplification (vulnerable path: raw xml.etree.ElementTree)

A payload of a few hundred bytes expands to megabytes in memory. Each nesting level multiplies output by 10 while adding ~56 bytes of input:

| levels | input bytes | expanded bytes | factor | |--------|-------------|----------------|--------| | 3 | 218 | 10,000 | x45 | | 4 | 274 | 100,000 | x364 | | 5 | 330 | 1,000,000 | x3,030 | | 6 | 386 | (libexpat 2.7.1 cap trips) | - |

The level-6 cap is libexpat's, not NLTK's: it only engages above an ~8 MiB activation threshold, and older libexpat builds (still shipped with many 3.10/3.11 interpreters) have no cap at all. Under the threshold — up to ~1 MB per parse here — expansion always succeeds.

python import xml.etree.ElementTree as ET def bomb(levels): d = "\n".join(f'<!ENTITY e{i} "{("&e%d;"%(i-1))10}">' for i in range(1, levels+1)) return f'<!DOCTYPE d [<!ENTITY e0 "AAAAAAAAAA">{d}]><d>&e{levels};</d>' ET.fromstring(bomb(5)) # -> element whose .text is 1,000,000 chars

2. The patched entry point rejects it

>> from nltk.internals import ElementWrapper >> ElementWrapper(bomb(5)) EntitiesForbidden: EntitiesForbidden(name='e0', ...)

3. Why a text-based screen is not enough

An entity declaration can hide behind a decoy <!DOCTYPE> in a prolog comment. Raw ElementTree still processes the real declaration and expands; a guard that walks the DOCTYPE text is fooled. The shipped guard re-parses with expat, so it is not:

python evil = '<!-- <!DOCTYPE x [ ] > --><!DOCTYPE d [<!ENTITY a "PPPP...">]><d>&a;</d>'

raw ElementTree -> EXPANDS ('PPPPPPPPPPPP...', 40 chars) nltk.xmlsec -> REJECTED (EntitiesForbidden)

An earlier draft of the fallback that walked the text was bypassed by this and 4 similar payloads (decoy DOCTYPE in a PI, stray ] inside a PI in the internal subset). All five are now regression tests.

4. Both back ends block it

nltk.xmlsec prefers defusedxml and falls back to a stdlib xml.parsers.expat pre-scan. Same payloads, defusedxml hidden to force the fallback:

stdlib fallback | billion-laughs -> REJECTED (EntitiesForbidden) stdlib fallback | comment-decoy differential -> REJECTED (EntitiesForbidden)

Environment: python 3.13.7, libexpat 2.7.1. Confirmed identical amplification on python 3.10 (NLTK's floor).

— GitHub

Affected Software

3 affected componentsFixes available
NLTK<3.10.3
nltk nltk<3.10.3
pip/nltk<=3.10.2
3.10.3

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/nltk to a version that resolves this vulnerability.

    Fixed in 3.10.3
  2. Upgrade

    Upgrade nltk.internals.ElementWrapper to a version that resolves this vulnerability.

    Fixed in 3.10.3
  3. Upgrade

    Upgrade NLTK to a version that resolves this vulnerability.

    Fixed in 3.10.3
  4. Configuration

    Route XML parsing through the new `nltk.xmlsec` module so it refuses entity declarations; prefer `defusedxml`, and when `defusedxml` is absent fall back to a stdlib `xml.parsers.expat` pre-scan that rejects `<!ENTITY>`/DTD entity declarations (e.g., returns REJECTED (EntitiesForbidden)).

    nltk.xmlsec (new XML security parsing path) entity_declarations = refuse

Event History

Aug 25, 2026
CVE Published
via MITRE·01:30 AM
Data Sourced
via MITRE·01:30 AM
DescriptionSeverityWeakness
Data Sourced
via NVD·02:16 AM
DescriptionSeverityWeaknessAffected Software
Sep 8, 2026
Advisory Published
via GitHub·04:42 PM
Data Sourced
via GitHub·04:42 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

Who is exposed to this denial-of-service issue?

Applications using NLTK versions earlier than 3.10.3 are exposed when they parse attacker-controlled XML through affected NLTK modules. The vulnerability is remotely reachable and requires no attacker privileges or user interaction.

2

What does an attacker need to exploit it?

An attacker needs to supply a crafted XML document containing a DTD with nested entity declarations. Element expansion can grow a small input into megabytes of in-memory data, causing a denial of service.

3

Is confidentiality or data integrity affected?

The provided severity vector indicates impact to availability only. It does not indicate confidentiality or integrity impact.

4

What is the available remediation?

Upgrade NLTK to version 3.10.3 or later. The affected range is NLTK versions before 3.10.3.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203