Uncontrolled Recursion Affecting nltk package, versions [,3.10.4)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.63% (45th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Uncontrolled Recursion vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-NLTK-22733174
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditYazan Balawneh

Introduced: 19 Nov 2026

NewCVE-2026-129222  (opens in a new tab)
CWE-674  (opens in a new tab)

How to fix?

Upgrade nltk to version 3.10.4 or higher.

Overview

nltk is a Natural Language Toolkit (NLTK) is a Python package for natural language processing.

Affected versions of this package are vulnerable to Uncontrolled Recursion via DependencyGraph._tree(), DependencyGraph.tree(), and DependencyGraph.triples() in nltk/parse/dependencygraph.py, which walk the parsed dependency structure using plain, unbounded Python recursion with no depth check. An attacker who can supply a CoNLL/Malt-TAB dependency file containing a long linear chain of tokens (exceeding Python's default recursion limit of 1000) causes an unhandled RecursionError the moment .tree() or .triples() is called on the resulting graph. The crash is reachable through any code path that loads user-supplied dependency-parse data, including DependencyGraph.load(), DependencyGraph() directly, or corpus readers such as DependencyCorpusReader backing nltk.corpus.dependency_treebank and nltk.corpus.conll2007.

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 lines whose head columns reference each other" file-based cycle does *not* actually reach this crash the way it might seem — in the single-head-per-token Malt-TAB/CoNLL format, a genuine mutual-reference pair can't simultaneously be reachable from the graph's root and form a back-edge, so it either leaves `self.root = None`, or the pair becomes a disconnected island that's silently walked past without crashing. The long-chain vector above is the one that's fully, independently confirmed; a cycle built via direct `add_arc()` graph manipulation does also crash, but that's a narrower trigger than a parsed file.)

Note: The PoC uses a 3-column Malt-TAB file with a 3000-token linear chain, verified against current NLTK source via three paths: direct DependencyGraph construction, .triples() consumption, and end-to-end through DependencyCorpusReader.

CVSS Base Scores

version 4.0
version 3.1