{"id":"GHSA-72r2-7mfr-5xr9","summary":"NLTK: FileSystemPathPointer.open() sandbox check is dead code — arbitrary file read via file:// protocol","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```","aliases":["CVE-2026-65915","PYSEC-2026-3731"],"modified":"2026-09-08T15:46:56.329043767Z","published":"2026-09-08T15:27:12Z","database_specific":{"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-09-08T15:27:12Z","nvd_published_at":null,"cwe_ids":["CWE-284"]},"references":[{"type":"WEB","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":"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"},{"type":"WEB","url":"https://www.vulncheck.com/advisories/nltk-before-arbitrary-file-read-via-filesystempathpointer"}],"affected":[{"package":{"name":"nltk","ecosystem":"PyPI","purl":"pkg:pypi/nltk"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"3.10.0"}]}],"versions":["0.8","0.9","0.9.3","0.9.4","0.9.5","0.9.6","0.9.7","0.9.8","0.9.9","2.0.1","2.0.1rc1","2.0.1rc2-git","2.0.1rc3","2.0.1rc4","2.0.2","2.0.3","2.0.4","2.0.5","2.0b4","2.0b5","2.0b6","2.0b7","2.0b8","2.0b9","3.0.0","3.0.0b1","3.0.0b2","3.0.1","3.0.2","3.0.3","3.0.4","3.0.5","3.1","3.2","3.2.1","3.2.2","3.2.3","3.2.4","3.2.5","3.3","3.4","3.4.1","3.4.2","3.4.3","3.4.4","3.4.5","3.5","3.5b1","3.6","3.6.1","3.6.2","3.6.3","3.6.4","3.6.5","3.6.6","3.6.7","3.7","3.8","3.8.1","3.9","3.9.1","3.9.2","3.9.3","3.9.4","3.9b1"],"database_specific":{"last_known_affected_version_range":"\u003c= 3.9.3","source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-72r2-7mfr-5xr9/GHSA-72r2-7mfr-5xr9.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N"}]}