NLTK: Missing Post-Download Integrity Verification Allows Malicious Package Injection
Published 8 Sept 2026 · Updated 16 Oct 2026
Is your project on an affected nltk?
Look after several Python apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <3.9.3
- Fixed in
- 3.9.3
pip install 'nltk>=3.9.3'Details
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:
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 payloadThis 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.
Is GHSA-5wp5-5229-5g6q in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected nltk, and gives you the command that fixes it.
More advisories for nltk
- HighCVE-2026-128135NLTK: ZIP package extraction follows in-root hardlinks and overwrites files outside the NLTK data root · 19 Nov 2026
- MediumCVE-2026-128136NLTK: AllowlistUnpickler does not deny numpy submodule-local file-I/O sinks · 19 Nov 2026
- MediumCVE-2026-128137NLTK corpus-reader view methods bypass the scoped root sandbox via intermediate-directory symlinks · 19 Nov 2026
- CriticalCVE-2026-128138NLTK incomplete fix: additional JVM/JAR sandbox bypass through unvalidated launcher tokens in java() command arguments · 19 Nov 2026
- HighCVE-2026-128139NLTK: XMLCorpusView comment and CDATA parsing permits quadratic CPU denial of service · 19 Nov 2026
- MediumCVE-2026-128140NLTK: Downloader cyclic collection indices cause an infinite closure walk · 19 Nov 2026
References
- Linkgithub.com/nltk/nltk/security/advisories/GHSA-5wp5-5229-5g6q
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-12259
- Linkgithub.com/nltk/nltk/pull/3449
- Linkgithub.com/nltk/nltk/commit/0e26734a61094b628d93e26dc18dd7302567ac46
- Packagegithub.com/nltk/nltk
- Linkgithub.com/nltk/nltk/releases/tag/3.9.3
- Linkgithub.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2026-3729.yaml
- Linkhuntr.com/bounties/659ccf6d-12d4-4d4a-84c0-078633c35a5d
- Linkwww.vulncheck.com/advisories/nltk-before-missing-post-download-integrity-verification
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.