CVE-2026-129232 — NLTK: Quadratic CPU exhaustion in nltk — CVE Details
NLTK: Quadratic CPU exhaustion in NLTK XMLCorpusView.read_block via deeply nested XML corpus tags
What Should I Do?
Address in Next Maintenance Window
Low exploitation probability (0.52%). Schedule for your next planned update.
Does your project use an affected nltk version?
Paste your requirements.txt to check it for CVE-2026-129232 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.
Summary
Summary
NLTK's XMLCorpusView.read_block rebuilds the full root-to-node context path with "/".join(context) on every start tag while it is still searching for a matching element. Because the context stack grows with XML nesting depth and the join is repeated once per start tag, a single corpus file containing deeply nested tags forces O(n^2) pure-Python work, where n is the number of nested elements. Any application that parses attacker-influenced XML corpus data through an XMLCorpusView subclass (for example the nps_chat, framenet, bnc, mte, nkjp, or semcor readers) can be driven to exhaust a CPU core for an extended period, producing a denial of service without any authentication or special privilege.
Root Cause
read_block maintains a context list that is appended on each start tag and popped on each end tag, so it grows monotonically to the maximum nesting depth while an element is being sought. For every start tag, while no target element has been located yet (elt_start is None), the code recomputes the entire path string from scratch and matches it against the reader's tagspec. The tagspec is anchored (tagspec + "\\Z"), so a nested path such as a/a/a/... never completes a full match against a concrete tagspec like Session/Posts/Post; elt_start therefore stays None for the entire file and the per-start-tag join runs for all n tags over depths 1..n. Summing those join costs yields O(n^2). There is no nesting-depth limit, context-length bound, or cumulative-work budget in read_block, and the per-call regex timeout used elsewhere in the file does not observe this cumulative pure-Python string cost.
nltk/corpus/reader/xmldocs.py : XMLCorpusView.read_block
context.append(name) # start-tag: stack grows with depth
if elt_start is None:
if tagspec.match("/".join(context)): # full path rebuilt per start tag -> O(depth)
...
# empty-element variant rebuilds "/".join(context) + "/" + name the same way
Impact
An unauthenticated attacker who can supply or influence an XML corpus file processed by an XMLCorpusView subclass can cause quadratic CPU consumption. A crafted file of roughly 200 KB consumes several seconds of a single core; a few-megabyte file pins a core for minutes, and an arbitrarily large or unclosed nested file can hang the affected process indefinitely on that core. The result is a denial-of-service condition (CWE-407 / CWE-400). No confidentiality or integrity impact is demonstrated; the impact is availability of the processing thread or process. The prerequisite is that the application feed untrusted or attacker-influenced corpus XML into one of the affected readers, which is the same trust boundary already accepted for the seed issue in the same file.
Proof of Concept
Requires only the nltk package and its standard XML corpus reading path; no network or special configuration.
Reproduction drives a real SeekableUnicodeStreamReader and the real read_block with an nps_chat-style tagspec, comparing nested input (growing context depth) against a flat negative control with an identical tag count.
import time, io
from nltk.corpus.reader.xmldocs import XMLCorpusView
def measure(build, label):
print(label)
prev = None
for n in (4000, 8000, 16000, 32000):
body = build(n).encode("utf-8")
# write to a temp file and open through an XMLCorpusView subclass tagspec
import tempfile, os
fd, path = tempfile.mkstemp(suffix=".xml")
os.write(fd, b"<Session>" + body + b"</Session>"); os.close(fd)
view = XMLCorpusView(path, "Session/Posts/Post")
t = time.time()
try:
list(view)
except Exception:
pass
dt = time.time() - t
ratio = "" if prev is None else f"({dt/prev:.1f}x)"
print(f" n={n:>6} time={dt:7.3f}s {ratio}")
prev = dt
os.remove(path)
measure(lambda n: "<a>"*n + "</a>"*n, "NESTED (context depth = n):")
measure(lambda n: "<a></a>"*n, "FLAT (context depth = 1, negative control):")
NESTED (context depth = n):
n= 4000 time= 0.162s
n= 8000 time= 0.484s (2.99x)
n= 16000 time= 1.595s (3.29x)
n= 32000 time= 5.667s (3.6x) -> ratios trend toward 4x per 2x input = O(n^2)
FLAT (context depth = 1, negative control):
n= 8000 time= 0.145s
n= 16000 time= 0.293s (2.03x)
n= 32000 time= 0.580s (2.0x) -> 2x per 2x input = linear
Attack Chain
- Exposure: An application uses an
XMLCorpusViewsubclass (nps_chat,framenet,bnc,mte,nkjp,semcor, and similar) to read an XML corpus file whose contents an attacker can supply or influence. - Control: The attacker controls the XML body and nests a tag the view's tagspec never fully matches, for example
"<a>"repeated n times followed by"</a>"repeated n times. - Path:
read_blockconsumes the whole file in one call, appending tocontexton every start tag; the target element is never found, so the loop runs to end of file andcontextgrows to depth n. - Guard: No nesting-depth cap, context-length bound, or cumulative-work budget exists in
read_block; the anchored tagspec match fails in O(1) at offset 0, so it is not the hot term, and the per-call regex timeout does not see cumulative string-build cost. - Primitive: For each of the n start tags,
"/".join(context)rebuilds an O(depth) string, giving a cumulative O(n^2) pure-Python CPU cost. - Result: Sustained single-core CPU exhaustion; a modest file blocks a core for seconds to minutes, and an unbounded or unclosed file hangs the processing thread indefinitely.
Bypass Evidence
The seed fix for the previously published quadratic-CPU issue in this same file (CVE-2026-81723, GHSA-vp2x-qp44-57v7) is confined to _read_xml_fragment, where it added incremental in-tag / last-open-bracket tracking. The commit that shipped that fix touched the read_block match line only to change the match call form (from a module-level regex match to a precompiled tagspec match) and preserved the "/".join(context) argument byte-for-byte; it did not add any depth or length bound. This sink is therefore not covered by the seed remediation. It is also distinct from the sibling published issue CVE-2026-81725 (GHSA-8mpw-7fpc-4gqj), whose sink is a block.count(...) line tracker in Pl196xCorpusReader.read_block, a different class, mechanism, input, and fix. The strongest disproof attempts, that the anchored tagspec match is the quadratic term, that the file is not fully consumed in one call, that an end-tag sanity check aborts early, that a depth cap or the per-call regex timeout catches it, that the seed fix already covers it, and that deep nesting is entity expansion blocked by defused XML handling, were each checked and refuted: the flat negative control with identical tag count stays linear, isolating the quadratic term to the depth-dependent join; well-formed balanced input runs to end of file before any pop; no depth cap exists; the timeout is per call and does not observe cumulative pure-Python cost; and benign literal nesting is not custom-entity expansion.
Affected Versions
Ecosystem: PyPI (pip)Package: nltkConfirmed affected range: <= 3.10.3Latest release checked: 3.10.3 (PyPI, nltk-3.10.3-py3-none-any.whl)Fix status: not fixed (no fix present in any released version or in the current development branch)
The vulnerable join sink is present in the latest published artifact (3.10.3) and was corroborated in 3.9.1. No released version and no development-branch commit contains a fix, so the upper bound <= 3.10.3 is proven. The introduction boundary was not pinned to an exact first-affected release: the algorithm is long-standing legacy code present in all inspected supported releases, and pinning an exact introduced version would require bisecting historical wheels. The lower boundary is therefore left unestablished rather than asserted.
Suggested Fix
Bound the work performed while searching for a target element in read_block. Options that address the root cause: track the running context path incrementally (append and truncate a single cached path string alongside the context stack, rather than rejoining the whole list on every tag), or enforce an explicit maximum nesting depth / maximum accumulated tag count for a single block and raise a clear error when it is exceeded. The remediation must cover both the start-tag match at the primary join site and the empty-element variant that rebuilds "/".join(context) + "/" + name, and it should apply regardless of whether the input is well-formed and balanced or an unclosed nested run. As an interim mitigation, deployments can impose an upstream size limit on corpus XML fed to these readers and avoid parsing untrusted corpus files, though this does not remove the quadratic behavior for inputs under the limit.
Reported by zx (GitHub: @manus-pi).
Fix status (2026-09-28)
Status: IN PROGRESS (fix on an open pull request, not yet on develop).
PR: #3895 "[WIP] Bound algorithmic-DoS and uncontrolled-recursion vectors (CWE-400/407/674/1333)", open, head b22ebe144.
Fix commit: 002bcf714 "Bound three quadratic algorithmic-DoS vectors on untrusted input" (XMLCorpusView.read_block no longer rebuilds the context path per piece).
No probe. The advisory PoC re-run (nested tags, n=8000 vs n=32000 through read_block): on the PR head 0.7x over a 4x input (linear); on develop 2fa3f48fe 11.3x (3.08 s vs 34.9 s), so develop is still VULNERABLE. The open PR #3753 measured on its head 238f81500 also gives 10.9x: its xmldocs change targets the unclosed CDATA/comment rescan of GHSA-j8g8, not this vector.
Release: none.
Advisory Timeline
- First published November 19, 2026 (6 days ago).
- Last revised November 20, 2026 — 0 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
pip install "nltk>=3.10.4"
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (1)
Affects 1 ecosystem: PyPI (1).
| Package | Fixed In |
|---|---|
| nltk PyPI · Affected: 0.8, 0.9, 0.9.3, 0.9.4 (+65 more) | 3.10.4 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-400Uncontrolled Resource ConsumptionMITRE
- CWE-407
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 5.3 score means for each attack dimension.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
References
- https://github.com/nltk/nltk/security/advisories/GHSA-cj8f-5fp3-6m88WEB
- https://nvd.nist.gov/vuln/detail/CVE-2026-129232ADVISORY
- https://github.com/nltk/nltk/pull/3895WEB
- https://github.com/nltk/nltk/commit/002bcf714ef8cb8baf94436f4be73e5516914412WEB
- https://github.com/nltk/nltkPACKAGE
- https://github.com/nltk/nltk/releases/tag/v3.10.4WEB
Frequently Asked Questions
- What is CVE-2026-129232?
- NLTK: Quadratic CPU exhaustion in NLTK XMLCorpusView.read_block via deeply nested XML corpus tags. This vulnerability has been assigned a severity rating of MEDIUM (CVSS score: 5.3/10).
- How do I check if my project is affected by CVE-2026-129232?
- CVE-2026-129232 affects nltk. It has a 0.5% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-129232 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Exploitation requires specific conditions, or the impact is limited.
This is a below-median EPSS score — only 37.8% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.
Also Known As
Related CVEs
- CVE-2024-39705HIGH
ntlk unsafe deserialization vulnerability
- CVE-2026-80206HIGH
NLTK: ReDoS in nltk.tgrep via unvalidated user-supplied regular expressions
- CVE-2026-63312HIGH
NLTK: StreamBackedCorpusView Bypasses pathsec.ENFORCE - Arbitrary Local File Read
- CVE-2026-81724MEDIUM
- CVE-2026-81726MEDIUM
- CVE-2026-81724MEDIUM
NLTK: Uncontrolled recursion in nltk.featstruct.FeatStructReader causes unhandled RecursionError (DoS) via deeply nested feature-structure input
- CVE-2026-129228MEDIUM
NLTK: Uncontrolled recursion in Toolbox settings helpers causes denial of service via deeply nested input
- CVE-2026-81722MEDIUM
NLTK: Quadratic-time DoS in PorterStemmer via long runs of 'y'