{"id":2014,"cve":"CVE-2026-54293","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-54293\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":7.5,"published":"2026-06-22","owasp":"A01 Broken Access Control","odc":"Checking","cdc":"Incorrect Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Information Disclosure","summary":"Path traversal in NLTK's data.load() using URL-encoded characters.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-54293\/","description":"NLTK (Natural Language Toolkit) is a suite of open source Python modules, data sets, and tutorials supporting research and development in Natural Language Processing. Prior to 3.10.0-rc1, 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. This vulnerability is fixed in 3.10.0-rc1.","solution":"Upgrade NLTK to version 3.10.0-rc1 or later.","affected_component":"NLTK","fixed_by_upgrading":true,"vulnerable_code":"import re\nimport os\nfrom urllib.request import url2pathname\n\n_UNSAFE_PATH_REGEX = re.compile(r\"\"\"\n    (^(\/|\\\\)) | # starts with a path separator\n    (\\.\\.)      | # contains '..'\n    (?!nltk:)     # does not start with 'nltk:'\n\"\"\", re.VERBOSE)\n\ndef find(resource_name, paths=None):\n    # This is a simplified stand-in for NLTK's actual find mechanism.\n    # It demonstrates the path joining part of the vulnerability.\n    if paths is None:\n        # A default search path for the example\n        paths = [\"\/tmp\/nltk_data\"]\n\n    for path in paths:\n        # The decoded, and now unsafe, path is joined here.\n        full_path = os.path.join(path, resource_name)\n        if os.path.exists(full_path):\n            return full_path\n    raise LookupError(f\"Resource {resource_name} not found.\")\n\ndef load(resource_url, format='auto', cache=True, verbose=False):\n    # The vulnerability is in how the resource_url is handled.\n    # 1. The check is performed on the raw, URL-encoded string.\n    # A path like 'corpora\/..\/..\/..\/..\/..\/etc\/passwd' would be blocked.\n    if _UNSAFE_PATH_REGEX.search(resource_url):\n        raise ValueError(f\"Malicious path component detected in '{resource_url}'\")\n\n    # 2. The URL is then decoded *after* the check.\n    # An encoded path like 'corpora\/%2e%2e\/%2e%2e\/etc\/passwd'\n    # passes the regex check above, but url2pathname decodes it\n    # into a malicious path. This is the core of the vulnerability.\n    resource_path = url2pathname(resource_url.split(':', 1)[1])\n\n    # 3. The decoded, potentially malicious path is used to find and open a file.\n    filepath = find(resource_path)\n    with open(filepath, 'rb') as f:\n        return f.read()","patched_code":"import re\nfrom urllib.parse import unquote\nimport os\n\n# This regex is a simplified representation of a check for unsafe path components.\n# It looks for directory traversal attempts or absolute paths.\nUNSAFE_PATH_REGEX = re.compile(r\"\\.\\.[\/\\\\]|[\/\\\\]\\.\\.|^[\/\\\\]|^[a-zA-Z]:[\/\\\\]\")\n\ndef fixed_nltk_data_load(resource_url: str):\n    \"\"\"\n    A conceptual fix demonstrating how to prevent path traversal by\n    decoding the URL path before validation, as described in CVE-2026-54293.\n    \"\"\"\n    if not resource_url.startswith(\"nltk:\"):\n        raise ValueError(f\"Unsupported resource URL: {resource_url}\")\n\n    path_component = resource_url[len(\"nltk:\"):]\n\n    # THE FIX:\n    # 1. First, decode any URL-encoded characters (e.g., %2e, %2f).\n    # This ensures that the security check sees the actual path components\n    # an attacker is trying to use, preventing a \"decode-after-check\" flaw.\n    decoded_path = unquote(path_component)\n\n    # 2. Second, perform the security check on the now-decoded path.\n    # An attack like '..%2f..%2fetc%2fpasswd' becomes '..\/etc\/passwd',\n    # which is now correctly caught by the regex.\n    if UNSAFE_PATH_REGEX.search(decoded_path):\n        raise ValueError(\n            f\"Path traversal or absolute path detected in '{decoded_path}'\"\n        )\n\n    # If the check passes, the path is considered safe. In a real implementation,\n    # it would be joined with a trusted base directory to load a file.\n    # For example:\n    #\n    # from nltk.downloader import Downloader\n    # downloader = Downloader()\n    # safe_full_path = downloader.find(decoded_path)\n    # with open(safe_full_path) as f:\n    #     return f.read()\n\n    # Placeholder for safe file loading logic\n    pass","payload_needed":true,"payload":"```python\nnltk.data.load('nltk:%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc\/passwd')\n```","payload_status":"available","published_fix":[{"repository":"nltk\/nltk","commit_url":"https:\/\/github.com\/nltk\/nltk\/pull\/3575","commit_subject":"fix(security): block URL-encoded path traversal in nltk: resource URLs","units":[{"file":"nltk\/data.py","function":null},{"file":"nltk\/data.py","function":"find"},{"file":"nltk\/data.py","function":"normalize_resource_url"},{"file":"nltk\/data.py","function":"_reject_unsafe_no_protocol"}]}],"references":null}