Executive brief
NLTK is a popular Python library used for natural language processing tasks. An uncontrolled recursion flaw in its JSON decoder can crash applications that process user-supplied JSON data. An attacker can send a specially crafted JSON payload with excessive nesting to crash the application or service, causing an outage.
Technical details
The vulnerability is an uncontrolled recursion (CWE-674) in the JSONTaggedDecoder.decode_obj() method in nltk/jsontags.py (lines 47–52). The method recursively processes dictionaries and lists without checking or limiting recursion depth. When a JSON structure exceeds sys.getrecursionlimit() (typically 1000), an unhandled RecursionError is raised, crashing the Python interpreter. The attack vector is network-based if the application receives JSON from external sources; no authentication or privileges are required. The proof-of-concept demonstrates the issue using deeply nested JSON. The fix adds a depth parameter with a hard limit (e.g., 100 levels) to prevent runaway recursion. Version 3.9.4 of NLTK contains the patch; all versions <= 3.9.3 are vulnerable.
Affected products
- NLTK Project Natural Language Toolkit <= 3.9.3
Timeline
- 2026-03-18: disclosed: Published in GitHub Advisory Database
- 2026-03-18: patched: Patched in version 3.9.4