GitHub advisory · PyPI
NLTK: Uncontrolled recursion in Toolbox settings helpers causes denial of service via deeply nested input
Description
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.
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.
ToolboxSettings.open_string /
open plus parse, producing an N-deep element tree; parsing is iterative and
completes without error.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.RecursionError propagates out of the public API.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…
Manual fix · PyPI
pip install --upgrade "nltk>=3.10.4"Sources