Executive brief
NLTK is a widely-used Python library for natural language processing that automatically downloads language data packages. The library fails to verify that downloaded packages haven't been tampered with before extracting and using them. An attacker could intercept downloads via network interception or DNS poisoning to inject malicious code that would be automatically extracted and executed, compromising any system using the affected NLTK versions.
Technical details
NLTK's downloader module (nltk/downloader.py) downloads packages to a temporary file, moves the file to its final location via os.replace(), and then immediately begins extraction via _unzip_iter(). However, there is no integrity verification step between the move and extraction. Although checksum validation logic exists in _pkg_status(), it is only invoked before download as a status check and never used to verify the downloaded file. The vulnerability enables multiple attack vectors: HTTP man-in-the-middle attacks (NLTK defaults to HTTP on some mirrors), race conditions on shared filesystems, and DNS poisoning. The fix involves computing and verifying the SHA-256 hash of the downloaded file against the expected checksum from the package index before extraction. NLTK 3.9.3 and later include this integrity check. This vulnerability is distinct from prior pickle deserialization and zip-slip vulnerabilities, as it addresses the gap before extraction rather than after.
Affected products
- NLTK NLTK <= 3.9.2
Timeline
- 2026-08-22: disclosed
- 2026-08-22: patched: NLTK 3.9.3 includes integrity verification fix