# CVE-2026-12876: NLTK: Uncontrolled resource consumption in RecursiveDescentParser via ambiguous or left-recursive grammars

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** MEDIUM
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Unknown
- **CWE:** CWE-407, CWE-674
- **Aliases:** GHSA-ff5c-cp5c-9wjf, PYSEC-2026-3869
- **Published:** 2026-09-02T14:33:38.000Z
- **Modified:** 2026-09-10T12:25:59.672Z

## Who should check

- Projects that depend on PyPI package nltk (\< 3.10.3)

## Description

\`nltk.parse.RecursiveDescentParser\` (and \`SteppingRecursiveDescentParser\`) enumerate parses top-down with no bound on the number of recursive steps. A small, crafted context-free grammar makes a short input consume unbounded CPU (and/or exhaust the Python recursion stack), pinning a process indefinitely — a denial of service.

\#\# Proof of concept

Both of the following hang on a 24-token input (killed after 8s; growth is super-linear in input length), on NLTK develop:

\`\`\`python
from nltk import CFG
from nltk.parse import RecursiveDescentParser

\# (a) left recursion -\> unbounded recursion
g = CFG.fromstring("S -\> S S \| 'a'")
list(RecursiveDescentParser(g).parse(\["a"\] \* 24))   \# hangs

\# (b) ambiguous grammar -\> exponential number of parses
g = CFG.fromstring("S -\> 'a' S \| 'a' S S \| 'a'")
list(RecursiveDescentParser(g).parse(\["a"\] \* 24))   \# hangs
\`\`\`

\#\# Impact

An application that runs \`RecursiveDescentParser\` on a grammar (or an input) drawn from an untrusted source can be driven into an unbounded CPU / stack-exhaustion loop by a tiny payload. No confidentiality or integrity impact; single-process availability only.

\#\# Sibling

The RegexpTokenizer ReDoS reported alongside this (CVE-2026-12875) is a different class (caller-supplied regex) and is addressed under GHSA-w3v8-gmh9-3wv7.

## Affected and fixed versions

- PyPI `nltk`: affected \< 3.10.3; fixed 3.10.3 (osv)

## Mitigation

- Upgrade nltk to 3.10.3 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-12876. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-12876.md
Affected: nltk < 3.10.3
Fixed in: 3.10.3

Steps:
1. Search this machine and project for nltk (PyPI): dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-12876 being exploited?

There is no confirmed exploitation: CVE-2026-12876 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known.

### How serious is CVE-2026-12876?

It has no CVSS score yet. Unknown.

### Which versions are affected by CVE-2026-12876?

nltk \< 3.10.3.

### Is there a fix for CVE-2026-12876?

Yes. Fixed in 3.10.3. Upgrade nltk to 3.10.3 or later.

### How do I check if I'm affected by CVE-2026-12876?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/nltk/nltk/security/advisories/GHSA-ff5c-cp5c-9wjf>
- vendor: <https://github.com/advisories/GHSA-ff5c-cp5c-9wjf>
- vendor: <https://nvd.nist.gov/vuln/detail/CVE-2026-12876>
- patch: <https://github.com/nltk/nltk/pull/3649>
- patch: <https://github.com/nltk/nltk/commit/43aaca1b9024138421c97f970bf13ee19ac8129d>
- other: <https://github.com/nltk/nltk>
- other: <https://github.com/nltk/nltk/releases/tag/v3.10.3>
- other: <https://pypi.org/project/nltk>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/GHSA-ff5c-cp5c-9wjf> (license: <https://creativecommons.org/licenses/by/4.0/>)
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/PYSEC-2026-3869> (license: <https://creativecommons.org/licenses/by/4.0/>)

HTML: <https://flawdb.com/CVE-2026-12876> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-12876>
