GitHub advisory · PyPI
NLTK: StreamBackedCorpusView constructor os.stat leaks out-of-root file existence, size, and mtime bypassing pathsec ENFORCE
Description
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.
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.
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
An attacker who can influence the fileid string passed to…
Manual fix · PyPI
pip install --upgrade "nltk>=3.10.4"Sources