NLTK dependency parser crashes on long sentences
What this means
An attacker who supplies a specially crafted text file with a very long chain of words can crash any program that uses NLTK to parse it. The crash happens when the program tries to read the parsed result, during normal use. This could disrupt services that depend on NLTK and cause denial of service attacks.
SecurityElites Manager Brief: the decision in one minute
NLTK's dependency parser can be forced to crash by giving it a text file with an unusually long sentence. This happens during normal reading of the parsed result, not during setup. Any service using NLTK to parse text files is at risk of being knocked offline.
| SecurityElites Fix-First Score | 43 of 100 Our own ranking of what to fix first. Real attacks count most, then the chance of attack, then severity. |
|---|---|
| SecurityElites fix window | Within 30 days High severity. This is our suggestion from common practice; your own policy comes first. |
| Who should own the fix | The team managing Python dependencies and natural language processing pipelines. |
| Likely effort | About 15 minutes per service: a pip update and a quick test run. If your NLTK installation is frozen in a larger build system, changing the version may require more testing. |
Questions to ask your team or supplier
- Does your team use NLTK's DependencyGraph, DependencyCorpusReader, or the public dependency corpora (conll2007, dependency_treebank)? If so, which services and how often?
- Do any of your services accept user-supplied text files, text from the web, or dependency-format data from untrusted sources? If yes, can they be forced to call .tree() or .triples() on them?
- If a crash was found in your logs, can you trace back where the malicious or unusual text file came from, and was any other sensitive system touched by the same source?
Message you can forward to the owning team
Security notice: NLTK dependency parser crashes on long sentences (CVE-2026-129222)
Severity: High
SecurityElites Fix-First Score: 43 of 100
SecurityElites fix window: Within 30 days
Action: upgrade to nltk 3.10.4 or later.
What we need from you: confirm whether we run this software, who owns it, and the date it will be fixed.
Full guide: https://securityelites.com/ai-vulnerabilities/cve-2026-129222-nltk-dependency-parser-crashes-on-long-sentences/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01483What is at stake in your AI setup
- Text processing pipelines and training data: a malicious input could crash systems that build or process NLP models using NLTK dependency parsing.
- Availability of NLP services: denial of service attacks could prevent legitimate requests to language understanding or parsing services from being completed.
Who is exposed
- Teams running services that parse dependency structures from text files using NLTK (DependencyGraph, DependencyCorpusReader, or the public corpora like conll2007 and dependency_tre
- Applications that call .tree() or .triples() on a parsed dependency graph immediately after loading it from a file.
- Systems that accept user-supplied text files or parse dependency-formatted data from untrusted sources.
- Services are NOT affected if they never use DependencyGraph, only use the tokenizer or other NLTK components.
Upgrades you need
| Software | Affected versions | Move to |
|---|---|---|
| nltk PyPI | Every version before 3.10.4 | 3.10.4 or later |
Am I affected?
Enter the version you run. Nothing you type is stored.
SecurityElites Developer Brief: the technical picture
| Is it being attacked | No known attacks and no public attack code when CISA last reviewed it |
|---|---|
| Where the attacker must be | Anywhere that can reach it over a network, including the internet if it is exposed |
| Account needed | None. No login is needed |
| Does a person have to do something | No. It works without anyone clicking or opening anything |
| How hard it is to do | Easy. It works reliably once the attacker can reach it |
| Risk of: data being read | None |
| Risk of: data or settings being changed | None |
| Risk of: the service being taken down | High |
| Can attackers automate it at scale | Yes, according to CISA |
| How much control an attacker gains | Partial control, according to CISA |
Read from the official severity rating: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Kind of coding mistake
- CWE-674
If you cannot upgrade today
- If you cannot upgrade immediately: add a custom check before calling .tree() or .triples() — catch RecursionError exceptions and reject files that trigger them, or set Python's recursion limit lower to fail fast.
- Limit the input: reject dependency-format files or text with sentences longer than 500 tokens, since the fix enforces a maximum tree depth of 500.
- Use only trusted, pre-vetted dependency files and corpora. Do not accept user-supplied dependency-format files until the upgrade is in place.
Signs it may already have been used against you
- Search logs for "RecursionError" and "dependency" or "DependencyGraph" appearing together in error messages.
- Look for process crashes or service restarts that happened immediately after a dependency-parsing operation (a call to .tree() or .triples()).
- Check if any malformed, extremely long, or unusual dependency-format files (Malt-TAB, CoNLL) were submitted to your service shortly before crashes.
- Review access logs for requests that uploaded or supplied text files with unusually long sentences (more than a few thousand words chained together).
SecurityElites Fix Guide: step by step
- Find where NLTK is installedList all Python environments in use (virtual environments, containers, production servers). Run `pip list | grep nltk` or `python -c "import nltk; print(nltk.__file__)"` in each one to see the current version.
- Check if DependencyGraph is usedSearch your codebase for imports and calls: `grep -r "DependencyGraph\|DependencyCorpusReader\|conll2007\|dependency_treebank\|parse.*dependency" --include="*.py"` to find all places where dependency parsing happens.
- Identify what text files are parsedList all text files, corpora, or input sources that are parsed as dependency structures. Note whether they come from trusted sources only or could include untrusted input (user uploads, web scrapes, external APIs).
- Upgrade NLTK to 3.10.4 or newerRun `pip install --upgrade nltk>=3.10.4` in each affected environment. For frozen requirements files, update the pinned version to 3.10.4 or higher and redeploy.
- Test the fix with a normal fileRun one of your existing dependency-parsing jobs on a sample text file to confirm it still works after the upgrade. Check that .tree() and .triples() calls complete without errors.
- Review recent logs for crashesSearch logs from the past month for unhandled RecursionError exceptions in NLTK dependency parsing code. If found, note the timestamps and input files to understand if the vulnerability was already exploited.
- If a crash was found, investigate the inputIf RecursionError crashes were logged, examine the dependency-formatted files or text that triggered them. Check their source and whether they may have been crafted maliciously or came from an untrusted source.
- Document the deploymentRecord the date and version upgraded to in your change log. Note which services were affected and which files or input sources they accept.
How to confirm it is fixed: Run your dependency-parsing code on a sample file and confirm that .tree() and .triples() complete without errors; then check `python -c "import nltk; print(nltk.__version__)"` and confirm it is 3.10.4 or higher.
SecurityElites Quick Fixes: copy and paste
Upgrade nltk with pipupgrade
pip install --upgrade "nltk>=3.10.4"
pip show nltk | grep VersionPin it in requirements.txtupgrade
nltk>=3.10.4Check installed NLTK versionfor this issue
python -c "import nltk; print(nltk.__version__)"Search for DependencyGraph usage in codefor this issue
grep -r "from nltk.parse import DependencyGraph\|from nltk.corpus import.*dependency\|DependencyCorpusReader\|.tree()\|.triples()" --include="*.py" .Require sign-in with nginx in front of the servicegeneral hardening
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://127.0.0.1:8080;
}Test in a non-production environment first. General hardening examples use placeholder names and ports; change them to match your setup.
Let your AI coding assistant do the upgrade
Paste this into the coding assistant you already use, inside the project. It checks first and asks before it changes anything.
Instruction for your coding assistant
You are helping me fix a security vulnerability (CVE-2026-129222) in this project.\n\n1. Search the whole repository, including lock files, container files and CI configuration, for these packages and list every place they are pinned or installed:\n - nltk (PyPI): must be 3.10.4 or later
2. Tell me which version we use now and whether it is affected. Stop and ask me before changing anything.
3. After I agree, raise each one to the safe version, update the lock files, and keep every other dependency as it is.
4. Run the tests and tell me what failed.
5. Give me a short summary of the files you changed that I can put in the pull request.SecurityElites Incident Drill: could your team handle this?
Four questions to ask in your next team meeting. If any has no clear answer, that is the gap to close.
Ticket for your backlog
Paste into Jira, GitHub Issues or any tracker that reads Markdown.
Ready-made ticket
## NLTK dependency parser crashes on long sentences (CVE-2026-129222)
**Severity:** High | **SE Fix-First Score:** 43/100 | **Fix window:** Within 30 days
**Record:** SE-AIV-01483 https://securityelites.com/ai-vulnerabilities/cve-2026-129222-nltk-dependency-parser-crashes-on-long-sentences/
### Why this matters
An attacker who supplies a specially crafted text file with a very long chain of words can crash any program that uses NLTK to parse it. The crash happens when the program tries to read the parsed result, during normal use. This could disrupt services that depend on NLTK and cause denial of service attacks.
### What to do
1. Find where NLTK is installed
2. Check if DependencyGraph is used
3. Identify what text files are parsed
4. Upgrade NLTK to 3.10.4 or newer
5. Test the fix with a normal file
6. Review recent logs for crashes
7. If a crash was found, investigate the input
8. Document the deployment
Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-129222-nltk-dependency-parser-crashes-on-long-sentences/
### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run your dependency-parsing code on a sample file and confirm that .tree() and .triples() complete without errors; then check `python -c "import nltk; print(nltk.__version__)"` and confirm it is 3.10.4 or higher.
- [ ] Logs were checked for signs of earlier use
SecurityElites Fix Tracker
Record who owns this fix, the date it is due and when it is done, and see everything still open in one list. Free with a SecurityElites account.
Related vulnerabilities
In the same software
- NLTK can overwrite files outside its data folder via hardlinks during package extraction High · CVE-2026-128135
- NLTK can run untrusted Java code even after security fix in 3.10.3 Critical · CVE-2026-128138
- NLTK XML parser can be made to freeze by reading a crafted corpus file High · CVE-2026-128139
- NLTK WordNet tree methods can run out of memory with deep relation chains High · CVE-2026-129223
- NLTK regex compilation denial of service via many groups High · CVE-2026-129229
- NLTK can run attacker's code when given a relative path to Prover9 or Mace High · CVE-2026-129234
The same kind of mistake in other AI tools
- BaaRai ARTEX admin account can be claimed without authentication on first run Critical · CVE-2026-140422
- BaaRai ARTEX admin login can be guessed without limits or lockouts Critical · CVE-2026-140365
- Model Context Protocol SDK tasks can be read by other clients sharing the store High · CVE-2026-111767
- rmcp: Session memory leak on invalid requests High · CVE-2026-63128
- n8n OAuth registration accepts unlimited field sizes, filling the database High · CVE-2026-86075
Change history
- 19 Nov 2026: Made public
- 1 Dec 2026: Published
Official record
### Summary DependencyGraph.tree()/triples() walk the parsed dependency structure using plain, unbounded Python recursion — one stack frame per edge in the graph — and never use the class's own cycle detector. A crafted dependency-parse file with a few thousand chained tokens (an entirely ordinary-looking long sentence) crashes the process with an unhandled RecursionError the moment .tree() or .triples() is called — which is NLTK's own documented usage pattern immediately after loading such a file.### Details `DependencyGraph._tree()` (~lines 393-406), `.tree()` (~408-417), and `.triples()` (~419-432) in `nltk/parse/dependencygraph.py` rebuild/walk the graph with `Tree(word, [self._tree(dep) for dep in deps])` and `yield from self.triples(node=dep)` — ordinary recursive calls, one per edge, with no depth check. `contains_cycle()` is defined on the class (~line 447) but is never invoked by any of these three methods.This is exactly the CWE-674 pattern the project has already identified and fixed elsewhere: `nltk/tree/tree.py` adds `MAX_TREE_DEPTH = 500` with a comment stating that an arbitrarily deep tree would make every traversal raise RecursionError, and `nltk/test/unit/test_recursion_dos.py` locks in the identical fix for `FeatStructReader`, `LogicParser`, and `ResolutionProver`. But `DependencyGraph` builds its `Tree` objects **programmatically** (`Tree(word, [...])`), which bypasses `MAX_TREE_DEPTH` entirely — that guard only fires inside `Tree.fromstring()`'s bracket-string parser, never in `Tree.__init__`. `DependencyGraph`'s own recursive walk has no depth limit of its own.Any Malt-TAB/CoNLL(3/4/7/10)-format text — read via `DependencyCorpusReader` (`nltk/corpus/reader/dependency.py`, lines 62-69, backing the public, documented `nltk.corpus.dependency_treebank` and `nltk.corpus.conll2007` corpora) or via the public classmethod `DependencyGraph.load(filename)` (~line 213) / `DependencyGraph(text)` directly — that chains more tokens than Python's default recursion limit (1000) via consecutive head references crashes with an unhandled `RecursionError` the moment `.tree()`/`.triples()` is called. Calling `.tree()` immediately after `parsed_sents()` is not a contrived edge case — it is NLTK's own documented usage pattern (`nltk/test/corpus.doctest`: `print(conll2007.parsed_sents('esp.train')[0].tree())`; `nltk/test/dependency.doctest`: `dg.tree().pprint()`).**Related observation:** `contains_cycle()` itself has a separate bug that means it wouldn't help even if it were called on this path — it iterates `node["deps"]` as if it were a flat list of neighbor addresses, but `_parse()`/`add_arc()` actually store `deps` as `{relation_label: [addresses]}`; iterating that dict yields relation-label strings, which then fail the `dep not in self.nodes` check and get silently skipped. So `contains_cycle()` returns `False` (a false negative) on real parsed/`add_arc()`-built graphs even when a genuine cycle exists — it only works on the flat-list shape used in its own docstring example. This reinforces that there is no working recursion/cycle safety net on this code path today.### PoC A tiny (few KB) 3-column Malt-TAB file: one root line `w1 ROOT 0` followed by ~2000-3000 lines `wi X i-1`, each chaining a token to the previous one (an entirely ordinary-looking long sentence/coordination structure). Verified directly against current source:1. Constructing a `DependencyGraph` from a 3000-token linear chain and calling `.tree()` → `RecursionError: maximum recursion depth exceeded`. Confirmed. 2. Same graph, `.triples()` fully consumed → `RecursionError`. Confirmed. 3. Full realistic path: wrote the 3000-token chain to a temp file, read it back through an actual `DependencyCorpusReader` (the exact class backing `dependency_treebank`/`conll2007`) via `parsed_sents()`, then called `.tree()` on the result → `RecursionError`, end-to-end through the real public API.(One honest correction to an earlier draft of this finding: a "two l
Weakness type: CWE-674
Use this record in your own tools
Get this record as JSON
curl https://securityelites.com/wp-json/se-aivd/v1/vulns/CVE-2026-129222For scanners and pipelines: OSV format · CycloneDX format · API guide · Email alerts · Fix tracker
The plain-language sections were written with AI from the official record, and the upgrade versions come directly from the official data. Last updated 1 Dec 2026. Read the vendor advisory before changing a production system.