NLTK can write files outside its data directory through hardlinks during package extraction
What this means
A local attacker who can write files to a shared NLTK data directory can place a hardlink that points outside that directory. When a victim runs nltk.download() to install a package, the extraction process follows the hardlink and overwrites files outside the intended data directory. This could compromise system files, application code, or other sensitive data on the same machine or container.
SecurityElites Manager Brief: the decision in one minute
NLTK's download and extract functions can be tricked into writing files outside their intended directory if an attacker plants hardlinks in a shared data folder. This affects versions 3.9.4 through 3.10.3. Any system where multiple users or processes share an NLTK data directory is at risk of file corruption or takeover.
| 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 application team that manages Python dependencies and NLTK installations. |
| Likely effort | About 15 minutes per machine: update the nltk package to version 3.10.4 and restart any applications that use nltk. Time could increase if nltk is pinned in multiple dependency lists or if many machines need updating. |
Questions to ask your team or supplier
- Do we use nltk.download() at runtime, and if so, in which applications and how often? Are those applications running in shared environments?
- Who has write access to our NLTK data directories today, and is that intentional? Should we restrict it to specific service accounts?
- If this vulnerability was exploited against us, what files outside the NLTK data directory could an attacker have damaged or replaced?
Message you can forward to the owning team
Security notice: NLTK can write files outside its data directory through hardlinks during package extraction (CVE-2026-128135)
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-128135-nltk-can-write-files-outside-its-data-directory-through/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01492What is at stake in your AI setup
- NLTK model and data files: an attacker could replace legitimate trained models or corpora with malicious versions, causing NLP pipelines to fail or produce incorrect results.
- Training or retrieval data: if training datasets are stored in or near the NLTK data directory, they could be corrupted or replaced with poisoned data.
- Application code and scripts that use NLTK: if these are stored in a directory accessible through the data root, they could be overwritten with malicious versions.
Who is exposed
- Teams running NLTK in shared environments (shared servers, containers, or groups of machines with shared home directories).
- Systems where the NLTK data directory is group-writable or in a predictable location like ~/nltk_data.
- Applications that call nltk.download() to fetch packages at runtime without validating the installation destination.
- Container setups where multiple services or pods mount the same NLTK data volume.
Upgrades you need
| Software | Affected versions | Move to |
|---|---|---|
| nltk PyPI | 3.9.4 up to, but not including, 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 | Already on the machine, or able to get a user to open something on it |
| Account needed | An ordinary user account |
| 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 | High |
| Risk of: the service being taken down | High |
| Can attackers automate it at scale | No, according to CISA. Each target needs manual work |
| How much control an attacker gains | Partial control, according to CISA |
Read from the official severity rating: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H
Kind of coding mistake
- CWE-59
- CWE-73
If you cannot upgrade today
- Until the upgrade is complete, make NLTK data directories private (permissions 700) so only the owner can write to them. If NLTK data must be shared, use a dedicated, isolated account for running nltk.download() and restrict all other acces
- Avoid calling nltk.download() at runtime in multi-user or container environments. Instead, pre-download packages in a secure environment and bake them into the application image or deploy them separately.
- Use security tools like AppArmor or SELinux to restrict the NLTK process from writing to any file outside the designated data directory, as a defense-in-depth layer.
Signs it may already have been used against you
- Review filesystem audit logs for open and write events on files outside the NLTK data directory during Python processes running nltk.download().
- Use find to search for hardlinks in NLTK data directories: find ~/nltk_data -type f -links +1 will show any files with more than one link (hardlinks planted by an attacker).
- Check modification times on critical system files or application code that share a filesystem with NLTK data, looking for unexpected changes around the time nltk.download() was run.
Log searches to start from
File open and write events on NLTK data directory pathsElastic
process.name:python* AND (file.path:*/nltk_data/* OR file.path:*/nltk/* OR process.args:*nltk.download*) AND event.action:(open OR write OR truncate) | stats count by file.path, process.pidUnexpected file modifications outside NLTK data directory during Python process activitySplunk
process=python* nltk.download file_action=write OR file_action=truncate NOT file_path=*nltk_data* | stats count, latest(_time) by file_path, process_idWritten 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 installedCheck all Python environments and virtual environments on affected systems. Use pip show nltk to find the version and location, or grep for import nltk in application code to find which projects use it.
- Check the current versionRun python -c "import nltk; print(nltk.__version__)" in each environment. Write down every version you find that is 3.9.4 or higher but lower than 3.10.4.
- Find shared or predictable NLTK data directoriesCheck whether NLTK data is stored in a shared location by running python -c "import nltk; print(nltk.data.path)" in each application. Look for directories like ~/nltk_data, /usr/share/nltk_data, or container volumes that multiple users or processes can write to.
- Review access permissions on data directoriesList permissions on each NLTK data directory using ls -ld. If any directory is writable by a group or by other users (permissions like 777, 755 for group-writable, or g+w), that system is at risk.
- Upgrade NLTK to version 3.10.4Update the package using pip install --upgrade nltk==3.10.4 (or your package manager equivalent) in each affected Python environment. Confirm the upgrade by running python -c "import nltk; print(nltk.__version__)" and verifying it shows 3.10.4 or later.
- Restart affected applicationsRestart any service, application, or daemon that imports or uses nltk to ensure it loads the updated version. Check application logs or status to confirm they started successfully.
- Check for signs of prior exploitationReview system logs and file access logs for the NLTK data directory. Look for unexpected file writes, file truncations, or modifications to files outside the NLTK data directory that happened around the time nltk.download() was called. Check the modification time of any critical files in directories that share a data root.
- Restrict NLTK data directory permissionsIf the NLTK data directory is shared, change permissions to 700 (owner only) or 750 (owner and specific group) using chmod. Document who needs write access and grant it only to those users or service accounts.
How to confirm it is fixed: Confirm the system is patched by running python -c "import nltk; print(nltk.__version__)" and verifying the version is 3.10.4 or higher in all affected environments.
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
import nltk
print(f"NLTK version: {nltk.__version__}")
print(f"Data paths: {nltk.data.path}")List permissions on NLTK data directoriesfor this issue
ls -ld ~/nltk_data 2>/dev/null || echo "Default NLTK data directory not found"
ls -ld /usr/share/nltk_data 2>/dev/null || echo "System NLTK data directory not found"Keep file access inside one directory (Python)general hardening
from pathlib import Path
BASE = Path("/srv/app/data").resolve()
def safe_path(name: str) -> Path:
p = (BASE / name).resolve()
if not p.is_relative_to(BASE):
raise ValueError("path outside allowed directory")
return pTest 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-128135) 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 can write files outside its data directory through hardlinks during package extraction (CVE-2026-128135)
**Severity:** High | **SE Fix-First Score:** 43/100 | **Fix window:** Within 30 days
**Record:** SE-AIV-01492 https://securityelites.com/ai-vulnerabilities/cve-2026-128135-nltk-can-write-files-outside-its-data-directory-through/
### Why this matters
A local attacker who can write files to a shared NLTK data directory can place a hardlink that points outside that directory. When a victim runs nltk.download() to install a package, the extraction process follows the hardlink and overwrites files outside the intended data directory. This could compromise system files, application code, or other sensitive data on the same machine or container.
### What to do
1. Find where NLTK is installed
2. Check the current version
3. Find shared or predictable NLTK data directories
4. Review access permissions on data directories
5. Upgrade NLTK to version 3.10.4
6. Restart affected applications
7. Check for signs of prior exploitation
8. Restrict NLTK data directory permissions
Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-128135-nltk-can-write-files-outside-its-data-directory-through/
### Done when
- [ ] nltk is at 3.10.4 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Confirm the system is patched by running python -c "import nltk; print(nltk.__version__)" and verifying the version is 3.10.4 or higher in all affected environments.
- [ ] 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 run untrusted Java code through command arguments Critical · CVE-2026-128138
- NLTK XML corpus reader CPU exhaustion with large comments or CDATA High · CVE-2026-128139
- NLTK dependency parser crashes on long sentences High · CVE-2026-129222
- NLTK WordNet methods can be made to exhaust the call stack High · CVE-2026-129223
- NLTK regex patterns can be made to freeze the server High · CVE-2026-129229
- NLTK can run attacker-controlled programs from the current directory High · CVE-2026-129234
The same kind of mistake in other AI tools
- Nik Voice Ticketing AI allows upload and run of harmful files without login Critical · CVE-2026-143966
- MLflow can read files outside its data folder via model version prompts High · CVE-2026-116690
- LiteLLM proxy can be made to read local files by authenticated users High · GHSA-g5ff-637f-6q2m
- MLflow can write files outside the trace directory via crafted trace ID High · CVE-2026-53995
- Flowise can run commands and read files outside its sandbox Critical · CVE-2026-119978
Change history
- 19 Nov 2026: Made public
- 1 Dec 2026: Published
- 3 Dec 2026: Guide updated
Official record
## SummaryNLTK ships a security wrapper, `nltk.pathsec.ZipFile`, that is meant to confine archive extraction to trusted data roots and to block link-based escapes. When `nltk.download()` installs a package, the extraction write opens each member's target path without checking whether that path is a hardlink to a file located outside the data root. A local actor who can write inside a shared or predictable NLTK data root (for example `~/nltk_data`, a group-writable `/usr/share/nltk_data`, or a shared container volume) can pre-plant an in-root hardlink at a member path that a soon-to-be-installed package will write. When the victim later runs the download, extraction truncates and overwrites the outside-root target through that hardlink. This is the same weakness class as the previously fixed downloader hardlink issue, but the fix did not reach the package-extraction write sink, so the latest published release remains exploitable through this path.## Root CauseThe prior fix added an `st_nlink > 1` refusal to the file-open helpers (`nltk.pathsec.open` / `_hardened_open`) and routed the downloader temporary-file write through that hardened opener, so a multiply-linked inode is refused on those paths. The extraction write sink was never given the same check. On published releases, `nltk.pathsec.ZipFile.extract` validates member names with `validate_zip_archive` and then delegates to the standard library extractor, whose plain `open(targetpath, "wb")` opens and truncates a pre-existing hardlink. The containment guard `validate_zip_archive` relies on `Path.resolve()` and name checks; `resolve()` follows symlinks (so a symlinked member is correctly refused) but a hardlink has a legitimate in-root name and in-root resolved path, so it passes. No code on the extraction path performs the `st_nlink` fstat that the sibling open helper performs.```text Affected component: nltk.pathsec (archive extraction), driven by nltk.downloader Released sink (<= 3.10.3): nltk/pathsec.py ZipFile.extract -> stdlib zipfile._extract_member -> open(targetpath, "wb") Containment guard that fails open for hardlinks: nltk/pathsec.py validate_zip_archive (name checks + Path.resolve()) Development-branch sink: nltk/pathsec.py ZipFile._extract_member leaf reopen with O_WRONLY|O_TRUNC|O_NOFOLLOW (no st_nlink fstat) ```## ImpactAn unprivileged local user who can create a file inside a data root that the victim's NLTK installation will extract into can cause the victim's process to truncate and overwrite a file outside that root. The attacker chooses which outside file is destroyed by selecting the hardlink target, so the integrity impact is complete for the chosen path (arbitrary outside-root file destruction). Where the victim resolves packages through an attacker-influenced mirror or index, the overwritten bytes are also attacker-chosen, which plausibly enables targeted file replacement and later code execution if the victim subsequently consumes the replaced file; that escalation is plausible rather than demonstrated here. Practical exploitation requires either that kernel hardlink protection (`fs.protected_hardlinks`) is disabled, or that the outside target is one the planting actor is permitted to hardlink (owned, writable, or group-shared), which is the same precondition carried by the previously accepted advisory for this weakness class.## Proof of Concept`Dependencies: a released nltk (3.10.3) installed from PyPI. The demonstration creates a data root, a victim file outside it, and a package archive whose member path is pre-planted as a hardlink to the victim file, then extracts through the security wrapper. It runs as a single user and succeeds even with fs.protected_hardlinks=1.`Steps: 1. Register a data root with `nltk.data.path` and create an extraction subtree inside it. 2. Create a victim file outside the data root. 3. Pre-plant an in-root hardlink at the member path the archive will write. 4. Extract the archive through `nltk.pathsec
Weakness type: CWE-59, CWE-73
Use this record in your own tools
Get this record as JSON
curl https://securityelites.com/wp-json/se-aivd/v1/vulns/CVE-2026-128135For 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 4 Dec 2026. Read the vendor advisory before changing a production system.