CVE-2025-71408
NLTK collocations eval injection allows code execution via CLI arguments.
- CVSS 8.5
- CWE-95
- Input Validation and Sanitization
- Local
NLTK (Natural Language Toolkit) before version 3.9.3 contains an eval injection vulnerability in the nltk.collocations module that allows an attacker who controls command-line arguments to execute arbitrary Python code. When collocations.py is invoked directly, the __main__ block passes command-line arguments directly to eval() as suffixes of BigramAssocMeasures without allowlist validation or sanitization, enabling an attacker to supply a Python expression that escapes the intended attribute lookup and executes arbitrary code including OS commands via the os module.
- CWE
- CWE-95
- CVSS base score
- 8.5
- Published
- 2026-07-24
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- NLTK
- Fixed by upgrading
- Yes
Solution
Upgrade NLTK to version 3.9.3 or later.
Vulnerable code sample
import sys
from nltk.metrics import BigramAssocMeasures
def _measure_from_argv():
"""Resolve the association measure named on the command line."""
suffix = sys.argv[1] if len(sys.argv) > 1 else "raw_freq"
# VULNERABLE: command-line suffix is evaluated as Python code
return eval("BigramAssocMeasures." + suffix)Patched code sample
import sys
from nltk.metrics import BigramAssocMeasures
ALLOWED_MEASURES = frozenset(
["raw_freq", "pmi", "student_t", "chi_sq", "likelihood_ratio"]
)
def _measure_from_argv():
"""Resolve the association measure named on the command line."""
suffix = sys.argv[1] if len(sys.argv) > 1 else "raw_freq"
if suffix not in ALLOWED_MEASURES:
raise ValueError("unknown association measure: %s" % suffix)
# FIX: allowlisted attribute lookup replaces eval of untrusted input
return getattr(BigramAssocMeasures, suffix)Payload
__import__('os').system('id')
Cite this entry
@misc{vaitp:cve202571408,
title = {{NLTK collocations eval injection allows code execution via CLI arguments.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2025-71408},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-71408/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
