CVE-2026-12259
JSON

5.3medium

Improper Input Validation in nltk/nltk

Severity
5.3medium CVSS:3.0 by @huntr_ai
Exploit likelihood
0.10% (higher than 0% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
@huntr_ai
Also known as
GHSA-5wp5-5229-5g6qGHSA-gf32-cmjh-8m9vPYSEC-2026-3729PYSEC-2026-4318

Description

In nltk version 3.9.4, the `nltk.downloader.Downloader._download_package()` 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.

Affected

Product or packageVersionsReported by
nltk nltk/nltkfrom unspecified up to latestCVE List
nltk (PyPI)before 3.9.3, up to 3.9.2, up to 3.9.4GitHub Advisory Database, PyPA Advisory Database
nltk nltk3.9.4NVD

All scores

@huntr_ai5.3medium CVSS:3.0CVSS:3.0/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N
GitHub5.3medium CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N
GitHub7.1critical CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:H/A:H
GitHubcritical CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
NVD6.5medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N
PyPA Advisory Database6.5medium CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:H/A:N
PyPA Advisory Database6.5medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N

Classification

CWE-494

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

In nltk version 3.9.4, the `nltk.downloader.Downloader._download_package()` 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.

GitHub Advisory Database

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 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.

GitHub Advisory Database

Duplicate Advisory

This advisory has been withdrawn because it is a duplicate of GHSA-5wp5-5229-5g6q. This link is maintained to preserve external references.

Original Description

NLTK before 3.9.3 fails to verify file integrity after downloading packages and before extraction in the downloader module. Attackers can perform man-in-the-middle attacks or DNS poisoning to inject malicious package contents that are extracted without validation.

NVD (es)

En la versión 3.9.4 de nltk, la función “nltk.downloader.Downloader._download_package()” escribe los bytes del paquete descargado en el disco y puede extraerlos antes de aplicar la validación de suma de comprobación SHA-256 o MD5. Esto permite a un atacante manipular el cuerpo de la respuesta del paquete para “info.url” a través de un espejo comprometido, un proxy malicioso u otra condición de sustitución de origen, lo que lleva a la instalación de bytes de paquete controlados por el atacante. La vulnerabilidad puede resultar en que contenido malicioso de corpus o modelo sea confiado por usuarios o aplicaciones posteriores.

PyPA Advisory Database

NLTK before 3.9.3 fails to verify file integrity after downloading packages and before extraction in the downloader module. Attackers can perform man-in-the-middle attacks or DNS poisoning to inject malicious package contents that are extracted without validation.

References

Related

Sources

SourceRecordLicence
CVE ListCVE-2026-12259 changed 2026-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-5wp5-5229-5g6q changed 2026-10-16CC-BY-4.0
GitHub Advisory DatabaseGHSA-gf32-cmjh-8m9v changed 2026-10-16CC-BY-4.0
NVDCVE-2026-12259 changed 2026-10-23Public domain
PyPA Advisory DatabasePYSEC-2026-3729 changed 2026-10-16CC-BY-4.0
PyPA Advisory DatabasePYSEC-2026-4318 changed 2026-10-16CC-BY-4.0