CVE-2026-12259: Improper Input Validation in nltk/nltk
In nltk version 3.9.4, the nltk.downloader.Downloader.downloadpackage() function writes downloaded package bytes to disk and may extract them before enforcing SHA-256 or MD5 checksum validation. This allows an attacker to tamper with the package response body for info.url through a compromised mirror, malicious proxy, or other source-substitution condition, leading to the installation of attacker-controlled package bytes. The vulnerability can result in malicious corpus or model content being trusted by downstream users or applications.
Other sources
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(tmpfilepath, filepath) moves it to the final location (line 799) 3. Extraction begins via unzipiter() (line 825)
Between steps 2 and 3, there is no SHA-256 verification. The checksum logic exists in pkgstatus() (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 unzipiter) 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" maliciouszip = io.BytesIO() with zipfile.ZipFile(maliciouszip, 'w') as zf: zf.writestr('punkttab/tokenizers/punkttab/english.pickle', b'MALICIOUS PAYLOAD - attacker controlled content')
Patch urllib to return our malicious zip with unittest.mock.patch('urllib.request.urlopen') as mockurlopen: mockresponse = unittest.mock.MagicMock() mockresponse.read.returnvalue = maliciouszip.getvalue() mockresponse.headers = {'Content-Length': str(len(maliciouszip.getvalue()))} mockurlopen.returnvalue = mockresponse # Download proceeds, no integrity check catches the swap # nltk.download('punkttab') # 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 unzipiter(), 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.
— GitHub
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/nltkto a version that resolves this vulnerability.Fixed in 3.9.3
Event History
Frequently Asked Questions
What is the severity of CVE-2026-12259?
CVE-2026-12259 has a medium severity rating of 5.3.
How do I fix CVE-2026-12259?
To fix CVE-2026-12259, update to nltk version 3.9.5 or later where the vulnerability has been addressed.
What are the potential risks associated with CVE-2026-12259?
The risk associated with CVE-2026-12259 includes the possibility of an attacker tampering with downloaded package content.
Which versions of nltk are affected by CVE-2026-12259?
CVE-2026-12259 affects nltk version 3.9.4.
Is user interaction required for CVE-2026-12259 to be exploited?
Yes, user interaction is required as the vulnerability involves downloading packages via the nltk downloader.