NLTK: link following
Summary
YCOECorpusReader builds two nested corpus sub-readers whose roots are derived from self.root.join("psd") and self.root.join("pos") (nltk/corpus/reader/ycoe.py). Because FileSystemPathPointer.join() (nltk/data.py) performs a purely lexical containment check and never resolves symlinks, and because CorpusReader.__init__ (nltk/corpus/reader/api.py) validates a sub-reader root only against the global NLTK data sandbox and not against the enclosing corpus root, a directory symlink named psd or pos planted inside a YCOE corpus lets the reader anchor its nested sub-readers outside the YCOE corpus root. An attacker who controls the contents of a YCOE corpus loaded under pathsec.ENFORCE=True can make parsed_sents(), tagged_words(), and related methods return file content from other locations inside the allowed data sandbox, defeating the per-corpus-root containment boundary the pathsec controls are meant to enforce.
Root Cause
NLTK's pathsec controls are designed to keep each corpus reader confined to its own corpus root. The scoped containment is enforced through validate_path(..., required_root=self._root) at read time. However, the containment invariant is violated at reader-construction time for nested readers:
FileSystemPathPointer.join()accepts a component that is a directory symlink because it only checks the joined string lexically...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| nltk PyPI | >= 3.10.0, < 3.10.4 | 3.10.4 |
Details and references
## Summary `YCOECorpusReader` builds two nested corpus sub-readers whose roots are derived from `self.root.join("psd")` and `self.root.join("pos")` (nltk/corpus/reader/ycoe.py). Because `FileSystemPathPointer.join()` (nltk/data.py) performs a purely lexical containment check and never resolves symlinks, and because `CorpusReader.__init__` (nltk/corpus/reader/api.py) validates a sub-reader root only against the global NLTK data sandbox and not against the enclosing corpus root, a directory symlink named `psd` or `pos` planted inside a YCOE corpus lets the reader anchor its nested sub-readers outside the YCOE corpus root. An attacker who controls the contents of a YCOE corpus loaded under `pathsec.ENFORCE=True` can make `parsed_sents()`, `tagged_words()`, and related methods return file content from other locations inside the allowed data sandbox, defeating the per-corpus-root containment boundary the pathsec controls are meant to enforce. ## Root Cause NLTK's pathsec controls are designed to keep each corpus reader confined to its own corpus root. The scoped containment is enforced through `validate_path(..., required_root=self._root)` at read time. However, the containment invariant is violated at reader-construction time for nested readers: - `FileSystemPathPointer.join()` accepts a component that is a directory symlink because it only checks the joined string lexically (`os.path.normpath` plus a `startswith` prefix test) and never calls `resolve()`. - `CorpusReader.__init__` validates the resulting sub-reader root string, but calls `validate_path` without `required_root`, so only the global-sandbox layer runs; the scoped per-corpus-root layer is skipped. The symlink is resolved by that global check, its target is found to be inside the allowed sandbox, and the sub-reader is accepted with its root pointing at the escaped target. From that point every read the sub-reader performs is scoped to the already-escaped root, so no later guard re-anchors it to the YCOE corpus root. ```text Affected functions: - nltk.corpus.reader.ycoe.YCOECorpusReader.__init__ (nltk/corpus/reader/ycoe.py) builds nested sub-readers from self.root.join("psd")/("pos") without containing them to the parent root - nltk.corpus.reader.api.CorpusReader.__init__ (nltk/corpus/reader/api.py) validates a sub-reader root only against the global sandbox (validate_path without required_root) - nltk.data.FileSystemPathPointer.join (nltk/data.py) applies a lexical prefix check only and never resolves symlinks ``` ## Impact An attacker who controls the directory contents of a YCOE corpus that is loaded by a victim application under `pathsec.ENFORCE=True` (the default in the affected releases) can read file content that lives outside the YCOE corpus root but inside an allowed NLTK data root. 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. The demonstrated capability is read-only cross-corpus-root disclosure. In a multi-tenant or automated-ingestion deployment the accessible scope includes other corpora placed under the shared data path and the shared system temporary directory, which is a default allowed root and can hold other processes' sensitive temporary files. There is no integrity or availability impact. ## Proof of Concept `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. ```python
- CVSS 3.1
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-59
- Also known as
- CVE-2026-126304
- github.com/nltk/nltk/security/advisories/GHSA-qg35-44qx-7vrr
- nvd.nist.gov/vuln/detail/CVE-2026-126304
- github.com/nltk/nltk/pull/3888
- github.com/nltk/nltk/commit/2c563b13f9dce7c15eefd4b03463e1b69b64f1f3
- github.com/nltk/nltk/commit/68434c0427f8d296f3adfddb518525038d1f7bfa
- github.com/nltk/nltk
- github.com/nltk/nltk/releases/tag/v3.10.4
- www.vulncheck.com/advisories/nltk-3.10.0-before-3.10.4-symlink-escape-in-ycoecorpusreader