NLTK recursive descent parser can be forced to run forever
What this means
An attacker who can control a grammar file or configuration can make a program hang indefinitely on a single parse call, freezing a CPU core and denying service to other work. This affects any application using NLTK to parse text with untrusted or complex grammars.
SecurityElites Manager Brief: the decision in one minute
NLTK's SteppingRecursiveDescentParser can hang indefinitely if given a complex grammar, freezing CPU and denying service. This is high-risk if grammars come from users or untrusted sources. Upgrade to NLTK 3.10.4 immediately.
| SecurityElites Fix-First Score | 43 of 100 Our own ranking of what to fix first. Real attacks count most, then the chance of attack, then severity. |
|---|---|
| SecurityElites fix window | Within 30 days High severity. This is our suggestion from common practice; your own policy comes first. |
| Who should own the fix | Development team and DevOps (whoever manages NLTK dependencies). |
| Likely effort | About 15 minutes: update NLTK to version 3.10.4 and restart the application. Longer if the application pins to an older major version or if you need to test with real-world grammars. |
Questions to ask your team or supplier
- Do we use SteppingRecursiveDescentParser, and if so, where do the grammars it parses come from—are they user-supplied, API-driven, or only internal and trusted?
- Have we seen any unexplained service freezes, CPU spikes, or hanging processes in the last month that could be related to parsing operations?
Message you can forward to the owning team
Security notice: NLTK recursive descent parser can be forced to run forever (CVE-2026-126303)
Severity: High
SecurityElites Fix-First Score: 43 of 100
SecurityElites fix window: Within 30 days
Action: upgrade to nltk 3.10.4 or later.
What we need from you: confirm whether we run this software, who owns it, and the date it will be fixed.
Full guide: https://securityelites.com/ai-vulnerabilities/cve-2026-126303-nltk-recursive-descent-parser-can-be-forced-to-run/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01441What is at stake in your AI setup
- NLP model fine-tuning or training pipelines: if they use this parser on training data, an adversary could halt training by injecting malicious grammars into the training corpus.
- Grammar or language model files used by AI systems: if they can be modified by an attacker, the system could be frozen.
Who is exposed
- Teams running NLP or parsing pipelines that accept grammar files or grammar configuration from users or external sources.
- Applications that use SteppingRecursiveDescentParser for interactive parsing or incremental analysis.
- Services that parse structured data or code using NLTK's recursive descent parser on untrusted input.
Upgrades you need
| Software | Affected versions | Move to |
|---|---|---|
| nltk PyPI | Every version before 3.10.4 | 3.10.4 or later |
Am I affected?
Enter the version you run. Nothing you type is stored.
SecurityElites Developer Brief: the technical picture
| Is it being attacked | Working attack code is public, so expect attacks to follow |
|---|---|
| Where the attacker must be | Anywhere that can reach it over a network, including the internet if it is exposed |
| Account needed | None. No login is needed |
| Does a person have to do something | No. It works without anyone clicking or opening anything |
| How hard it is to do | Easy. It works reliably once the attacker can reach it |
| Risk of: data being read | None |
| Risk of: data or settings being changed | None |
| Risk of: the service being taken down | High |
| Can attackers automate it at scale | Yes, according to CISA |
| How much control an attacker gains | Partial control, according to CISA |
Read from the official severity rating: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Kind of coding mistake
- CWE-400: resources can be exhausted
- CWE-407
Where it sits in the standards
OWASP Top 10 for LLM Applications 2025: LLM10 Unbounded Consumption
If you cannot upgrade today
- If upgrade is not possible immediately, avoid using SteppingRecursiveDescentParser with grammars you do not fully control or trust. Use the base RecursiveDescentParser with its default max_time parameter (5 seconds) instead.
- If you must use SteppingRecursiveDescentParser, validate and simplify grammars before parsing, and wrap the parse() call in a thread or subprocess with an explicit timeout using Python's threading or multiprocessing modules.
Signs it may already have been used against you
- CPU core pinned at 100% for an extended period with no I/O, particularly during parsing operations or when grammars are loaded.
- Application process marked as hung or unresponsive during a parse call, with no timeout or crash logged.
- Unusual or complex grammar files loaded shortly before a service freeze or high CPU event.
- System monitoring showing a single Python process thread at 100% CPU with no exit, terminated only by a manual kill or timeout.
SecurityElites Fix Guide: step by step
- Find where NLTK is installedCheck all Python environments and virtual environments in use. Run `pip show nltk` in each to record the current version. Also search your requirements files, setup.py, and pyproject.toml for nltk entries.
- Check if SteppingRecursiveDescentParser is usedSearch your codebase for imports of `SteppingRecursiveDescentParser` from `nltk.parse.recursivedescent`. If you find none, the risk is lower but you should still upgrade. If you find uses, note which services or scripts call it.
- Check if grammars come from untrusted sourcesReview code that creates or loads grammar objects passed to the parser. If the grammar comes from a user upload, API endpoint, config file, database, or any source outside your control, the risk is high. Document where grammars originate.
- Upgrade NLTK to version 3.10.4Update the NLTK package to version 3.10.4 in all Python environments. Use `pip install --upgrade nltk==3.10.4` or update your requirements file and redeploy.
- Verify the upgradeRun `pip show nltk` to confirm version 3.10.4 is installed. Restart any running services or applications that use NLTK. No further action is needed to test; the fix is in the library code.
- Review recent logs for signs of exposureCheck application logs and system resource logs (CPU usage, process hang times) for the last 30 days. Look for single parse calls that consumed 100% of a CPU core for unusual lengths of time, or for hung processes involving NLTK.
- If SteppingRecursiveDescentParser was used with untrusted grammars before upgrade, assess If the parser was used on user-supplied grammars before this fix, review access logs to see who could have supplied grammars. Check if there were unexplained service freezes or CPU spikes that may indicate exploitation. Plan to audit grammar sources going forward.
How to confirm it is fixed: Run `pip show nltk` and confirm the Version field shows 3.10.4 or later.
SecurityElites Quick Fixes: copy and paste
Upgrade nltk with pipupgrade
pip install --upgrade "nltk>=3.10.4"
pip show nltk | grep VersionPin it in requirements.txtupgrade
nltk>=3.10.4Check NLTK version installedfor this issue
pip show nltk | grep VersionSearch codebase for SteppingRecursiveDescentParser usagefor this issue
grep -r "SteppingRecursiveDescentParser" --include="*.py" .Rate and size limits with nginxgeneral hardening
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
server {
location /api/ {
limit_req zone=api burst=20 nodelay;
client_max_body_size 2m;
}
}Test in a non-production environment first. General hardening examples use placeholder names and ports; change them to match your setup.
Let your AI coding assistant do the upgrade
Paste this into the coding assistant you already use, inside the project. It checks first and asks before it changes anything.
Instruction for your coding assistant
You are helping me fix a security vulnerability (CVE-2026-126303) in this project.\n\n1. Search the whole repository, including lock files, container files and CI configuration, for these packages and list every place they are pinned or installed:\n - nltk (PyPI): must be 3.10.4 or later
2. Tell me which version we use now and whether it is affected. Stop and ask me before changing anything.
3. After I agree, raise each one to the safe version, update the lock files, and keep every other dependency as it is.
4. Run the tests and tell me what failed.
5. Give me a short summary of the files you changed that I can put in the pull request.SecurityElites Incident Drill: could your team handle this?
Four questions to ask in your next team meeting. If any has no clear answer, that is the gap to close.
Ticket for your backlog
Paste into Jira, GitHub Issues or any tracker that reads Markdown.
Ready-made ticket
## NLTK recursive descent parser can be forced to run forever (CVE-2026-126303)
**Severity:** High | **SE Fix-First Score:** 43/100 | **Fix window:** Within 30 days
**Record:** SE-AIV-01441 https://securityelites.com/ai-vulnerabilities/cve-2026-126303-nltk-recursive-descent-parser-can-be-forced-to-run/
### Why this matters
An attacker who can control a grammar file or configuration can make a program hang indefinitely on a single parse call, freezing a CPU core and denying service to other work. This affects any application using NLTK to parse text with untrusted or complex grammars.
### What to do
1. Find where NLTK is installed
2. Check if SteppingRecursiveDescentParser is used
3. Check if grammars come from untrusted sources
4. Upgrade NLTK to version 3.10.4
5. Verify the upgrade
6. Review recent logs for signs of exposure
7. If SteppingRecursiveDescentParser was used with untrusted grammars before upgrade, assess
Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-126303-nltk-recursive-descent-parser-can-be-forced-to-run/
### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run `pip show nltk` and confirm the Version field shows 3.10.4 or later.
- [ ] Logs were checked for signs of earlier use
SecurityElites Fix Tracker
Record who owns this fix, the date it is due and when it is done, and see everything still open in one list. Free with a SecurityElites account.
Related vulnerabilities
In the same software
- NLTK can overwrite files outside its data folder via hardlinks during package extraction High · CVE-2026-128135
- NLTK can run untrusted Java code even after security fix in 3.10.3 Critical · CVE-2026-128138
- NLTK XML parser can be made to freeze by reading a crafted corpus file High · CVE-2026-128139
- NLTK dependency parser crashes on long sentences High · CVE-2026-129222
- NLTK WordNet tree methods can run out of memory with deep relation chains High · CVE-2026-129223
- NLTK regex compilation denial of service via many groups High · CVE-2026-129229
The same kind of mistake in other AI tools
- NLTK CCG lexicon parser can be made to freeze with large input High · CVE-2026-126299
- NLTK tree normalizer hangs on wide trees High · CVE-2026-126298
- NLTK CoNLL reader can be made to consume CPU when reading malicious corpus files High · CVE-2026-126297
- n8n Git node can freeze the instance with a crafted path High · CVE-2026-86081
- n8n Edit Fields node can crash the whole instance with a bad field name High · CVE-2026-72749
Change history
- 13 Nov 2026: Made public
- 1 Dec 2026: Published
- 3 Dec 2026: Guide updated
Official record
## 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 ```## ImpactAn 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, SteppingRecursiveDescentParserg = 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("stepp
Weakness type: CWE-400, CWE-407
Use this record in your own tools
Get this record as JSON
curl https://securityelites.com/wp-json/se-aivd/v1/vulns/CVE-2026-126303For scanners and pipelines: OSV format · CycloneDX format · API guide · Email alerts · Fix tracker
The plain-language sections were written with AI from the official record, and the upgrade versions come directly from the official data. Last updated 3 Dec 2026. Read the vendor advisory before changing a production system.