VAITP Dataset

← Back to the dataset

CVE-2026-129228

NLTK recursion depth overflow allows DoS via deep settings tree.

  • CVSS 5.3
  • CWE-674
  • Resource Management
  • Local

NLTK (Natural Language Toolkit) is a suite of open source Python modules, data sets, and tutorials supporting research and development in Natural Language Processing. Prior to 3.10.4, ToolboxSettings.parse builds a deeply nested attacker-controlled settings tree iteratively, but the later public helpers to_settings_string, remove_blanks, add_default_fields, sort_fields, and add_blank_lines recursively traverse that tree without a depth bound. Invoking any of those helpers on input nested beyond the interpreter recursion limit can raise RecursionError and abort the operation or request worker. This issue is fixed in version 3.10.4.

CVSS base score
5.3
Published
2026-11-19
OWASP
A04 Insecure Design
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
NLTK
Fixed by upgrading
Yes

Solution

Upgrade NLTK to version 3.10.4 or later.

Vulnerable code sample

import sys
from nltk.toolbox import ToolboxSettings

def build_deep_settings(depth, current=None):
    # builds a nested settings dict of given depth
    if depth == 0:
        return {"value": "leaf"}
    current = current or {}
    current["child"] = build_deep_settings(depth - 1)
    return current

def to_settings_string(settings):
    # VULNERABLE: unbounded recursion when traversing deep settings
    return ToolboxSettings.to_settings_string(settings)

def main():
    # Construct a settings tree deeper than Python's recursion limit
    deep_settings = build_deep_settings(sys.getrecursionlimit() + 10)
    # This call will raise RecursionError on vulnerable NLTK versions
    result = to_settings_string(deep_settings)
    return result

Patched code sample

import sys
from nltk.toolbox import ToolboxSettings

def build_deep_settings(depth, current=None):
    if depth == 0:
        return {"value": "leaf"}
    current = current or {}
    current["child"] = build_deep_settings(depth - 1)
    return current

def to_settings_string(settings, max_depth=1000):
    # FIX: bound recursion depth to prevent exhaustion
    def _traverse(node, current_depth):
        if current_depth > max_depth:
            return "<truncated>"
        if isinstance(node, dict):
            parts = []
            for k, v in node.items():
                parts.append(f"{k}: {_traverse(v, current_depth + 1)}")
            return "{" + ", ".join(parts) + "}"
        return str(node)
    return _traverse(settings, 0)

def main():
    deep_settings = build_deep_settings(sys.getrecursionlimit() + 10)
    result = to_settings_string(deep_settings)
    return result

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • Fix toolbox.py (nltk/nltk)
    nltk/toolbox.py, nltk/toolbox.py · add_blank_lines, nltk/toolbox.py · add_default_fields, nltk/toolbox.py · remove_blanks, nltk/toolbox.py · ToolboxSettings.parse, nltk/toolbox.py · _sort_fields, nltk/toolbox.py · _to_settings_string

Cite this entry

@misc{vaitp:cve2026129228,
  title        = {{NLTK recursion depth overflow allows DoS via deep settings tree.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-129228},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129228/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.