Symlink Attack 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.16% (3rd 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-22733177
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • credithaoxiang Yan

Introduced: 19 Nov 2026

NewCVE-2026-128137  (opens in a new tab)
CWE-59  (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 Symlink Attack via intermediate-directory symlinks in CorpusReader.abspaths() and abspath(). The view methods of PlaintextCorpusReader (words, sents, paras) and SyntaxCorpusReader (words, sents, parsed_sents, tagged_sents, tagged_words) build their file streams from abspaths(), which performs only a lexical self._root.join(fileid) and returns a FileSystemPathPointer without invoking pathsec.validate_path with required_root. When the pointer is subsequently opened via FileSystemPathPointer.open(), pathsec.open is called with required_root=None, so only the global allowed-roots check runs. Because O_NOFOLLOW in _hardened_open protects only the final path component, an intermediate-directory symlink inside the corpus root that points at a sibling directory within the global NLTK data sandbox is followed by the kernel, allowing an attacker to read files outside the corpus root. The identical fileid is correctly rejected by CorpusReader.open() via its Layer-2 scoped guard, but succeeds through the view-method channel, defeating the scoped sandbox protection.

Note: This is only exploitable when an attacker can place an intermediate-directory symlink inside an NLTK corpus root - either through direct write access to the data directory, or by supplying an untrusted corpus that is unpacked in a symlink-preserving manner (e.g. via tar extraction, git checkout, or shared/multi-tenant data directories).

PoC

A self-contained, self-checking repro script is embedded at the end of this advisory. It builds a private temp sandbox as an allowed NLTK data root, creates corpus root R, sibling bar (inside the same allowed root), file bar/secret.txt = TOPSECRET, and an intermediate directory symlink R/sub -> bar. It then asserts the control (same fileid through open() is refused) and the attack (abspaths() pointer, PlaintextCorpusReader.words, SyntaxCorpusReader.words/sents read the secret), plus a boundary check that a symlink pointing outside every allowed root is still refused.

Scope note: dynamically run on (1) the released nltk 3.9.4 wheel, (2) the released nltk 3.10.3 wheel, and (3) master 6818767b9 (v3.10.3-15-g6818767b9). The scoped-escape checks pass on all three; the "global sandbox still blocks outside-allowed-root read" boundary check passes on 3.10.3 and master, and is expected to differ on 3.9.4: 3.9.4 ships pathsec.ENFORCE = False (enforcement became the default only in 3.10.0) and its pathsec.open is a thin builtins.open wrapper with no _hardened_open/O_NOFOLLOW, so on 3.9.4 the sandbox does not confine reads to the allowed roots at all — the escape is broader there, not narrower. The required_root scoped guard (1b0e519e2, "Implement scoped root validation in pathsec sentinel") is present in 3.9.4 and every later release (v3.10.0/3.10.1/3.10.2/3.10.3 confirmed by tag inspection), and static comparison shows the identical abspaths()/view-method code path in all of them; 3.9.4 and 3.10.3 were the versions dynamically run.

Environment / steps (Python 3.10.12, Linux, pathsec.ENFORCE=True, POSIX):

  1. SANDBOX=$(mktemp -d); nltk.data.path.append(SANDBOX) — the private dir becomes an allowed NLTK data root.
  2. R=$SANDBOX/corpora/mysample, BAR=$SANDBOX/bar; write BAR/secret.txt = TOPSECRET.
  3. ln -s "$BAR" "$R/sub" — intermediate directory symlink inside the corpus root.
  4. Control: reader.open("sub/secret.txt") → ValueError: Security Violation [CorpusReader]: Path <BAR>/secret.txt escapes root <R> (refused).
  5. Attack: reader.abspaths(["sub/secret.txt"])[0].open().read() → b'TOPSECRET\n'; list(reader.words(["sub/secret.txt"])) → ['TOPSECRET']; same for BracketParseCorpusReader.words/sents.
  6. Boundary: R/out -> /etc (outside every allowed root) is refused with PermissionError: Security Violation [pathsec.open]: Unauthorized path ....

Live transcript, key output (identical on nltk 3.9.4, 3.10.3 and master @ 6818767b9 unless noted):

nltk version: 3.9.4/3.10.3   python: 3.10.12   (posix)
CONTROL open() rejects symlink escape                 ValueError: ... escapes root ...
abspaths() pointer.open() reads outside root          b'TOPSECRET\n'
PlaintextCorpusReader.words() leaks outside root      ['TOPSECRET']
SyntaxCorpusReader.words() leaks outside root         ['TOPSECRET']
GLOBAL sandbox still blocks outside-allowed-root read PermissionError: ... Unauthorized path ...
                                                      (3.10.3+ only; on 3.9.4 the sandbox
                                                       is not enforced and the read succeeds)
RESULT: 3.9.4: 8/9 · 3.10.3: 9/9 · master: 9/9 (all scoped-escape checks pass)

The scoped-escape checks (the vulnerability itself) pass on all three pinned versions; the single 3.9.4 difference is the global-sandbox boundary check, which is weaker there by design (ENFORCE=False, thin pathsec.open).

Note: The PoC states it was run on Python 3.10.12, Linux, with pathsec.ENFORCE=True on POSIX, against nltk versions 3.9.4 and 3.10.3.

CVSS Base Scores

version 4.0
version 3.1