Junglewise Threat Intelligence

NLTK uncontrolled recursion in FeatStructReader denial of service

Severity: medium · CVSS 5.3 · Published 2026-08-27

Executive brief

NLTK is a widely-used natural language processing library; its FeatStructReader component parses feature structures used in linguistic grammars. An unauthenticated attacker can send a trivial payload (less than 1 KB) of deeply nested brackets to crash any application that accepts user-supplied feature structures or grammars—for example, NLP teaching tools, grammar playgrounds, or unification-grammar-based NLU systems. The crash is caused by an unhandled exception and can lead to service downtime if the application lacks automatic recovery.

Technical details

The vulnerability exists in nltk.featstruct.FeatStructReader, a recursive-descent parser that processes feature-structure notation (e.g., [a=1]). The parser contains a recursive call cycle (FeatStructReader.read_partial → _read_partial_featdict → _read_value → read_value → read_fstruct_value → read_partial) with no nesting-depth limit or guard. When input contains deeply nested brackets, the recursion depth exceeds Python's built-in limit, raising an unhandled RecursionError—a subclass not caught by the parser's normal exception handlers (which expect ValueError). The same vulnerability affects FeatureGrammar.fromstring(), which uses the same parser for embedded feature structures. A proof-of-concept payload of 669 bytes with 167 levels of nesting crashes in under 2 milliseconds. Similar issues in other NLTK modules (logic.py, jsontags.py) were previously fixed by enforcing a MAX_*_DEPTH constant; featstruct.py lacked equivalent protection. The vulnerability is patched in NLTK 3.10.3 by adding recursion-depth checks.

Affected products

  • NLTK Project NLTK <= 3.10.2

Timeline

  • 2026-08-12: disclosed: Original advisory GHSA-cw6x-m8jw-qmrh published
  • 2026-08-27: advisory: Duplicate advisory GHSA-pf76-q698-37v8 published
  • 2026-08-27: patched: Fix available in NLTK 3.10.3 and later

References

Related threats