/

CVE-2026-63312

Severity:

HIGH RISK

(7.5)

Path Traversal (CWE-22) in NLTK Corpus Reader Component

CVE-2026-63312

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary Local File Read

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

NLTK before version 3.10.0 contains a path traversal issue in StreamBackedCorpusView that can allow arbitrary local file reads.

If an attacker controls the fileid argument, the code may read files outside the intended corpus location, including sensitive system files or application credentials, even when pathsec.ENFORCE is enabled.

Affected context

The vulnerability occurs in NLTK's StreamBackedCorpusView when a caller-controlled fileid is used to access corpus data. The risk is present where untrusted input can influence that identifier and the implementation uses builtins.open() directly rather than the security-aware pathsec.open() enforcement path. Exploitation depends on the attacker being able to reach the affected corpus-reading functionality and influence the file selection value.

Exploit preconditions

  • Attack surface: An application or service that uses NLTK's StreamBackedCorpusView
  • Required access: Ability to supply or influence the fileid argument
  • Trigger point: Opening a corpus resource through the affected file-reading path
  • Why exploitation is possible: Direct use of builtins.open() bypasses pathsec.ENFORCE and permits path values outside the intended corpus directory

Why this happens

The underlying bug is improper restriction of filesystem paths, mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.

The implementation relies on a security control in pathsec.open(), but a separate code path calls builtins.open() directly. As a result, the configured path enforcement is not consistently applied before a caller-controlled filename is opened. This creates a mismatch between the intended trust boundary and the actual filesystem access behavior.

Potential impact

  • An attacker could read arbitrary files accessible to the NLTK process.
  • Sensitive system configuration or application credentials may be exposed.
  • Authentication tokens, keys, or environment-specific secrets could be disclosed.
  • Information from readable files could support further compromise.
  • Confidential training data or locally stored application data may be retrieved.

General mitigation guidance

Mitigation generally focuses on ensuring that every filesystem access uses a consistently enforced, security-aware path handling mechanism.

Common defensive patterns include:

  • Route file access through approved path-validation and opening APIs.
  • Resolve and validate paths against an explicit allowed base directory.
  • Treat file identifiers and corpus names as untrusted input.
  • Prefer allowlisted resource identifiers over user-provided filesystem paths.
  • Apply least-privilege permissions to the process and its readable directories.
  • Avoid storing credentials or other sensitive material in locations readable by the application.
  • Add regression tests covering traversal sequences, absolute paths, symbolic links, and enforcement-disabled configurations.

How teams detect issues like this

Organizations can detect related issues through:

  • Static analysis rules that identify direct filesystem opens using caller-controlled paths.
  • Code review checks for inconsistent use of path-validation wrappers and raw file APIs.
  • Tests that verify all corpus resource access remains within an approved directory.
  • Runtime monitoring for unexpected reads of system files, credential stores, or paths outside application data directories.
  • Policy enforcement requiring centralized filesystem access functions for untrusted filenames.

Automated code review and software composition analysis tools may help identify unsafe path handling, but findings should be validated against the application's actual input and permission boundaries.

Sources

SourceLink
github.comgithub.com/nltk/nltk/security/advisories/GHSA-x5ph-mj9p-rfr8
vulncheck.comvulncheck.com/advisories/nltk-streambackedcorpusview-bypasses-pathsec-enforce-arbitrary-file-read

Frequently asked

questions

It can be exploitable through a remote application if that application exposes NLTK functionality that allows an attacker to control the fileid argument. In other deployments, exploitation may require local access or access to an upstream data-processing interface.

The attacker must be able to influence the file identifier used by StreamBackedCorpusView and the NLTK process must have read permission for the targeted file.

Ensure that all file access uses a security-aware path-opening mechanism, validates resolved paths against an allowed directory, and rejects untrusted absolute or traversal-based paths.

Use resource identifiers rather than raw paths, centralize filesystem access, apply least-privilege permissions, and test path enforcement across every code path that opens files.

Find out what's already
exploitable in your codebase.