{"id":"CVE-2026-65915","aliases":["GHSA-72r2-7mfr-5xr9","PYSEC-2026-3731"],"url":"https://o3.security/vulnerability/CVE-2026-65915","summary":"NLTK before 3.10.0 Arbitrary File Read via FileSystemPathPointer","details":"### Summary\n\nThere's a logic bug in `FileSystemPathPointer.open()` inside `nltk/data.py`\nthat makes the sandbox check permanently inert. The guard condition is always\n`False` — meaning any file the process can read is accessible by passing a\n`file://` URL to `nltk.data.load()`.\n\n---\n\n### Details\n\nIn `nltk/data.py`, `FileSystemPathPointer.open()` was patched at some point\nwith a comment saying \"SECURITY PATCH ENFORCING SANDBOX\", but the check\ndoesn't work:\n```python\ndef open(self, encoding=None):\n    path = os.path.normpath(self._path)\n\n    # Block raw absolute reads such as \"/\" \"C:\\\\Windows\" etc.\n    if os.path.isabs(path) and path != os.path.normpath(self._path):\n        raise ValueError(f\"Direct absolute file access blocked: {path}\")\n\n    stream = open(self._path, \"rb\")\n```\n\n`path` is set to `os.path.normpath(self._path)` on line 1, then compared\nagainst `os.path.normpath(self._path)` again in the condition. They are\nalways equal. The `ValueError` never fires.\n\nOn top of that, `__init__` already calls `os.path.abspath()` before storing\n`self._path`, so it's normalized before `open()` is even called. Running\n`normpath` on it again changes nothing.\n\nThe `stream = open(self._path, \"rb\")` line is always reached regardless of\nwhat path was passed in.\n\n---\n\n### PoC\n\nTested on Python 3.11, NLTK 3.9.1, Ubuntu 22.04.\n```python\nimport nltk\nfrom nltk.data import FileSystemPathPointer\n\n# direct construction\nptr = FileSystemPathPointer(\"/etc/passwd\")\nwith ptr.open() as f:\n    print(f.read(300))\n\n# via load() using file:// URL\ndata = nltk.data.load(\"file:///etc/passwd\", format=\"raw\")\nprint(data[:300])\n```\n\nBoth print file contents. No exception is raised.\n\n---\n\n### Impact\n\nAny app that lets users influence the string passed to `nltk.data.load()` or\n`nltk.data.find()` is exposed — web APIs, notebook servers, multi-tenant\npipelines. An attacker can read any file the process user has access to:\n`/etc/passwd`, `.env` files, private keys, `~/.aws/credentials`, etc.\n\n## Suggested Fix\n\n**File:** `nltk/data.py` — `FileSystemPathPointer.open()` (lines 378–390)\n\n### What's wrong\n\nLine 387 compares `normpath(self._path)` against itself — always equal,\nso the `ValueError` never fires. The check is dead code.\n`__init__` already calls `abspath()` on construction, so re-running\n`normpath` inside `open()` changes nothing either.\n\n---\n\n### Fix\n\nValidate against the actual list of permitted data directories instead:\n```python\ndef open(self, encoding=None):\n    import nltk.data as _d\n    allowed = [os.path.abspath(p) for p in _d.path if p]\n    if allowed and not any(\n        os.path.commonpath([self._path, r]) == r for r in allowed\n    ):\n        raise ValueError(\n            f\"Access outside nltk_data blocked: {self._path!r}\"\n        )\n    stream = open(self._path, \"rb\")\n    if encoding is not None:\n        stream = SeekableUnicodeStreamReader(stream, encoding)\n    return stream\n```\n\n---\n\n### Why `commonpath` not `startswith`\n\n`startswith` is bypassable by a path that shares a prefix:\n```\n/tmp/nltk_data_evil\".startswith(\"/tmp/nltk_data\") → True  ✗\ncommonpath([\"/tmp/nltk_data_evil\", \"/tmp/nltk_data\"]) → \"/tmp\"  ✓\n```\n\n---\n\n### Diff\n```diff\n-    path = os.path.normpath(self._path)\n-    if os.path.isabs(path) and path != os.path.normpath(self._path):\n-        raise ValueError(f\"Direct absolute file access blocked: {path}\")\n-\n+    import nltk.data as _d\n+    allowed = [os.path.abspath(p) for p in _d.path if p]\n+    if allowed and not any(\n+        os.path.commonpath([self._path, r]) == r for r in allowed\n+    ):\n+        raise ValueError(f\"Access outside nltk_data blocked: {self._path!r}\")\n     stream = open(self._path, \"rb\")\n```","published":"2026-08-22T14:12:41.391Z","modified":"2026-09-02T03:47:25.588074515Z","cvss":null,"epss":null,"cisaKev":null,"exploitsKnown":null,"affectedPackages":[{"ecosystem":"PyPI","name":"nltk","fixedVersion":"3.10.0"}],"fix":{"url":"https://github.com/nltk/nltk/pull/3522","label":"nltk/nltk#3522"},"references":[{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/65xxx/CVE-2026-65915.json"},{"type":"ADVISORY","url":"https://github.com/nltk/nltk/security/advisories/GHSA-72r2-7mfr-5xr9"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-65915"},{"type":"ADVISORY","url":"https://www.vulncheck.com/advisories/nltk-before-arbitrary-file-read-via-filesystempathpointer"},{"type":"WEB","url":"https://github.com/nltk/nltk/pull/3522"},{"type":"WEB","url":"https://github.com/nltk/nltk/commit/69db9911fdba914ceeaca7aec6e892d1b14586a9"},{"type":"PACKAGE","url":"https://github.com/nltk/nltk"},{"type":"WEB","url":"https://github.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2026-3731.yaml"},{"type":"WEB","url":"https://huntr.com/bounties/a510de7b-ffaf-4a83-9bf8-fa7e63f4bd2d"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-09-02T03:47:25.588074515Z"}}