high · 7.5 Patched

NLTK: Unbounded CPU consumption in SteppingRecursiveDescentParser.parse() with ambiguous or self-embedding grammars

CVE-2026-126303 · GHSA-8fx7-8jr8-84rv · GHSA-4hvg-fv5c-9936 · EUVD-2026-125218 · published 13 Nov 2026

How serious is it

  • Severity: high, CVSS score 7.5 out of 10.
  • No exploit prediction (EPSS) score yet.
  • Not on the CISA list of exploited vulnerabilities.
  • No public exploit in Exploit-DB.

Is your app affected by CVE-2026-126303?

Paste this prompt into Claude Code, Cursor or any AI coding tool: it runs a free Shippable scan of your project and fixes what it finds. Built with Lovable, Bolt or v0? Scan your live app. Or upload your package file.

Who is affected

  • nltk (PyPI) <= 3.10.3

How to check

  1. Run pip show nltk in your project to see the installed version, including copies pulled in by other packages.
  2. Or paste your lockfile into the checker: it lists every package with a known vulnerability, this one included.
  3. Or run npx shippable-dev scan localhost:3000 in your project folder. It reads your lockfile and flags this vulnerability along with every other known one.

How to fix

Copies a prompt for Claude Code, Cursor or Codex: it checks your lockfiles for this and upgrades it.
  1. Upgrade nltk to 3.10.4 or later, commit the lockfile and redeploy.
  2. If a vulnerable version was live, check your logs and rotate the secrets that server could read.

The advisory

## Summary `nltk.parse.recursivedescent.SteppingRecursiveDescentParser.parse()` performs an unbounded top-down search over ambiguous or self-embedding context-free grammars with no wall-clock or step limit. An actor who can influence the grammar and supply a short input to a caller that uses this parser can force a single `parse()` call to pin a CPU core indefinitely, producing a denial of service. The related base class `RecursiveDescentParser` gained a `max_time` wall-clock deadline, but the stepping subclass drives its own step loop and never arms or consults that deadline, and its constructor does not accept a `max_time` parameter, so the guard cannot be enabled on this path. ## Root Cause `RecursiveDescentParser` bounds its recursive search inside `_parse`: it arms a wall-clock deadline on the first step and raises `TimeoutError` once `max_time` (default 5.0 seconds) is exceeded. `SteppingRecursiveDescentParser` was designed for interactive single-stepping and overrides both `parse()` and `_parse`. Its `parse()` runs `initialize()` followed by a `while self.step() is not None` loop that never enters the guarded base `_parse`. Its `_parse` override is a state-capturing stub that records history and returns a sentinel, and it never references the inherited `self._parse_deadline` or `self._max_time`. Its `__init__` signature omits `max_time` entirely, so a caller cannot enable or tighten a bound. The security invariant that a single parse must terminate within a bounded time is therefore never enforced on this parser. ```text Affected component: nltk.parse.recursivedescent.SteppingRecursiveDescentParser - parse() nltk/parse/recursivedescent.py:428-433 (drives its own step loop, no bound armed or checked) - _parse() nltk/parse/recursivedescent.py:643-668 (stub override; never consults self._parse_deadline / self._max_time) - __init__() nltk/parse/recursivedescent.py:410-418 (signature (self, grammar, trace=0); no max_time parameter) Base guard for comparison: RecursiveDescentParser._parse nltk/parse/recursivedescent.py:141-150 ``` ## Impact An actor who controls or influences the grammar passed to `SteppingRecursiveDescentParser` and can supply a short token sequence to a caller that invokes `parse()` can cause that call to never return. The top-down search enumerates a derivation space that grows on the order of the Catalan numbers with no memoization of the search and no deadline, so one crafted grammar plus a short input deterministically consumes a CPU core. In a deployment that parses attacker-influenced input on a bounded worker pool, repeated requests exhaust the pool and deny service to legitimate users. No authentication, privilege, or user interaction is required in that worst-credible deployment. Exploitation requires that the target actually use this parser on untrusted input; because the stepping parser is primarily a debugging or interactive-stepping component that backs a GUI, real-world exposure is narrower than for the base parser, though `parse()` is a supported public method that behaves as a full parser. ## Proof of Concept `Requires only the nltk package (3.10.3) and standard library; no data downloads or network access.` Reproduction steps: 1. Build an ambiguous, self-embedding grammar such as `S -> 'a' S S | 'a'`. 2. Confirm the base parser self-terminates: `RecursiveDescentParser(g, max_time=2.0).parse(['a']*17)` raises `TimeoutError` at about 2 seconds. 3. Run the stepping parser on the same grammar and input and observe it never returns. ```python import time, inspect from nltk import CFG from nltk.parse.recursivedescent import RecursiveDescentParser, SteppingRecursiveDescentParser g = CFG.fromstring("S -> 'a' S S | 'a'") # Base parser is bounded and self-terminates. try: list(RecursiveDescentParser(g, max_time=2.0).parse(['a'] * 17)) except TimeoutError: print("base: TimeoutError (guarded)") # Stepping subclass cannot be bounded: no max_time parameter. print("stepping __init__ sig:", inspect.signature(SteppingRecursiveDescentParser.__init__)) # Stepping parser runs unbounded on the same input. t0 = time.perf_counter() list(SteppingRecursiveDescentParser(g).parse(['a'] * 17)) # does not return print("stepping: returned after", time.perf_counter() - t0) ``` ```text base: TimeoutError (guarded) stepping __init__ sig: (self, grammar, trace=0) # stepping len3: 1 parse in 0.001s ; len7: 5 in 0.017s ; len9: 14 in 0.075s ; len11: 42 in 0.36s # stepping len17: still running past a 10s watchdog, process alive, no RecursionError ``` ## Attack Chain 1. **Exposure:** A caller uses `nltk.parse.SteppingRecursiveDescentParser`, a public exported symbol (`nltk/parse/__init__.py:97`), invoking `parse(tokens)` on grammar and input influenced by an actor. 2. **Control:** The actor influences the grammar (an ambiguous, self-embedding CFG such as `S -> 'a' S S | 'a'`) and supplies a short token list (for example 17 copies of `'a'`). Both survive to the parser unchanged. 3. **Path:** `parse()` (`recursivedescent.py:428`) calls `initialize()` then loops `while self.step() is not None`; `step()` (`:479`) calls `match()`/`expand()` (`:552`/`:512`) which call the inherited `_match`/`_expand` (`:172`/`:214`), which resolve `self._parse` by MRO to the subclass stub (`:643`). 4. **Guard:** The `max_time` wall-clock deadline exists only in the base `_parse` (`:141-150`) and is never entered on this path; the stub `_parse` records state and returns without consulting the deadline, and `__init__` exposes no `max_time` to enable a bound. 5. **Primitive:** The unbounded top-down search enumerates a Catalan-number-sized derivation space with no memoization and no deadline. 6. **Result:** The `parse()` call never returns and pins a CPU core; repeated calls exhaust a bounded worker pool, denying service. ## Bypass Evidence The prior fix for this class of issue added a `max_time` wall-clock deadline to the base `RecursiveDescentParser._parse` (`recursivedes…

Check your whole app

Dependencies are only half of it. Free and read-only: before you push, run npx shippable-dev scan localhost:3000 in your project folder, no account needed. For your live app, you prove it's yours with a one-line tag first.

References

Merged from GitHub Advisory Database, OSV, ENISA EUVD. Last updated 18 Nov 2026. All vulnerabilities · RSS · JSON