NLTK: information disclosure
Summary
StreamBackedCorpusView, a public API in nltk/corpus/reader/util.py, applies the pathsec sandbox to the file content it reads but not to the file metadata it probes in its constructor. When the view is created with a plain string fileid, __init__ calls os.stat(self._fileid).st_size with no pathsec validation, so an application that passes an attacker influenced path to the constructor discloses whether an arbitrary out of root file exists and, if it does, its exact byte size and modification time, even when nltk.pathsec.ENFORCE is True. This is the residual metadata channel left open by the fix for CVE-2026-63312 (GHSA-x5ph-mj9p-rfr8), which closed arbitrary content read on the same code path but did not bring the sibling os.stat under the sandbox.
Root Cause
The pathsec sandbox is intended to confine all NLTK filesystem access to allowed data roots. The fix for CVE-2026-63312 enforced this for content reads by routing StreamBackedCorpusView._open through nltk.pathsec.open (_secure_open). The constructor, however, computes the end of file position eagerly, and on the non PathPointer branch it stats the caller supplied path directly. The PathPointer branch is validated (it calls PathPointer.file_size()), but the plain string branch reaches os.stat with no validate_path, _secure_open, or required_root check. The security...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| nltk PyPI | >= 3.10.0, < 3.10.4 | 3.10.4 |
Details and references
## Summary `StreamBackedCorpusView`, a public API in `nltk/corpus/reader/util.py`, applies the pathsec sandbox to the file content it reads but not to the file metadata it probes in its constructor. When the view is created with a plain string fileid, `__init__` calls `os.stat(self._fileid).st_size` with no pathsec validation, so an application that passes an attacker influenced path to the constructor discloses whether an arbitrary out of root file exists and, if it does, its exact byte size and modification time, even when `nltk.pathsec.ENFORCE` is `True`. This is the residual metadata channel left open by the fix for CVE-2026-63312 (GHSA-x5ph-mj9p-rfr8), which closed arbitrary content read on the same code path but did not bring the sibling `os.stat` under the sandbox. ## Root Cause The pathsec sandbox is intended to confine all NLTK filesystem access to allowed data roots. The fix for CVE-2026-63312 enforced this for content reads by routing `StreamBackedCorpusView._open` through `nltk.pathsec.open` (`_secure_open`). The constructor, however, computes the end of file position eagerly, and on the non `PathPointer` branch it stats the caller supplied path directly. The `PathPointer` branch is validated (it calls `PathPointer.file_size()`), but the plain string branch reaches `os.stat` with no `validate_path`, `_secure_open`, or `required_root` check. The security invariant "no filesystem access outside allowed roots under ENFORCE" is therefore violated for the metadata channel: `os.stat` is filesystem access, and it is performed on the same untrusted string entry point that the content read fix protected. ```text Affected component: nltk.corpus.reader.util.StreamBackedCorpusView.__init__ Sink: nltk/corpus/reader/util.py, os.stat(self._fileid).st_size on the plain-string branch Guarded sibling: _open() (routes through nltk.pathsec.open); the constructor os.stat is not guarded ``` ## Impact An attacker who can influence the fileid string passed to `StreamBackedCorpusView(...)` (the same attacker model under which CVE-2026-63312 was published for content read) obtains a filesystem oracle that operates across the process visible filesystem regardless of the pathsec data roots and with `ENFORCE=True`: - Existence: a present path returns a size; a missing path raises `ValueError` whose message embeds the underlying OS error, so ENOENT, EACCES, and ENOTDIR are distinguishable, adding a permission and type probe. - Exact size: `st_size` of the target file is exposed (demonstrated below: `1850` for `/etc/passwd`, matching the real size). - Modification time: `st_mtime` is available from the same stat result. File content is not disclosed: iterating the view still routes through the sandboxed open and is refused. The demonstrated capability is therefore metadata only (existence, exact size, mtime, and error class discrimination). Reachability is application conditional: in tree corpus readers construct views from validated `PathPointer` objects and take the guarded branch, so exploitation requires application code that hands an attacker influenced string directly to the public constructor, which is the same condition accepted for the original content read advisory. ## Proof of Concept `Requires nltk 3.10.0 through 3.10.3 installed (the pathsec-hardened line). No non-default configuration; pathsec ENFORCE defaults to True. Reproduced against the published PyPI sdist nltk==3.10.3.` 1. Construct the public corpus view with an out of root path string. 2. Read the eagerly computed `_eofpos` (the leaked size) without iterating the view. 3. Observe that iterating the view (which would read content) is blocked by the sandbox. ```python import os import nltk.pathsec as ps from nltk.corpus.reader.util import StreamBackedCorpusView as V print("ENFORCE", ps.ENFORCE) # True (default) v = V("/etc/passwd", lambda s: [s.read()]) print("size leaked", v._eofpos, "real", os.stat("/etc/passwd").st_size) try: "".
- CVSS 3.1
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-200, CWE-538
- Also known as
- CVE-2026-129233
- github.com/nltk/nltk/security/advisories/GHSA-w674-vqhw-g3pg
- nvd.nist.gov/vuln/detail/CVE-2026-129233
- 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