CVE-2026-70626: NLTK before 3.9.4 Symlink Escape via CorpusReader
Summary nltk.corpus.reader.api.CorpusReader.open() can be used to read files outside the intended corpus root via a symlink placed inside that root. Although NLTK blocks absolute paths and .. traversal, the current boundary check is only lexical and does not account for symlink resolution. This leads to an arbitrary local file read / filesystem sandbox bypass for applications that rely on CorpusReader or FileSystemPathPointer to restrict file access.
Details The vulnerable flow is:
- nltk/corpus/reader/api.py:222 - CorpusReader.open() blocks absolute paths and .., then calls self.root.join(file).open()
- nltk/data.py:398 - FileSystemPathPointer.join() joins the requested file ID and checks whether the resulting path still appears to remain under the configured root
The problem is that the check is based on the lexical path after os.path.normpath(), not on the resolved path after following symlinks.
Current behavior:
1. CorpusReader.open() rejects: - absolute paths - .. path traversal 2. FileSystemPathPointer.join() computes: - joined = os.path.normpath(os.path.join(self.path, fileid)) - root = os.path.normpath(self.path) 3. It allows the access if joined starts with root
This misses the case where a path stays inside the root lexically, but resolves outside the root via a symlink already present under the allowed directory.
Example:
text JOINED=/tmp/nltk-root/link/secret.txt REALPATH=/tmp/outside/secret.txt
JOINED still appears to be inside the root, but REALPATH is outside it.
This is distinct from simple ../ traversal:
- the file ID is not absolute - the file ID does not contain .. - the escape only happens after filesystem resolution of a symlink under the allowed root
PoC Reproduced in an isolated Docker sandbox using the local nltk clone.
Minimal Python PoC:
python import os import tempfile from nltk.corpus.reader.api import CorpusReader
root = tempfile.mkdtemp(prefix="nltk-root-") outsidedir = tempfile.mkdtemp(prefix="nltk-out-") outsidefile = os.path.join(outsidedir, "secret.txt")
with open(outsidefile, "w") as f: f.write("secret-data")
os.symlink(outsidedir, os.path.join(root, "link"))
corpus = CorpusReader(root, ["link/secret.txt"]) with corpus.open("link/secret.txt") as f: print(f.read())
Observed result:
text secret-data
Docker re-test output:
text ROOT=/tmp/nltk-root-jjxay3if OUTSIDEDIR=/tmp/nltk-out-1kef36e0 JOINED=/tmp/nltk-root-jjxay3if/link/secret.txt REALPATH=/tmp/nltk-out-1kef36e0/secret.txt READOK=secret-data INSIDEROOT=True REALINSIDEROOT=False
Additional impact validation using a system file:
text ROOT=/tmp/nltk-root-h5x4m19 JOINED=/tmp/nltk-root-h5x4m19/hostfile REALPATH=/etc/hostname HOSTNAMEREAD=48dafb244af3 INSIDEROOT=True REALINSIDEROOT=False
This shows that the issue is not limited to attacker-created files outside the root; it can also read existing system files that are readable by the application user.
Impact This is an arbitrary local file read / symlink escape issue.
Who is impacted:
- applications that accept attacker-controlled corpus directories, extracted datasets, or package contents - applications that rely on NLTK corpus readers as a trust boundary for file access - any deployment where an attacker can place or influence files inside the allowed corpus root
Practical impact includes disclosure of:
- application secrets stored on disk - local configuration files - private datasets - process-exposed files such as /proc/self/environ - system files readable by the running user
The issue is best described as a filesystem sandbox bypass caused by improper link resolution before file access.
Other sources
NLTK versions before 3.9.4 contain a symlink escape vulnerability in CorpusReader.open() that allows local attackers to read arbitrary files outside the corpus root. The vulnerability exists because path validation is lexical and does not account for symlink resolution, enabling attackers to place symlinks inside the corpus root to access files outside the intended boundary.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/nltkto a version that resolves this vulnerability.Fixed in 3.9.4 - Upgrade
Upgrade
nltkto a version that resolves this vulnerability.Fixed in 3.9.4
Event History
Frequently Asked Questions
Who is exposed to this issue?
Applications using NLTK versions before 3.9.4 are exposed where a local attacker can create or control symlinks within a corpus root used by CorpusReader.open(). The impact is disclosure of files readable by the affected application outside that corpus root.
What does an attacker need to exploit it?
The attacker needs local access and the ability to place a symlink inside the corpus root. No privileges or user interaction are required according to the supplied vector.
How can this be mitigated if upgrading is not immediately possible?
Prevent untrusted local users or processes from creating, modifying, or placing symlinks in corpus root directories. Restrict filesystem permissions on corpus data and avoid using corpus roots in attacker-writable locations.