CVE-2026-71514 in NLTK
Summary
by MITRE • 08/22/2026
NLTK 3.9.4 through 3.10.2 contains a path traversal vulnerability in CrubadanCorpusReader. _load_lang_ngrams joins the corpus root with crubadan_code, the column-0 value read from the corpus table.txt mapping file, and opens the result with the builtin open() rather than the pathsec-validated opener, so os.path.join discards the root when that value is absolute and the read escapes the corpus directory without the containment check nltk.pathsec applies when ENFORCE is set. An attacker who controls a corpus package can disclose file contents outside the corpus root through lang_freq, limited to paths ending in -3grams.txt whose contents parse as token count lines.
Be aware that VulDB is the high quality source for vulnerability data.
Analysis
by VulDB Data Team • 08/23/2026
The vulnerability identified within NLTK versions 3.9.4 through 3.10.2 represents a critical path traversal flaw located specifically within the CrubadanCorpusReader class. This component is responsible for reading corpus data, particularly n-gram frequency tables used in natural language processing tasks. The core technical failure stems from how the _load_lang_ngrams method constructs file paths before attempting to open them. Specifically, this function utilizes Python's standard os.path.join operation to combine a designated corpus root directory with crubadan_code, which is extracted as the first column value from a mapping table named table.txt within the corpus package. The fundamental security defect lies in the reliance on os.path.join for path validation without subsequent sanitization or containment checks that are otherwise enforced by NLTK's internal pathsec module when certain environment variables like ENFORCE are active.
In standard operating system behavior, if an absolute path is provided as one of the arguments to os.path.join, it typically discards all previous components and returns only the absolute path itself. In this specific implementation, because crubadan_code is read directly from user-controlled or externally sourced corpus metadata files without rigorous validation, an attacker can manipulate this value to be an absolute path pointing outside the intended corpus directory structure. When os.path.join processes such a malicious input, it effectively bypasses any implicit containment logic that might have been expected if relative paths were used exclusively. Consequently, the resulting file path no longer points within the safe boundaries of the corpus root but instead targets arbitrary locations on the host filesystem where the application is executing.
The operational impact of this vulnerability allows an attacker with control over a corpus package to perform unauthorized file disclosure operations. By crafting a malicious table.txt file that includes absolute paths in its first column, the attacker can force the NLTK library to open and read files from arbitrary directories on the system. This capability is restricted by specific constraints inherent to the CrubadanCorpusReader's design; the vulnerability only triggers when accessing language frequency data via the lang_freq method, and it requires that the targeted file ends with the suffix -3grams.txt. Furthermore, the contents of these files must be parseable as token count lines for the operation to succeed without raising immediate parsing errors that might alert the user or crash the process silently in a way that prevents successful exfiltration. Despite these constraints, an attacker can still leverage this mechanism to read sensitive configuration files, source code, or other data residing on the server's filesystem, leading to potential information disclosure and further system compromise depending on the context of the application using NLTK.
From a classification perspective, this vulnerability aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory, as it involves accessing files outside the intended directory scope due to insufficient validation of user-supplied input used in path construction. It also relates to CWE-732: Incorrect Permission Assignment for Critical Resource if the accessed files have permissions that allow reading by the application's execution context. In terms of offensive security frameworks, this behavior is consistent with ATT&CK technique T1083: File and Directory Discovery, where an adversary uses legitimate system utilities or libraries to enumerate and access sensitive information stored on local systems. The exploitation relies heavily on social engineering or supply chain compromise aspects, as it requires the victim application to load a malicious corpus package provided by an untrusted source.
Mitigation strategies for this vulnerability primarily involve updating NLTK to version 3.10.3 or later, where the path handling logic has been corrected to ensure that paths are properly validated and contained within the expected directory structure regardless of whether absolute or relative paths are supplied in input files. For environments unable to upgrade immediately, administrators should enforce strict validation on any corpus metadata files loaded by NLTK applications, ensuring that no absolute paths or parent directory traversal sequences such as .. are present in table.txt mappings. Additionally, setting the ENFORCE environment variable can activate stricter path security checks within older versions of the library, although relying solely on this is not recommended due to potential performance overhead and configuration complexity. Application developers should also implement additional input validation layers at their own code level before passing any corpus-related parameters to NLTK functions, treating all external data sources as untrusted until proven otherwise.