CVE-2026-81722 — NLTK: Quadratic-time DoS in nltk — CVE Details
NLTK: Quadratic-time DoS in PorterStemmer via long runs of 'y'
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-81722 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
nltk.stem.PorterStemmer.stem() -- a ubiquitous public API applied to arbitrary, often untrusted, tokens -- runs in O(n^2) time on a token containing a long run of the letter 'y', letting a single ~20-50 KB token pin a CPU core (CWE-407).
Root cause
_is_consonant(word, i) was made iterative (commit for #3633, GHSA/CWE-674) to fix an earlier unbounded-recursion RecursionError on 'y'*10000. The iterative form walks backward over the whole run of 'y's on every call:
while i > 0 and word[i] == 'y':
negate = not negate
i -= 1
_measure() then calls _is_consonant(stem, i) once for every position i of the stem. For a run of n 'y's that is sum_{i} O(i) = O(n^2). The recursion fix therefore traded a CWE-674 RecursionError for a CWE-407 quadratic-time DoS.
Proof of concept
Measured (Python 3.13): stem('y'*5000 + 'ness') = 2.6s, stem('y'*10000 + 'ness') = 11.3s (2x input -> ~4.3x time = quadratic), stem('y'*20000 + 'ness') > 20s. A pure run of 'y' with no matching suffix is fast because the stemmer rules that call _measure do not fire; a real suffix such as 'ness' triggers _measure on the long stem.
from nltk.stem import PorterStemmer
PorterStemmer().stem('y' * 20000 + 'ness') # >20s of CPU
Impact
Stemming is routinely applied to untrusted text (search, indexing, NLP pipelines). A single unbroken ~20-50 KB token of 'y' characters (no whitespace, so it survives tokenization) causes multi-second-to-minutes CPU consumption per request. No confidentiality/integrity impact; single-process availability only.
Fix direction
Classify each character's consonant/vowel status in a single left-to-right O(n) pass (memoise the 'y' run parity) instead of re-walking the run on every _is_consonant call, so _measure and stemming are linear. This is a sibling of the corpus-reader quadratic advisories GHSA-vp2x-qp44-57v7 and GHSA-8mpw-7fpc-4gqj (CWE-407).
Advisory Timeline
- First published September 2, 2026 (85 days ago).
- Last revised September 10, 2026 — 8 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
pip install "nltk>=3.10.3"
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 (+64 more) | 3.10.3 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-407
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 5.3 score means for each attack dimension.
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
References
- https://github.com/nltk/nltk/security/advisories/GHSA-ww6m-cw3f-q94gWEB
- https://nvd.nist.gov/vuln/detail/CVE-2026-81722ADVISORY
- https://github.com/nltk/nltk/commit/7808692d451b962711005d954859bb83aabcf8faWEB
- https://github.com/nltk/nltkPACKAGE
- https://github.com/nltk/nltk/releases/tag/v3.10.3WEB
- https://github.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2026-3738.yamlWEB
- https://www.vulncheck.com/advisories/nltk-porterstemmer-before-3.10.3-quadratic-time-dosWEB
Frequently Asked Questions
- What is CVE-2026-81722?
- NLTK: Quadratic-time DoS in PorterStemmer via long runs of 'y'. 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-81722?
- CVE-2026-81722 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-81722 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.6% 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-2025-14009CRITICAL
NLTK has a Zip Slip Vulnerability
- CVE-2026-66393HIGH
- CVE-2026-62385HIGH
- CVE-2026-128134HIGH
NLTK dot2img runs Graphviz 'dot' without the trusted-exec chokepoint, enabling local code execution via a writable PATH element
- CVE-2025-71408HIGH
NLTK vulnerable to Eval Injection via collocations CLI arguments
- CVE-2026-12075HIGH
Natural Language Toolkit (NLTK): DNS-rebinding SSRF filter bypass in nltk.pathsec.urlopen (nltk.download / nltk.data.load) defeats ENFORCE mode
- CVE-2026-128140MEDIUM
NLTK: Downloader cyclic collection indices cause an infinite closure walk
- CVE-2026-129231MEDIUM
NLTK: Quadratic-time DoS in SeekableUnicodeStreamReader.readline on an unterminated corpus line via per-iteration full-buffer rescan