CVE-2025-71408 in NLTKinfo

Summary

by MITRE • 07/25/2026

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.

If you want to get the best quality for vulnerability data then you always have to consider VulDB.

Analysis

by VulDB Data Team • 07/25/2026

The NLTK library represents a widely adopted toolkit for natural language processing in python environments, with applications spanning academic research, commercial software development, and enterprise automation systems. The vulnerability discovered in versions prior to 3.9.3 resides within the nltk.collocations module specifically when the collocations.py script is executed directly through command-line invocation. This presents a critical security risk as it allows for arbitrary code execution through improper input handling within the application's main execution block.

The technical flaw manifests in how the _main_ block processes command-line arguments without proper validation or sanitization mechanisms. When users invoke the module directly, the script accepts arguments that are subsequently passed to eval() function calls within the BigramAssocMeasures class hierarchy. This design pattern creates a direct code injection vector where attacker-controlled input bypasses any intended security boundaries. The vulnerability stems from the absence of allowlist validation or input sanitization that would normally prevent malicious payloads from being executed as legitimate Python expressions.

The operational impact of this vulnerability extends beyond simple code execution to potentially compromise entire systems when the affected NLTK library is used in production environments. Attackers can leverage this flaw to execute arbitrary OS commands through the os module, effectively gaining complete control over the underlying operating system where the vulnerable application runs. This makes the vulnerability particularly dangerous in server-side applications, automated processing pipelines, or any environment where NLTK processes untrusted input data from external sources.

This vulnerability aligns with CWE-94, which specifically addresses "Improper Control of Generation of Code ('Code Injection')" and can be mapped to ATT&CK technique T1059.001 for "Command and Scripting Interpreter: Python" within the execution phase of the attack chain. The lack of proper input validation in the command-line argument processing creates an attack surface that allows for privilege escalation when the vulnerable application executes with elevated permissions. Organizations using NLTK in production systems face significant risk exposure, particularly in environments where automated processing of external data feeds or user-supplied text inputs occurs.

The recommended mitigation strategy involves upgrading to NLTK version 3.9.3 or later, which implements proper input validation and sanitization mechanisms for command-line arguments. Additionally, system administrators should implement strict input validation at multiple layers including application-level filtering, network-level restrictions, and monitoring for suspicious command execution patterns. Organizations should also consider implementing runtime protections such as python sandboxing or restricted execution environments to limit the potential impact of any remaining vulnerabilities in legacy deployments.

Responsible

VulnCheck

Reservation

07/24/2026

Disclosure

07/25/2026

Moderation

accepted

CPE

ready

EPSS

0.00158

KEV

no

Activities

very low

Sources

Might our Artificial Intelligence support you?

Check our Alexa App!