MEDIUM · CVSS 3.1 5.3 EPSS 0.5% · 42th percentile CWE-674

CVE-2026-129228: NLTK: Uncontrolled recursion in Toolbox settings helpers causes denial of service via deeply nested input

Published 2026-11-19 · Updated 2026-11-20 · Also known as GHSA-f2h2-f4fc-p978

Summary

NLTK contains uncontrolled recursion vulnerabilities in its Toolbox settings helpers, allowing unauthenticated attackers to cause a denial of service via deeply nested input. Users of the affected NLTK versions should monitor for the upcoming patch release that includes the recursion depth bounding.

Who is affected

Applications that parse and subsequently process or serialize untrusted Toolbox settings files are vulnerable. When an attacker provides a sufficiently deep settings tree, the lack of recursion limits causes a Python RecursionError, which terminates the affected operation or request worker, leading to denial of service.

Exploitability

The vulnerability is rated as Medium severity with a CVSS 3.1 base score of 5.3, indicating it is remotely exploitable with low attack complexity and no privileges required. There is no active exploitation reported via CISA KEV, and EPSS data is not yet available.

Remediation

How to check your project

Automated analysis of the published advisory data, generated 2026-11-20. Not human-reviewed; verify against the official advisory. How this works.

Affected packages

EcosystemPackageAffected versionsFixed inUpgrade
PyPI nltk >= 0, < 3.10.4 3.10.4 python -m pip install 'nltk>=3.10.4'

CVSS 3.1 vector

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

Attack vectorNetwork
Attack complexityLow
Privileges requiredNone
User interactionNone
ScopeUnchanged
ConfidentialityNone
IntegrityNone
AvailabilityLow

FAQ

Does this vulnerability allow for arbitrary code execution?

No. The vulnerability is limited to a Python RecursionError, which results in a denial of service rather than memory corruption or code execution.

Is there a patch available for immediate installation?

The fix is merged into the develop branch (commit e521ecafc), but it has not yet been included in a formal release tag. Version 3.10.4 is identified as the fixed version.

What specifically triggers the denial of service?

The vulnerability is triggered when a deeply nested element tree (built from attacker-supplied input) is passed to one of the public helper functions, such as to_settings_string, remove_blanks, add_default_fields, sort_fields, or add_blank_lines.

Original advisory description
## Root Cause The Toolbox settings-tree helpers recurse over the parsed element tree without any depth bound. `_to_settings_string` (`nltk/toolbox.py:418`), `remove_blanks` (`nltk/toolbox.py:432`), `add_default_fields` (`nltk/toolbox.py:451`), `_sort_fields` (`nltk/toolbox.py:484`), and `add_blank_lines` (`nltk/toolbox.py:502,516`) each recurse once per element level with no depth counter or explicit stack. The producer `ToolboxSettings.parse` builds the element tree iteratively, so nesting depth is driven entirely by attacker-supplied `\+marker` / `\-marker` pairs. ## Impact An application that parses an untrusted Toolbox settings file and then serialises or transforms it through any of the public helper functions aborts with an unhandled `RecursionError`, terminating the affected operation or request worker (denial of service, CWE-674). The recursion is pure Python, yielding a catchable `RecursionError` rather than memory corruption or code execution. Confidentiality and integrity are unaffected. ## Attack Chain 1. The application parses an untrusted settings file via `ToolboxSettings.open_string` / `open` plus `parse`, producing an *N*-deep element tree; parsing is iterative and completes without error. 2. The application passes the tree to a public helper - `to_settings_string`, `remove_blanks`, `add_default_fields`, `sort_fields`, or `add_blank_lines` - as in the module's own parse-then-serialise round trip. 3. The helper recurses once per element level with no depth guard, consuming call-stack frames. This holds even when the helper's configuration dictionaries are empty. 4. Once the nesting depth exceeds the interpreter recursion limit, an unhandled `RecursionError` propagates out of the public API. ## Bypass Evidence Against the shipped source at the default recursion limit, a settings input nested 5 levels deep traverses cleanly through every helper, while a well-formed input nested 5000 levels deep drives each of the five helpers to an unhandled `RecursionError`; the iterative parse builds the 4999-deep tree without error, isolating the fault to the recursive helpers. The config-taking helpers (`add_default_fields`, `sort_fields`, `add_blank_lines`) recurse to failure even with empty configuration dictionaries. A repository-wide search confirms no depth guard exists anywhere in this module. ## Suggested Fix Cap nesting depth at the shared producer `ToolboxSettings.parse` (the choke point that builds the tree), or convert the five helpers to iterative traversals / add a shared recursion-depth bound, so all consumers are protected by one fix. Reported by pi (GitHub: @manus-pi). ## Fix status (2026-09-28) Status: MERGED on develop (unreleased; v3.10.3 of 2026-08-12 predates the fix). PR: #3885 "Bound recursion depth in parsers and traversal helpers" (ekaf), merged 2026-09-11, merge commit e521ecafc on develop. Fix commit: 0b6975377 (nltk/toolbox.py: the settings helpers stop at MAX_TOOLBOX_DEPTH=500 with ValueError). Probe: nltk/test/unit/security_probes/ghsa_f2h2_f4fc_p978.py (added in 2a6704952 on that PR); verdict on develop 2fa3f48fe: FIXED (bounded during parse (ValueError)). Release: none yet; no release tag contains e521ecafc.

References

Source records: GHSA-f2h2-f4fc-p978 (OSV.dev) · EPSS by FIRST, 2026-11-21.