Executive brief
NLTK's tgrep module processes tree pattern queries used in natural language processing. It accepts user-supplied regular expressions and runs them without protection against pathological patterns, allowing an attacker to craft a single malicious request that causes the application to hang indefinitely and consume 100% CPU. In multi-tenant or web-facing deployments, this blocks service for all other users.
Technical details
The vulnerability is a classic ReDoS (regular expression denial of service) issue in the _tgrep_node_action function within nltk/tgrep.py (around line 320). When a tgrep pattern contains a /regex/ node, the function compiles the embedded regex literal directly with re.compile() and applies it via r.search() against tree node labels without any validation or timeout guard. An attacker who controls the tgrep pattern (via tgrep_positions() or tgrep_compile() exposed to external input) can supply a pattern like /((a+)+)b/ that triggers catastrophic backtracking. The attack requires network access but high attack complexity; no authentication or user interaction needed. A proof-of-concept shows exponential growth in execution time, with n≥35 hanging indefinitely. Fix: upgrade to NLTK 3.10.3 or later, which wraps regex execution in a timeout-guarded mechanism.
Affected products
- NLTK Project NLTK <= 3.10.2
Timeline
- 2026-08-26: disclosed: Published to NVD
- 2026-08-31: disclosed: Published to GitHub Advisory Database
- 2026-08-12: patched: Advisory GHSA-w3v8-gmh9-3wv7 published; fix available in NLTK >= 3.10.3
- 2026-09-02: advisory: Duplicate advisory GHSA-vf76-f5cp-9846 withdrawn