# NLTK tgrep regular expression denial of service

Source: https://junglewise.ai/threats/nltk-tgrep-regular-expression-denial-of-service-02fca1b2  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-08-31. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

Severity: medium · CVSS 5.9 · Published 2026-08-31

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.

Technologies: [nltk (PyPI)](https://junglewise.ai/threats/technologies/nltk). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Medium severity, with a CVSS score of 5.9, published 31 August 2026.

**Which products and versions are affected?** nltk (PyPI) <= 3.10.2.

**Is there a fix for This vulnerability?** A patch was published on 2026-08-12: Advisory GHSA-w3v8-gmh9-3wv7 published; fix available in NLTK >= 3.10.3 Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run nltk (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## 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

## References

- [https://github.com/nltk/nltk/security/advisories/GHSA-w3v8-gmh9-3wv7](https://github.com/nltk/nltk/security/advisories/GHSA-w3v8-gmh9-3wv7)
- [https://www.vulncheck.com/advisories/nltk-3.10.2-regular-expression-denial-of-service-via-tgrep](https://www.vulncheck.com/advisories/nltk-3.10.2-regular-expression-denial-of-service-via-tgrep)

## Related threats

- [NLTK WekaClassifier path traversal in model validation](https://junglewise.ai/threats/cve-2026-109956-nltk-through-3-10-3-contains-a-path-traversal-vulnerability-in)
- [NLTK RecursiveDescentParser uncontrolled recursion denial of service](https://junglewise.ai/threats/cve-2026-12876-nltk-recursivedescentparser-uncontrolled-recursion-denial-of)
- [NLTK Downloader hardlink filesystem containment bypass](https://junglewise.ai/threats/nltk-downloader-hardlink-filesystem-containment-bypass-522cb97d)
- [NLTK Pl196xCorpusReader quadratic ReDoS on malformed TEI blocks](https://junglewise.ai/threats/nltk-pl196xcorpusreader-quadratic-redos-on-malformed-tei-blocks-8473e6ef)
- [NLTK path traversal in model-artifact APIs via pathsec bypass](https://junglewise.ai/threats/nltk-path-traversal-in-model-artifact-apis-via-pathsec-bypass-a4651c73)
