GCVE Workshop - 22 September 2026 (14:00-18:00), Luxembourg Before The Vulnopticon Conference - Registration

GHSA-72R2-7MFR-5XR9

Vulnerability from github – Published: 2026-09-08 15:27 – Updated: 2026-09-08 15:27
VLAI
Summary
NLTK: FileSystemPathPointer.open() sandbox check is dead code — arbitrary file read via file:// protocol
Details

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:

def open(self, encoding=None):
    path = os.path.normpath(self._path)

    # Block raw absolute reads such as "/" "C:\\Windows" etc.
    if os.path.isabs(path) and path != os.path.normpath(self._path):
        raise ValueError(f"Direct absolute file access blocked: {path}")

    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.

import nltk
from nltk.data import FileSystemPathPointer

# direct construction
ptr = FileSystemPathPointer("/etc/passwd")
with ptr.open() as f:
    print(f.read(300))

# via load() using file:// URL
data = nltk.data.load("file:///etc/passwd", format="raw")
print(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.pyFileSystemPathPointer.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:

def open(self, encoding=None):
    import nltk.data as _d
    allowed = [os.path.abspath(p) for p in _d.path if p]
    if allowed and not any(
        os.path.commonpath([self._path, r]) == r for r in allowed
    ):
        raise ValueError(
            f"Access outside nltk_data blocked: {self._path!r}"
        )
    stream = open(self._path, "rb")
    if encoding is not None:
        stream = SeekableUnicodeStreamReader(stream, encoding)
    return stream

Why commonpath not startswith

startswith is bypassable by a path that shares a prefix:

/tmp/nltk_data_evil".startswith("/tmp/nltk_data") → True  ✗
commonpath(["/tmp/nltk_data_evil", "/tmp/nltk_data"]) → "/tmp"  ✓

Diff

-    path = os.path.normpath(self._path)
-    if os.path.isabs(path) and path != os.path.normpath(self._path):
-        raise ValueError(f"Direct absolute file access blocked: {path}")
-
+    import nltk.data as _d
+    allowed = [os.path.abspath(p) for p in _d.path if p]
+    if allowed and not any(
+        os.path.commonpath([self._path, r]) == r for r in allowed
+    ):
+        raise ValueError(f"Access outside nltk_data blocked: {self._path!r}")
     stream = open(self._path, "rb")
Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 3.9.3"
      },
      "package": {
        "ecosystem": "PyPI",
        "name": "nltk"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "3.10.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-65915"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-284"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-09-08T15:27:12Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "### Summary\n\nThere\u0027s a logic bug in `FileSystemPathPointer.open()` inside `nltk/data.py`\nthat makes the sandbox check permanently inert. The guard condition is always\n`False` \u2014 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\u0027t 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\u0027s 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 \u2014 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` \u2014 `FileSystemPathPointer.open()` (lines 378\u2013390)\n\n### What\u0027s wrong\n\nLine 387 compares `normpath(self._path)` against itself \u2014 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\") \u2192 True  \u2717\ncommonpath([\"/tmp/nltk_data_evil\", \"/tmp/nltk_data\"]) \u2192 \"/tmp\"  \u2713\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```",
  "id": "GHSA-72r2-7mfr-5xr9",
  "modified": "2026-09-08T15:27:12Z",
  "published": "2026-09-08T15:27:12Z",
  "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"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "NLTK: FileSystemPathPointer.open() sandbox check is dead code \u2014 arbitrary file read via file:// protocol"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…

Loading…