Skip to content
RCE Disclosed report Intermediate CVE-2026-12259

NLTK: Missing Post-Download Integrity Verification Allows Malicious Package Injection

NLTK's downloader does not verify the integrity of downloaded packages before extraction, allowing an attacker to inject malicious content via man-in-the-middle, race condition, or DNS poisoning. This could lead to arbitrary code execution when the package is later used.

nltk/nltk

Originally disclosed on huntr

NLTK's package downloader in nltk/downloader.py does not verify file integrity after download and before extraction.

The download flow at lines 789-825:

  1. File is downloaded to a temp path via HTTP
  2. os.replace(tmp_filepath, filepath) moves it to the final location (line 799)
  3. Extraction begins via _unzip_iter() (line 825)

Between steps 2 and 3, there is no SHA-256 verification. The checksum logic exists in _pkg_status() (lines 982-1015) but it is only used BEFORE download as a status check ("is this package already installed and up-to-date?"). It is never called after download to verify the file that was actually received.

Attack vectors:

  1. MITM during HTTP download (NLTK downloads from http:// by default on some mirrors)
  2. Race condition on shared filesystems (attacker replaces file between os.replace and _unzip_iter)
  3. DNS poisoning redirecting to attacker-controlled server

PoC:

Python
import nltk
import unittest.mock
import zipfile
import io
import os

# Create a malicious zip that will be "downloaded"
malicious_zip = io.BytesIO()
with zipfile.ZipFile(malicious_zip, 'w') as zf:
    zf.writestr('punkt_tab/tokenizers/punkt_tab/english.pickle', 
                b'MALICIOUS PAYLOAD - attacker controlled content')

# Patch urllib to return our malicious zip
with unittest.mock.patch('urllib.request.urlopen') as mock_urlopen:
    mock_response = unittest.mock.MagicMock()
    mock_response.read.return_value = malicious_zip.getvalue()
    mock_response.headers = {'Content-Length': str(len(malicious_zip.getvalue()))}
    mock_urlopen.return_value = mock_response
    
    # Download proceeds, no integrity check catches the swap
    # nltk.download('punkt_tab')  # Would install attacker payload

This is distinct from CVE-2024-39705 (pickle deserialization via download) and CVE-2025-14009 (zip-slip path traversal). Those address what happens AFTER extraction. This finding addresses the gap BEFORE extraction where integrity is never verified.

Suggested fix: After os.replace() and before _unzip_iter(), compute SHA-256 of the final file and compare against the expected checksum from the package index. Reject and delete the file if the hash does not match.

From the GitHub Advisory Database (GHSA-5wp5-5229-5g6q, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The downloader moves the downloaded file to its final location and extracts it without verifying its SHA-256 checksum against the expected value from the package index.

Impact

An attacker could inject malicious content into downloaded packages, potentially leading to arbitrary code execution when the package is used.

What the attacker needed

MITM or DNS poisoning or shared filesystem access

The fix

After moving the file to its final location and before extraction, compute the SHA-256 hash and compare it to the expected checksum; reject and delete the file if it does not match.

How it was found

  1. Download the package file to a temporary path via HTTP.
  2. Move the file to its final location using os.replace.
  3. Extract the file without verifying its integrity.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you download a file, it's important to check that it hasn't been tampered with. NLTK downloads language data packages but doesn't check if the file is the correct one after downloading, so an attacker could replace it with a malicious file. This could let them run harmful code on your computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from nltk/nltk

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.