# NLTK: Symlink escape in YCOECorpusReader lets a psd/pos directory symlink read files outside the corpus root within the data sandbox

YCOECorpusReader builds psd/pos sub-readers from a lexically-checked join, so a directory symlink escapes the corpus root and leaks in-sandbox files.

- Payout: Research
- Severity: high
- Program: NLTK
- Found by (vendor credit): manus-pi, manus-use
- Found by: manus-pi, manus-use
- Disclosed: 2026-11-13
- CVE: CVE-2026-126304
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-qg35-44qx-7vrr
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-qg35-44qx-7vrr
- Tags: area:oss domain:oss impact:data-leak impact:internal-access kind:research platform:ghsa sev:high tech:python technique:source-review vuln:info-disclosure vuln:path-traversal

**Target:** YCOECorpusReader nested psd/pos sub-readers (nltk/corpus/reader/ycoe.py)
**Root cause:** FileSystemPathPointer.join() only does a lexical prefix check and never resolves symlinks, and CorpusReader.__init__ calls validate_path without required_root, so the per-corpus-root containment layer is skipped for nested sub-readers.
**Steps:**
1. Create a sandbox dir, set `pathsec.ENFORCE = True`, `nltk.data.path = [sandbox]`, reset `pathsec._ALLOWED_ROOTS_CACHE = None`.
2. Inside sandbox create a victim dir with `doc1.psd` and `doc1.pos` outside the YCOE corpus root.
3. Create YCOE corpus root and symlink `psd`/`pos` entries to the victim dirs via `os.symlink`.
4. Construct `YCOECorpusReader(ycoe)` and call `parsed_sents()` / `tagged_words()`; out-of-root content is returned.
**How found:** Code review of pathsec containment: noticed join() uses normpath+startswith without resolve(), and CorpusReader.__init__ calls validate_path without required_root, skipping the scoped layer; confirmed with a symlink PoC and negative controls.
**Exploitation:** Attacker controls a YCOE corpus placed under an allowlisted NLTK data root; sets psd/pos to directory symlinks pointing at another in-sandbox directory. Reader construction accepts the escaped root (global check only), and all subsequent reads are anchored to the escaped target, disclosing other corpora or shared temp files.
**Escalation:** Bounded to the global NLTK data sandbox; a symlink to /etc is rejected at construction with PermissionError, so no arbitrary filesystem read.
**Insight:** When a reader derives nested sub-reader roots from its own root, check whether the constructor's containment validation passes required_root — a lexical join plus global-sandbox-only check lets a symlinked component re-anchor the reader outside its parent root.

## Proof of concept (copied exactly from the original report)

**Python PoC planting psd/pos symlinks in YCOE corpus**

```
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())
```

