GHSA-5wp5-5229-5g6q

Suggest an improvement
Source
https://github.com/advisories/GHSA-5wp5-5229-5g6q
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-5wp5-5229-5g6q/GHSA-5wp5-5229-5g6q.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-5wp5-5229-5g6q
Aliases
Downstream
Published
2026-09-08T15:27:55Z
Modified
2026-09-10T11:25:57Z
Severity
  • 5.3 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N CVSS Calculator
Summary
NLTK: Missing Post-Download Integrity Verification Allows Malicious Package Injection
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 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.

Database specific
{
    "cwe_ids": [
        "CWE-494"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-09-08T15:27:55Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
}
References

Affected packages

PyPI / nltk

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
3.9.3

Affected versions

2.*
2.0.1rc2-git
2.0b4
2.0b5
2.0b6
2.0b7
2.0b8
2.0b9
2.0.1rc1
2.0.1rc3
2.0.1rc4
2.0.1
2.0.2
2.0.3
2.0.4
2.0.5
0.*
0.8
0.9
0.9.3
0.9.4
0.9.5
0.9.6
0.9.7
0.9.8
0.9.9
3.*
3.0.0b1
3.0.0b2
3.0.0
3.0.1
3.0.2
3.0.3
3.0.4
3.0.5
3.1
3.2
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.3
3.4
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.5b1
3.5
3.6
3.6.1
3.6.2
3.6.3
3.6.4
3.6.5
3.6.6
3.6.7
3.7
3.8
3.8.1
3.9b1
3.9
3.9.1
3.9.2

Database specific

last_known_affected_version_range
"<= 3.9.2"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-5wp5-5229-5g6q/GHSA-5wp5-5229-5g6q.json"