NLTK can overwrite files outside its data folder via hardlinks during package extraction

HighSE Fix-First Score 43/100CVE-2026-128135SE-AIV-01492Reading or writing files it should notAI softwareMade public 20 Nov 2026

Download as PDF

What this means

A person with write access to a shared NLTK data folder can trick the software into overwriting files elsewhere on the system when you download a package. This could corrupt system files, replace configuration files, or take over accounts if key files are overwritten. Any process running NLTK download commands is at risk.

SecurityElites Manager Brief: the decision in one minute

NLTK's download feature can be tricked into writing files outside its intended folder. If your data folder is shared or world-writable, a local attacker can plant a hardlink trap to overwrite system files or credentials. You must upgrade to 3.10.4 immediately if your NLTK data folder is not fully controlled by one trusted user.

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 fixPython and AI platform teams (whoever manages dependencies and runs NLTK setup).
Likely effortAbout 15 minutes per machine: check your NLTK setup, upgrade the package, and verify the fix. This is an estimate; delays happen if you have many machines or if older NLTK versions are pinned in multiple places.

Questions to ask your team or supplier

  • Who has write access to our NLTK data folders, and are those folders on shared or cloud storage where multiple machines use them?
  • Do we run nltk.download() automatically in CI/CD pipelines, containers, or shared environments, and have we tested that the data folder is protected from local write access?

Message you can forward to the owning team

Security notice: NLTK can overwrite files outside its data folder via 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-overwrite-files-outside-its-data-folder-via/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01492

What is at stake in your AI setup

  • Downloaded models and language data: an attacker could replace legitimate model files with malicious or poisoned versions, causing the AI to produce wrong outputs or leak information.
  • Keys for AI provider APIs: if stored near the NLTK data folder, they could be overwritten or exfiltrated.
  • Training or retrieval data: custom datasets stored in the data folder could be replaced with poisoned data, corrupting model outputs.

Map where your company uses AI

Who is exposed

  • Teams running nltk.download() on shared machines or in containers with shared volumes.
  • Any setup where the NLTK data folder (default: ~/nltk_data) is group-writable or world-writable.
  • Development teams using NLTK in Docker or Kubernetes with shared or predictable data paths.
  • Local development machines in offices with physical access or shared user accounts.
  • Single-user machines with NLTK data in a user-only folder are not at risk from other local users.

Upgrades you need

SoftwareAffected versionsMove to
nltk
PyPI
3.9.4 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 beAlready on the machine, or able to get a user to open something on it
Account neededAn ordinary user account
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 changedHigh
Risk of: the service being taken downHigh
Can attackers automate it at scaleNo, according to CISA. Each target needs manual work
How much control an attacker gainsPartial 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 you can upgrade: make your NLTK data folder read-only to other users. Run `chmod 700 ~/nltk_data` on Linux/Mac or restrict folder permissions on Windows to your user only.
  • Do not run nltk.download() on shared machines where other users can write to the data folder. Download packages on a secure machine and copy the data folder.
  • If using a container or shared volume, mount the NLTK data folder as read-only after the initial setup, or run setup in a secure build stage and bake the data into the image.

Signs it may already have been used against you

  • Check system logs (e.g., /var/log/auth.log on Linux) around the time you ran nltk.download() for unexpected file modifications, especially to /etc, /root, or home directories of other users.
  • Look for files in your NLTK data folder with unusual names, very recent timestamps, or link counts > 1 (run `find ~/nltk_data -type f -links +1`).
  • Search for signs of SSH key replacement or sudoers file changes: check /root/.ssh/authorized_keys and /etc/sudoers modification times and content.
  • Review process logs if available: look for nltk.download() or Python extract operations followed by file writes to paths outside the data folder.

Log searches to start from

File open and truncate operations on sensitive paths during NLTK extract (requires process or file access logs; adapt field names for your eSplunk

process=python* OR process=nltk* file_path=/etc/* OR file_path=/root/.ssh/* OR file_path=/home/*/.*ssh* action=open OR action=truncate

Hardlinks created or resolved in NLTK data folder around download time (requires auditd or file integrity logs; adapt field names)Elastic

process.name:python* AND (file.path:*nltk_data* AND (event.action:link_count_changed OR event.action:open_for_write))

Written 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

  1. Find where NLTK is installed and what version you haveOpen a terminal and run `python -c "import nltk; print(nltk.__file__)"` to see the installation path. Run `python -c "import nltk; print(nltk.__version__)"` to see the version. Write down the version number.
  2. Check if your version is affectedIf your version is 3.9.4, 3.10.0, 3.10.1, 3.10.2, or 3.10.3, you are at risk. If your version is 3.10.4 or later, you are already patched.
  3. Check where your NLTK data folder is and who can write to itRun `python -c "import nltk; print(nltk.data.path)"` to see the folder list. For each folder, run `ls -ld /path/to/nltk_data` (or on Windows, check Properties). Look for permissions that say 'group' or 'other' can write. If only your user can write, the risk is low unless you share your account.
  4. If the data folder is shared or group-writable, restrict access immediatelyOn Linux or Mac, run `chmod 700 ~/nltk_data` and `chmod 700 /usr/share/nltk_data` (if it exists and you own it). On Windows, right-click the folder, choose Properties, Security, and remove all users except yourself. This reduces risk while you upgrade.
  5. Upgrade NLTK to version 3.10.4 or laterRun `pip install --upgrade nltk>=3.10.4`. On a system where multiple Python versions exist, make sure you upgrade the one your code uses. If NLTK is pinned in a requirements file, update the pin to `nltk>=3.10.4` and run install again.
  6. Verify the upgrade workedRun `python -c "import nltk; print(nltk.__version__)"` again and confirm it says 3.10.4 or later.
  7. Check for signs that this was exploited before you patchedLook for unexpected files in your NLTK data folder that you did not download, or check system logs for file writes to important files (like /etc/passwd, SSH keys, or config files) around the time you ran nltk.download(). See the detect section for more detail.
  8. Re-run any nltk.download() commands you needNow that you are patched, run your normal NLTK setup or download commands. The hardlink trap will be blocked.

How to confirm it is fixed: Run `python -c "import nltk; print(nltk.__version__)"` and confirm the version is 3.10.4 or later, then run a test nltk.download() to confirm it succeeds without errors.

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 installed NLTK versionfor this issue

import nltk
print(f"NLTK version: {nltk.__version__}")
print(f"Data paths: {nltk.data.path}")

List files in NLTK data folder to spot unexpected additionsfor this issue

find ~/nltk_data -type f -mtime -7 -ls 2>/dev/null | head -20

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 p

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

What is the attack: how does an attacker get the system to write to a file outside the NLTK folder?A good answer: They pre-create a hardlink inside the NLTK data folder that points to a file outside it; when NLTK extracts a package member with that name, it opens the target path without checking for hardlinks, so it truncates and overwrites the outside
Which NLTK versions are safe, and which are vulnerable?A good answer: NLTK 3.9.4 through 3.10.3 are vulnerable; 3.10.4 and later are fixed.
What setup makes you most at risk?A good answer: A shared NLTK data folder (like /usr/share/nltk_data or ~/nltk_data on a shared machine) where multiple users or processes can write, combined with running nltk.download().
What is the immediate step to reduce risk while you upgrade?A good answer: Restrict permissions on the NLTK data folder so only the owner can write (chmod 700 on Linux/Mac, or restrict Windows permissions to your user).

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 can overwrite files outside its data folder via 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-overwrite-files-outside-its-data-folder-via/

### Why this matters
A person with write access to a shared NLTK data folder can trick the software into overwriting files elsewhere on the system when you download a package. This could corrupt system files, replace configuration files, or take over accounts if key files are overwritten. Any process running NLTK download commands is at risk.

### What to do
1. Find where NLTK is installed and what version you have
2. Check if your version is affected
3. Check where your NLTK data folder is and who can write to it
4. If the data folder is shared or group-writable, restrict access immediately
5. Upgrade NLTK to version 3.10.4 or later
6. Verify the upgrade worked
7. Check for signs that this was exploited before you patched
8. Re-run any nltk.download() commands you need

Full steps: https://securityelites.com/ai-vulnerabilities/cve-2026-128135-nltk-can-overwrite-files-outside-its-data-folder-via/

### 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 the version is 3.10.4 or later, then run a test nltk.download() to confirm it succeeds without errors.
- [ ] 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

## 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-128135

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.