Executive brief
NLTK is a widely-used Python library for natural language processing that includes parsers for analyzing text based on grammars. The RecursiveDescentParser component fails to limit recursive operations when processing certain ambiguous or left-recursive grammars, allowing an attacker to supply a tiny crafted grammar or input that causes the parser to consume unbounded CPU cycles and exhaust the Python call stack, permanently blocking the affected process. This is a single-process availability attack with no data breach or system integrity risk.
Technical details
The RecursiveDescentParser (and SteppingRecursiveDescentParser) in NLTK enumerate parse trees top-down with no upper bound on the number of recursive steps (CWE-407, CWE-674). Two attack patterns are demonstrated: (a) left-recursive grammars (e.g., "S -> S S | 'a'") trigger unbounded recursion depth; (b) ambiguous grammars (e.g., "S -> 'a' S | 'a' S S | 'a'") cause exponential enumeration of parse trees. Both hang on a 24-token input with super-linear growth in input length. Attack vector is network-capable if the grammar or input is drawn from an untrusted source. The fix (in NLTK 3.10.3+) adds a wall-clock max_time limit (default 5 seconds) checked on every recursive _parse entry, protecting by default while allowing opt-out via max_time=None.
Affected products
- NLTK Project NLTK <= 3.10.2
Timeline
- 2026-08-12: disclosed: Published to GitHub Advisory Database
- 2026-08-12: patched: Fix committed; NLTK 3.10.3 released
- 2026-09-02: advisory: Advisory GHSA-ff5c-cp5c-9wjf published
References
- https://github.com/nltk/nltk/security/advisories/GHSA-ff5c-cp5c-9wjf
- https://github.com/nltk/nltk/pull/3649
- https://github.com/nltk/nltk/commit/43aaca1b9024138421c97f970bf13ee19ac8129d
- https://github.com/nltk/nltk/releases/tag/v3.10.3
- https://api.github.com/repos/nltk/nltk/security-advisories/GHSA-ff5c-cp5c-9wjf