NLTK: FileSystemPathPointer.open() sandbox check is dead code — arbitrary file read via file:// protocol
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N상세 설명
Summary
There's a logic bug in FileSystemPathPointer.open() inside nltk/data.py
that makes the sandbox check permanently inert. The guard condition is always
False — meaning any file the process can read is accessible by passing a
file:// URL to nltk.data.load().
Details
In nltk/data.py, FileSystemPathPointer.open() was patched at some point
with a comment saying "SECURITY PATCH ENFORCING SANDBOX", but the check
doesn't work:
1def open(self, encoding=None): 2 path = os.path.normpath(self._path) 3 4 # Block raw absolute reads such as "/" "C:\\Windows" etc. 5 if os.path.isabs(path) and path != os.path.normpath(self._path): 6 raise ValueError(f"Direct absolute file access blocked: {path}") 7 8 stream = open(self._path, "rb")path is set to os.path.normpath(self._path) on line 1, then compared
against os.path.normpath(self._path) again in the condition. They are
always equal. The ValueError never fires.
On top of that, __init__ already calls os.path.abspath() before storing
self._path, so it's normalized before open() is even called. Running
normpath on it again changes nothing.
The stream = open(self._path, "rb") line is always reached regardless of
what path was passed in.
PoC
Tested on Python 3.11, NLTK 3.9.1, Ubuntu 22.04.
1import nltk 2from nltk.data import FileSystemPathPointer 3 4# direct construction 5ptr = FileSystemPathPointer("/etc/passwd") 6with ptr.open() as f: 7 print(f.read(300)) 8 9# via load() using file:// URL10data = nltk.data.load("file:///etc/passwd", format="raw")11print(data[:300])Both print file contents. No exception is raised.
Impact
Any app that lets users influence the string passed to nltk.data.load() or
nltk.data.find() is exposed — web APIs, notebook servers, multi-tenant
pipelines. An attacker can read any file the process user has access to:
/etc/passwd, .env files, private keys, ~/.aws/credentials, etc.
Suggested Fix
File: nltk/data.py — FileSystemPathPointer.open() (lines 378–390)
What's wrong
Line 387 compares normpath(self._path) against itself — always equal,
so the ValueError never fires. The check is dead code.
__init__ already calls abspath() on construction, so re-running
normpath inside open() changes nothing either.
Fix
Validate against the actual list of permitted data directories instead:
1def open(self, encoding=None): 2 import nltk.data as _d 3 allowed = [os.path.abspath(p) for p in _d.path if p] 4 if allowed and not any( 5 os.path.commonpath([self._path, r]) == r for r in allowed 6 ): 7 raise ValueError( 8 f"Access outside nltk_data blocked: {self._path!r}" 9 )10 stream = open(self._path, "rb")11 if encoding is not None:12 stream = SeekableUnicodeStreamReader(stream, encoding)13 return streamWhy commonpath not startswith
startswith is bypassable by a path that shares a prefix:
1/tmp/nltk_data_evil".startswith("/tmp/nltk_data") → True ✗ 2commonpath(["/tmp/nltk_data_evil", "/tmp/nltk_data"]) → "/tmp" ✓Diff
1- path = os.path.normpath(self._path) 2- if os.path.isabs(path) and path != os.path.normpath(self._path): 3- raise ValueError(f"Direct absolute file access blocked: {path}") 4- 5+ import nltk.data as _d 6+ allowed = [os.path.abspath(p) for p in _d.path if p] 7+ if allowed and not any( 8+ os.path.commonpath([self._path, r]) == r for r in allowed 9+ ):10+ raise ValueError(f"Access outside nltk_data blocked: {self._path!r}")11 stream = open(self._path, "rb")AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 8
링크 내용 불러오는 중…