NLTK XML parser can be made to freeze by reading a crafted corpus file

HighSE Fix-First Score 43/100CVE-2026-128139SE-AIV-01467Denial of service and resource exhaustionAI softwareMade public 20 Nov 2026

Download as PDF

What this means

An attacker who can place a malicious XML corpus file where a user will read it can freeze one CPU core for minutes or hours, depending on file size. This stops the application from responding to other requests. In a service, this can cause downtime affecting many users.

SecurityElites Manager Brief: the decision in one minute

NLTK's XML corpus reader has a performance flaw that lets an attacker freeze the application by supplying a specially crafted XML file. Users who process untrusted XML corpora are at risk. Update NLTK to the fixed version as soon as possible.

SecurityElites Fix-First Score43 of 100
Our own ranking of what to fix first. Real attacks count most, then the chance of attack, then severity.
SecurityElites fix windowWithin 30 days
High severity. This is our suggestion from common practice; your own policy comes first.
Who should own the fixThe team that manages Python dependencies and machine learning libraries.
Likely effortAbout 10 minutes per service: check the installed version, update NLTK to 3.10.4, test it, and restart. It may take longer if you have many services or if you need to test with real corpus data.

Questions to ask your team or supplier

  • Do we ever process XML corpus files from users, customers, or untrusted sources, and if so, which services do that?
  • Have we seen any unexplained CPU spikes or hangs when loading large XML corpora in the past few months?
  • Do our systems monitor for one CPU core pinned at 100% for an extended time, and if not, should we add that alert?

Message you can forward to the owning team

Security notice: NLTK XML parser can be made to freeze by reading a crafted corpus file (CVE-2026-128139)

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-128139-nltk-xml-parser-can-be-made-to-freeze-by/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01467

What is at stake in your AI setup

  • Training or retrieval data: an attacker could cause the system to freeze while loading corpus data, disrupting training or retrieval pipelines
  • The compute bill: wasted CPU time from the freeze could lead to unnecessary cloud computing charges
  • Tools and systems an agent is connected to: if the NLP system is part of a larger agent or pipeline, a freeze here can block other work

Map where your company uses AI

Who is exposed

  • Teams running NLP or machine learning systems that read XML corpus files from users or untrusted sources
  • Services using NLTK's NPSChatCorpusReader or FramenetCorpusReader
  • Applications that call XMLCorpusView directly
  • Teams running NLTK versions 3.6 through 3.10.3
  • Services that only read built-in or verified corpus files are not affected

Upgrades you need

SoftwareAffected versionsMove to
nltk
PyPI
3.6 up to, but not including, 3.10.43.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 attackedWorking attack code is public, so expect attacks to follow
Where the attacker must beAnywhere that can reach it over a network, including the internet if it is exposed
Account neededNone. No login is needed
Does a person have to do somethingNo. It works without anyone clicking or opening anything
How hard it is to doEasy. It works reliably once the attacker can reach it
Risk of: data being readNone
Risk of: data or settings being changedNone
Risk of: the service being taken downHigh
Can attackers automate it at scaleYes, according to CISA
How much control an attacker gainsPartial 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

  • Until you can upgrade, limit the size of XML corpus files you will accept or process, and set a timeout on any code that reads them
  • If possible, pre-process or validate corpus XML files outside NLTK before passing them to the reader
  • Avoid using XMLCorpusView, NPSChatCorpusReader, or FramenetCorpusReader on untrusted or user-supplied XML files

Signs it may already have been used against you

  • Watch for one CPU core pinned at 100% while an XML corpus file is being read, especially if the file size is unusually large
  • Look for requests that time out or hang while NLTK is processing XML corpora
  • Check if the process consuming CPU is running Python code in the NLTK xmldocs module
  • If you see a consistent delay that grows with corpus file size, that is a sign of the quadratic slowdown

SecurityElites Fix Guide: step by step

  1. Find where NLTK is installedList all Python environments and virtual environments in use. Check which ones have NLTK installed and note the version. Use pip list or check requirements files.
  2. Check the current NLTK versionRun python -c "import nltk; print(nltk.__version__)" in each environment. If the version is 3.6, 3.7, 3.8, 3.9, 3.10.0, 3.10.1, 3.10.2, or 3.10.3, the system is affected.
  3. Back up your workIf you have custom code that uses XMLCorpusView, NPSChatCorpusReader, or FramenetCorpusReader, save a copy of that code and any test files you use.
  4. Update NLTK to version 3.10.4In each affected Python environment, run: pip install --upgrade nltk==3.10.4. Wait for the installation to finish.
  5. Verify the fix is installedRun python -c "import nltk; print(nltk.__version__)" again and confirm it shows 3.10.4 or later.
  6. Test with your corpus filesIf you use custom XML corpora, re-run your normal tests to ensure they still work. Pay attention to load times and check that no process hangs.
  7. Restart affected servicesRestart all applications or services that use NLTK so they load the new version. Watch system CPU usage for a few minutes to confirm it stays normal.
  8. Check if you were affected beforeReview logs from before the update to see if any process consumed 100% of one CPU core for an unusual length of time. If yes, an attacker may have tried to freeze your service.

How to confirm it is fixed: Run a test that loads an XML corpus file and confirm it completes in reasonable time (similar to before), and verify that python -c "import nltk; print(nltk.__version__)" 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 Version

Pin it in requirements.txtupgrade

nltk>=3.10.4

Check NLTK versionfor this issue

python -c "import nltk; print('NLTK version:', nltk.__version__)"

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-128139) 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.

What is the root cause of the slowdown in NLTK's XML corpus reader?A good answer: The code re-runs a full validation regex against the entire buffer after every 1 KiB chunk, which causes the time to grow as the square of the file size when a large comment or CDATA section is present.
Which NLTK corpus readers are most at risk?A good answer: NPSChatCorpusReader and FramenetCorpusReader are built on XMLCorpusView and inherit the flaw, as well as any direct use of XMLCorpusView.
What type of file content triggers the vulnerability?A good answer: A well-formed XML file with one large comment or CDATA section can freeze the reader because the validation loop runs many times before finding the end of the comment or CDATA.
What is the first step to protect your services?A good answer: Identify all services running NLTK versions 3.6 through 3.10.3 and update them to version 3.10.4 as soon as possible.

Run a full timed drill with your team

Ticket for your backlog

Paste into Jira, GitHub Issues or any tracker that reads Markdown.

Ready-made ticket

## NLTK XML parser can be made to freeze by reading a crafted corpus file (CVE-2026-128139)

**Severity:** High  |  **SE Fix-First Score:** 43/100  |  **Fix window:** Within 30 days
**Record:** SE-AIV-01467 https://securityelites.com/ai-vulnerabilities/cve-2026-128139-nltk-xml-parser-can-be-made-to-freeze-by/

### Why this matters
An attacker who can place a malicious XML corpus file where a user will read it can freeze one CPU core for minutes or hours, depending on file size. This stops the application from responding to other requests. In a service, this can cause downtime affecting many users.

### What to do
1. Find where NLTK is installed
2. Check the current NLTK version
3. Back up your work
4. Update NLTK to version 3.10.4
5. Verify the fix is installed
6. Test with your corpus files
7. Restart affected services
8. Check if you were affected before

Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-128139-nltk-xml-parser-can-be-made-to-freeze-by/

### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run a test that loads an XML corpus file and confirm it completes in reasonable time (similar to before), and verify that python -c "import nltk; print(nltk.__version__)" 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.

Sign in to track this fix

Change history

  • 19 Nov 2026: Made public
  • 1 Dec 2026: Published

Official record

> **affected**: PyPI `nltk` `>= 3.6` — `nltk.corpus.reader.xmldocs.XMLCorpusView` streaming read (and the `nps_chat` / `framenet` readers built on it) > **dynamically reproduced**: `3.6` (6/6 checks), `3.9.2` (6/6), `3.10.3` (6/6) and `develop` `6818767b9` (6/6)---_Source references (`nltk/corpus/reader/xmldocs.py:NNN`) are to commit `6818767b99c24659107eb2be9bccd32a3d4bf045` (`develop`, `v3.10.3-15-g6818767b9`). The released `v3.10.3` wheel's `xmldocs.py` is byte-identical to that commit, so the same line numbers apply to the released wheel._### Summary**An attacker who can make a victim read a well-formed XML corpus file whose body contains one large comment or CDATA section can pin a CPU core for a time quadratic in the file size, because `XMLCorpusView._read_xml_fragment` (`nltk/corpus/reader/xmldocs.py`) re-runs a linear whole-buffer validation after every 1 KiB block while the comment/CDATA terminator is still ahead.** `XMLCorpusView` is NLTK's documented streaming API for XML corpora and is instantiated directly by the `NPSChatCorpusReader` and `FramenetCorpusReader` readers; the module header (`xmldocs.py:16-20`) explicitly handles untrusted corpus XML. The `in_tag` guard added to this function for GHSA-vp2x covers only a single oversized `<...>` tag and leaves the CDATA/comment path quadratic in the current release.### DetailsRoot cause: `_read_xml_fragment` (`xmldocs.py:273-338`) accumulates the file into one `fragment` string in `_BLOCK_SIZE` (1024) character chunks (`xmldocs.py:123, 298-299`). After every block that is not yet a well-formed prefix, the fragment is re-validated against `_VALID_XML_RE`. Two whole-buffer operations dominate:```python # xmldocs.py:308 if not in_tag and self._VALID_XML_RE.match(fragment): # whole-buffer match (O(len)) return fragment # xmldocs.py:312 if re.search("[<>]", fragment).group(0) == ">": # O(1) for this input class: ... # the document starts with '<' # xmldocs.py:329 if self._VALID_XML_RE.match(fragment[:last_open_bracket]): # whole-buffer prefix match (O(len)) ... ```For this input class the `re.search` probe at `xmldocs.py:312` is O(1): the fragment always starts with `<` (e.g. `<root>…`), so the first `<`/`>` character is at offset 0 and it never contributes cost. The quadratic cost comes entirely from the two whole-buffer regex matches at `xmldocs.py:308` and `xmldocs.py:329` (the latter scans the buffer up to the most recent `<`, which for this input sits near the end of the buffer).`_VALID_XML_RE` (`xmldocs.py:238-249`) is a *linear* regex (its tempered-dot comment/CDATA bodies `(?:(?!-->).)*` / `(?:(?!\]\]>).)*` scan left-to-right in O(length) — confirmed by the embedded script's single-match check), but for a fragment whose terminator is far ahead the *match itself fails after scanning the whole buffer*. With an unclosed-across-blocks CDATA or comment, **every one of the n/1024 blocks** pays O(current buffer length) on lines 308 and 329, for a total of ~O(n²) character operations.The `in_tag` guard added for GHSA-vp2x (`xmldocs.py:283-305`) tracks only bare `<`/`>` characters: it is `True` inside an unclosed `<...>` tag and, in that state, skips only the line-308 match. It never represents "the fragment sits inside an unclosed CDATA or comment" — XML allows arbitrary `<`/`>` inside those constructs — so both the line-308 match and the line-329 backtrack match still fire on every block for a CDATA/comment fragment. The comment block at `xmldocs.py:283-289` even documents the intended linearity contract ("re-running it on every 1 KiB block otherwise makes a single oversized tag O(n^2) (CWE-407)"); the guard implements it for the tag branch only.The single-match cost is linear, not super-linear: the embedded script measures `_VALID_XML_RE.match()` on 512 KiB → 1 MiB → 2 MiB unclosed-CDATA buffers and gets ≈ 0.074 s → 0.142 s → 0.280 s (≈ 1:1.9:3.8, i.e. linear), asserting

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

For 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 1 Dec 2026. Read the vendor advisory before changing a production system.