NLTK CCG lexicon parser can be made to freeze with large input
What this means
An attacker can send a specially crafted CCG lexicon string to a service that uses NLTK's parser, causing the service to use 100% CPU for tens of seconds and block all requests on that worker. Multiple such requests can lock down an entire service.
SecurityElites Manager Brief: the decision in one minute
NLTK's CCG lexicon parser has two slow loops that waste CPU time proportional to the square of the input size. A attacker who can submit lexicon data to your service can freeze it. Update NLTK to fix this.
| 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 | Platform or infrastructure team that manages Python dependencies |
| Likely effort | About 15 minutes per service: a pip update and a restart. It could take longer if you have pinned NLTK to an older version and need to test for compatibility. |
Questions to ask your team or supplier
- Does our service parse CCG lexicon data from untrusted sources (users, uploads, or external APIs)? If yes, what is the current NLTK version and when can we upgrade?
- Do we have request timeouts or resource limits on lexicon parsing? Should we add them as a defense-in-depth measure?
Message you can forward to the owning team
Security notice: NLTK CCG lexicon parser can be made to freeze with large input (CVE-2026-126299)
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-126299-nltk-ccg-lexicon-parser-can-be-made-to-freeze/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01440What is at stake in your AI setup
- Grammar and lexicon files: an attacker could use this to deny service to NLP tasks that rely on parsing user-supplied grammars.
- Compute resources: CPU time is wasted on parsing, increasing inference costs and slowing down model responses.
Who is exposed
- Services that parse untrusted CCG lexicon text from users or the network.
- Chatbots or NLP pipelines that accept user-supplied grammar definitions.
- Research or demo applications that allow upload of NLTK lexicon files.
- Services that do NOT parse user-supplied lexicon data are not affected.
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 you cannot upgrade NLTK immediately, limit the size of lexicon strings your service accepts: reject any lexicon input longer than a reasonable threshold (e.g., 1 MB).
- If the service receives lexicon data from users, add a timeout wrapper around `nltk.ccg.lexicon.fromstring` and kill the parse if it runs longer than expected (e.g., 5 seconds for normal input).
- Isolate CCG parsing into a separate worker pool or service so that a frozen parse does not block other requests.
Signs it may already have been used against you
- Single-threaded CPU usage at 100% for tens of seconds during or after a CCG lexicon parsing request.
- Timeout or hang errors from `nltk.ccg.lexicon.fromstring` calls, especially during parsing of large or complex lexicon strings.
- In request logs, unusually large lexicon payloads (megabytes) submitted to endpoints that parse lexicon data.
- Thread pool exhaustion: request workers staying in a blocked or busy state and not accepting new requests.
Log searches to start from
Single-threaded CPU spikes during CCG parsing (adapt field names to your logs)Splunk
index=main component=nltk_ccg cpu_usage>90 duration>10 | stats count by src_ip, payload_sizeWritten with AI as a starting point. Review them and change the index and field names to match your own logs before you rely on the result.
SecurityElites Fix Guide: step by step
- Find where NLTK is installedList your Python dependencies. Run `pip list | grep nltk` or check your requirements.txt file.
- Check the current versionNote the version number. If it is 3.10.4 or newer, you are not affected. If it is older than 3.10.4, continue to the next step.
- Review which code calls the CCG lexicon parserSearch your codebase for imports or calls to `nltk.ccg.lexicon.fromstring` or `nltk.ccg.chart.fromstring`. Check whether the input to these functions comes from untrusted sources (users, network requests, uploaded files).
- Back up your current environmentTake a snapshot of your current Python environment or version-control your requirements. This lets you revert if the upgrade causes unexpected issues.
- Upgrade NLTK to 3.10.4 or laterRun `pip install --upgrade nltk>=3.10.4` in your Python environment. If you use a requirements file, update the NLTK version and run `pip install -r requirements.txt`.
- Restart the serviceRestart all running instances of the service to load the new NLTK version.
- Test that the fix worksVerify that your service starts and that normal lexicon parsing still works. Run any existing tests that exercise the CCG parser.
- Check for prior exploitationReview logs from before the upgrade for signs that this was used to attack the service: look for unusually long lexicon strings, sustained high CPU usage on single threads, or timeout errors in CCG parsing. If you find any, investigate whether user accounts or data were accessed.
How to confirm it is fixed: Run `python -c "import nltk; print(nltk.__version__)"` and confirm it is 3.10.4 or newer, then confirm that your service can parse a normal CCG lexicon string without timeout or hang.
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 installed NLTK versionfor this issue
python -c "import nltk; print(nltk.__version__)"Search for CCG lexicon parser calls in a codebasefor this issue
grep -r "fromstring" --include="*.py" | grep -E "(ccg\.lexicon|ccg\.chart)"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-126299) 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 CCG lexicon parser can be made to freeze with large input (CVE-2026-126299)
**Severity:** High | **SE Fix-First Score:** 43/100 | **Fix window:** Within 30 days
**Record:** SE-AIV-01440 https://securityelites.com/ai-vulnerabilities/cve-2026-126299-nltk-ccg-lexicon-parser-can-be-made-to-freeze/
### Why this matters
An attacker can send a specially crafted CCG lexicon string to a service that uses NLTK's parser, causing the service to use 100% CPU for tens of seconds and block all requests on that worker. Multiple such requests can lock down an entire service.
### What to do
1. Find where NLTK is installed
2. Check the current version
3. Review which code calls the CCG lexicon parser
4. Back up your current environment
5. Upgrade NLTK to 3.10.4 or later
6. Restart the service
7. Test that the fix works
8. Check for prior exploitation
Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-126299-nltk-ccg-lexicon-parser-can-be-made-to-freeze/
### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run `python -c "import nltk; print(nltk.__version__)"` and confirm it is 3.10.4 or newer, then confirm that your service can parse a normal CCG lexicon string without timeout or hang.
- [ ] 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 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
- NLTK recursive descent parser can be forced to run forever High · CVE-2026-126303
- 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
- 14 Nov 2026: Made public
- 1 Dec 2026: Published
Official record
## SummaryThe public CCG lexicon parser `nltk.ccg.lexicon.fromstring` parses caller-influenced lexicon text with two pure-Python loops whose cost is quadratic in the input width. A service that parses an untrusted CCG lexicon string can be driven into tens of seconds of single-threaded CPU by a few-megabyte input, starving the request worker. No authentication or user interaction is required.## Root Cause`matchBrackets` consumes a bracket body one character at a time with `inside = inside + rest[0]; rest = rest[1:]`. The `rest = rest[1:]` tail re-slice copies the entire remaining string on every iteration, so a flat bracket body costs O(n^2). `augParseCategory` drives a `while rest != "":` operator loop that re-copies the regular-expression match tail (`rest = app[3]`) once per operator, which is also O(n^2) over a long operator chain. The parser carries a recursion-depth guard (`MAX_PARSE_DEPTH = 500`) that raises on deeply nested categories, but both quadratic loops run on flat input whose nesting depth stays at zero, so that guard never fires. No bound is applied to line length or category width before the text reaches these loops.```text Affected functions: - nltk.ccg.lexicon.matchBrackets (nltk/ccg/lexicon.py:149-172; tail re-slice at line 168) - nltk.ccg.lexicon.augParseCategory (nltk/ccg/lexicon.py:223-268; APP_RE tail re-copy at line 250) Public entry point: nltk.ccg.lexicon.fromstring (nltk/ccg/lexicon.py:271), also re-exported as nltk.ccg.chart.fromstring. ```## ImpactAn attacker who can influence the CCG lexicon string parsed by an application causes sustained single-threaded CPU consumption (availability loss). The vulnerable path is network-reachable (AV:N) and needs no privileges or user interaction (PR:N, UI:N). Because the cost grows quadratically with attacker-chosen input size, a few-megabyte payload costs tens of seconds per core, and a small number of concurrent requests can exhaust worker threads. Confidentiality and integrity are not affected. The NLTK regular-expression wall-clock timeout wraps regex matching only; it does not wrap these pure-Python slicing loops, so it provides no protection here.## Proof of Concept```text Environment: nltk 3.10.3, regex 2026.9.10, CPython. Run the parser on the shipped public API. ``````python import nltk.ccg.lexicon as L# Vector A: flat bracket body -> matchBrackets tail re-slice is O(n^2) n = 400000 lex_a = ":- S\nw => (" + "a" * n + ")\n"# Vector B: long operator chain -> augParseCategory tail re-copy is O(n^2) m = 32000 lex_b = ":- a\nw => " + "a" + "/a" * m + "\n"import time for name, s in (("A", lex_a), ("B", lex_b)): t = time.perf_counter() try: L.fromstring(s) except Exception: pass # downstream parse error is irrelevant; the CPU is already burned print(name, round(time.perf_counter() - t, 3), "s") ``````text Negative control (":- a\nw => (a/a)"): ~0.00007 s Vector A (matchBrackets, flat body): n=50k 0.078s | 100k 0.260s | 200k 1.046s | 400k 2.083s (~4x per doubling => O(n^2)) Vector B (augParseCategory, operators): m=4k 0.078s | 8k 0.215s | 16k 0.485s | 32k 1.329s (super-linear) ```## Attack Chain1. **Exposure:** An application calls the public `nltk.ccg.lexicon.fromstring(lex_str)` (also reachable as `nltk.ccg.chart.fromstring`) on lexicon text the attacker can influence. 2. **Control:** The attacker fully controls the body width (a run of characters inside one bracket) and the operator-chain length; neither is capped by `fromstring`. 3. **Path:** `fromstring` splits input into lines and routes each category through `nextCategory`, which dispatches to `matchBrackets` (Vector A) or into the `augParseCategory` operator loop (Vector B). 4. **Guard:** The only relevant guard is the `MAX_PARSE_DEPTH = 500` recursion-depth check. On flat input the recursion depth is zero, so `if _depth > max_depth` is never reached; the width loops run unbounded. 5. **Primitive:** The tail re-sl
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-126299For 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 2 Dec 2026. Read the vendor advisory before changing a production system.