GHSA-XMFG-F9CM-W86Q
Vulnerability from github – Published: 2026-11-16 14:47 – Updated: 2026-11-16 14:47Summary
nltk.sem.chat80.sql_query() opens a SQLite database by handing the result of nltk.data.find(dbname) straight to sqlite3.connect() without the path-containment check that the NLTK data sandbox (nltk.pathsec) is meant to enforce. nltk.data.find() applies only lexical checks to the resource name and returns a FileSystemPathPointer whose path is normalized with os.path.abspath but never resolved for symlinks. As a result, an in-root symbolic link that points at a SQLite file outside every registered NLTK data root is followed by SQLite, and the caller receives query results from the out-of-sandbox database. An attacker who can place a file inside a directory the application trusts as an NLTK data root can read SQLite databases that the pathsec sandbox is supposed to keep out of reach.
Root Cause
The security invariant is that file access performed through NLTK data resolution must stay within the configured data roots; the sandbox enforces this in nltk.pathsec via validate_path and pathsec.open, which resolve the real path (Path(...).resolve()) and reject targets outside the allowed roots. sql_query() never reaches that enforcement point. It calls nltk.data.find(dbname), whose guards operate purely on the resource-name string, and FileSystemPathPointer.__init__ performs only os.path.abspath plus an existence check, which does not collapse symlinks. The pointer is then passed to sqlite3.connect(str(path)), so the containment decision that FileSystemPathPointer.open() would delegate to pathsec.open is bypassed entirely. The sibling functions in the same module that create or write databases (cities2table, val_dump, val_load) obtain their protection from a validation call in later development, but the read sink sql_query performs no equivalent check in any published release.
nltk/sem/chat80.py -> sql_query(): path = nltk.data.find(dbname); sqlite3.connect(str(path))
nltk/data.py -> find(): lexical name guards only; returns FileSystemPathPointer
nltk/data.py -> FileSystemPathPointer.__init__(): os.path.abspath + os.path.exists (no symlink resolution)
nltk/data.py -> FileSystemPathPointer.open() -> nltk.pathsec.open (the containment guard that sql_query never calls)
Impact
An attacker who can write into a directory the application registers as an NLTK data root (a shared or writable corpus directory, or a downloaded corpus) can plant a symbolic link at the expected resource location that points at a SQLite database elsewhere on the filesystem. When the application invokes sql_query() (directly or via sql_demo()) for that resource, SQLite follows the link and the query executes against the out-of-sandbox database, returning its rows to the caller. This escapes the pathsec confidentiality boundary. The read primitive is bounded to SQLite-format files that are readable by the process user: a non-SQLite target raises sqlite3.DatabaseError rather than leaking content. A caller-supplied write query would be redirected onto the out-of-sandbox target and SQLite may create sidecar files (-wal, -journal) next to it, which is a plausible integrity side effect rather than a demonstrated arbitrary-write primitive. Exploitation requires the same local write capability into a trusted data root as the related symlink-read sandbox-escape issues already recorded for this project.
Proof of Concept
Requires the published nltk 3.10.3 wheel and a writable directory registered as an NLTK data root. No network access is needed.
- Create a throwaway data root with the expected corpus subdirectory.
- Create a SQLite database outside that root and populate it.
- Plant an in-root symbolic link at
corpora/city_database/city.dbpointing at the outside database. - Register the data root and call
sql_query()for the in-root resource name.
import os, tempfile, sqlite3, nltk, nltk.data
from nltk.sem import chat80
work = tempfile.mkdtemp()
root = os.path.join(work, "nltk_data")
corp = os.path.join(root, "corpora", "city_database")
os.makedirs(corp)
secret = os.path.join(work, "outside", "secret.db")
os.makedirs(os.path.dirname(secret))
con = sqlite3.connect(secret)
con.execute("CREATE TABLE t (x text)")
con.execute("INSERT INTO t VALUES ('OUT-OF-SANDBOX-SECRET')")
con.commit(); con.close()
os.symlink(secret, os.path.join(corp, "city.db"))
nltk.data.path.insert(0, root)
ptr = nltk.data.find("corpora/city_database/city.db")
try:
ptr.open().read() # pathsec route: blocked
except Exception as e:
print("open() blocked:", type(e).__name__)
cur = chat80.sql_query("corpora/city_database/city.db", "SELECT * FROM t")
print("sql_query rows:", cur.fetchall()) # sink route: follows the symlink
open() blocked: PermissionError
sql_query rows: [('OUT-OF-SANDBOX-SECRET',)]
Attack Chain
- Exposure: The application exposes
sql_query()(orsql_demo(), which calls it) and resolves the target database throughnltk.data.find, using at least one directory the attacker can write to as a data root. - Control: The attacker controls the on-disk object at the in-root resource path, replacing it with a symbolic link whose target is chosen freely. The resource-name argument stays a clean, in-root string.
- Path:
nltk.data.findapplies its lexical name guards (_UNSAFE_NO_PROTOCOL_RE, encoded and normalized-form checks), which inspect only the name string and pass, then returns aFileSystemPathPointerwhose__init__appliesos.path.abspathand an existence check without resolving the symlink. - Guard: The containment guard (
FileSystemPathPointer.open()delegating tonltk.pathsec.open, which resolves the real path and rejects out-of-root targets) is never invoked, becausesql_query()passes the raw pointer string tosqlite3.connect()instead of opening through the pointer. - Primitive:
sqlite3.connect(str(path))opens the symlink target; the kernel follows the link out of every data root and the cursor executes the query against the outside database. - Result: Rows from a SQLite database outside the sandbox are returned to the caller, escaping the pathsec confidentiality boundary for SQLite-format files readable by the process user.
Bypass Evidence
The relevant guard is the pathsec containment enforced by nltk.pathsec.open/validate_path, reached through FileSystemPathPointer.open(). On an identical pointer produced from the planted symlink, ptr.open() raises PermissionError with an "Unauthorized path" security violation, confirming the guard is active and correct for the sandbox route. sql_query() does not call .open() and does not call validate_path; it passes the unresolved pointer string directly to sqlite3.connect(), so the guard never runs on this path and the read succeeds. Attempts to invalidate the finding were made and failed: nltk.data.find was checked for a hidden containment or real-path resolution and has none (its guards are name-string only, and FileSystemPathPointer.__init__ uses abspath, not realpath); SQLite was confirmed to follow the link and read the outside file rather than opening the link node; and the possibility that an existing published fix already covers this sink was refuted by inspecting the published artifacts, where no containment check is present on sql_query. The behavior was reproduced against the exact published 3.10.3 wheel (verified by its published SHA-256 digest).
Affected Versions
Ecosystem: PyPIPackage: nltkConfirmed affected range: >= 3.9.4, <= 3.10.3Latest release checked: 3.10.3 (PyPI, wheel SHA-256 ff9598a8e20518ee0d557745890cc4435b9578489e2dcbc69c4f81fa060caf7c)Fix status: 3.10.4
The pathsec sandbox that this issue bypasses was introduced in 3.9.4; the immediately preceding release 3.9.3 does not ship nltk/pathsec.py and therefore does not present this sandbox-escape surface. Every published release from 3.9.4 through the current latest 3.10.3 ships nltk/pathsec.py with ENFORCE = True and ships sql_query() without any containment check, so all of them are affected. Each affected wheel was fetched from PyPI and inspected directly. No published release removes the sink or adds the guard, so no fixed version exists at the time of review.
Suggested Fix
Enforce the data-root containment invariant on the resolved database path before opening it. In sql_query(), validate the path through the same mechanism the sibling functions use (for example validate_path(str(path), context="chat80.sql_query")) or open the database through the pointer's sandboxed open path rather than passing the raw string to sqlite3.connect(). The remediation should resolve symbolic links (real-path resolution) and reject targets outside the registered data roots, and it should cover any other read sinks that connect to on-disk databases resolved through nltk.data.find. As an interim mitigation, applications should ensure that no attacker-writable directory is registered as an NLTK data root and should avoid calling sql_query/sql_demo on resources that live in shared or untrusted locations.
Reported by zx (GitHub: @manus-pi).
Fix status (2026-09-28)
Status: IN PROGRESS (fix on an open pull request, not yet on develop).
PR: #3888 "Validate chat80.sql_query dbname for path containment (CWE-59/73)", open; head e0e890f51 at the time of this note. This is the same sink and vector as GHSA-xv54-447f-mj22 (now closed).
Fix commits: 9f5d2ea6d (sql_query calls validate_path before nltk.data.find, as cities2table, val_dump and val_load already do) and 47bd0476e (the file behind a sql_query resource name is resolved through the data roots and validated, and its store is pinned).
The advisory PoC (an in-root corpora/city_database/city.db symlink to an out-of-root SQLite file, resolved through find()) re-run on the PR head e0e890f51: refused with PermissionError (Security Violation [chat80.sql_query]: Unauthorized path, naming the symlink's resolved out-of-root target); the same resource name backed by a real in-root database still returns its rows on that head. On develop 2fa3f48fe the PoC returns the rows of the out-of-root database, so develop is VULNERABLE.
Probe: nltk/test/unit/security_probes/ghsa_xv54_447f_mj22.py on the PR (the sibling advisory GHSA-xv54-447f-mj22), FIXED on the PR head (absolute path, traversal and a symlink inside a scratch directory are all security-rejected). Those three cases are also rejected on develop by find() itself; the in-root symlink above is the case that only the PR closes.
Release: none.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 3.10.3"
},
"package": {
"ecosystem": "PyPI",
"name": "nltk"
},
"ranges": [
{
"events": [
{
"introduced": "3.9.4"
},
{
"fixed": "3.10.4"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-126302"
],
"database_specific": {
"cwe_ids": [
"CWE-22",
"CWE-59"
],
"github_reviewed": true,
"github_reviewed_at": "2026-11-16T14:47:23Z",
"nvd_published_at": null,
"severity": "MODERATE"
},
"details": "## Summary\n\n`nltk.sem.chat80.sql_query()` opens a SQLite database by handing the result of `nltk.data.find(dbname)` straight to `sqlite3.connect()` without the path-containment check that the NLTK data sandbox (`nltk.pathsec`) is meant to enforce. `nltk.data.find()` applies only lexical checks to the resource name and returns a `FileSystemPathPointer` whose path is normalized with `os.path.abspath` but never resolved for symlinks. As a result, an in-root symbolic link that points at a SQLite file outside every registered NLTK data root is followed by SQLite, and the caller receives query results from the out-of-sandbox database. An attacker who can place a file inside a directory the application trusts as an NLTK data root can read SQLite databases that the pathsec sandbox is supposed to keep out of reach.\n\n## Root Cause\n\nThe security invariant is that file access performed through NLTK data resolution must stay within the configured data roots; the sandbox enforces this in `nltk.pathsec` via `validate_path` and `pathsec.open`, which resolve the real path (`Path(...).resolve()`) and reject targets outside the allowed roots. `sql_query()` never reaches that enforcement point. It calls `nltk.data.find(dbname)`, whose guards operate purely on the resource-name string, and `FileSystemPathPointer.__init__` performs only `os.path.abspath` plus an existence check, which does not collapse symlinks. The pointer is then passed to `sqlite3.connect(str(path))`, so the containment decision that `FileSystemPathPointer.open()` would delegate to `pathsec.open` is bypassed entirely. The sibling functions in the same module that create or write databases (`cities2table`, `val_dump`, `val_load`) obtain their protection from a validation call in later development, but the read sink `sql_query` performs no equivalent check in any published release.\n\n```text\nnltk/sem/chat80.py -\u003e sql_query(): path = nltk.data.find(dbname); sqlite3.connect(str(path))\nnltk/data.py -\u003e find(): lexical name guards only; returns FileSystemPathPointer\nnltk/data.py -\u003e FileSystemPathPointer.__init__(): os.path.abspath + os.path.exists (no symlink resolution)\nnltk/data.py -\u003e FileSystemPathPointer.open() -\u003e nltk.pathsec.open (the containment guard that sql_query never calls)\n```\n\n## Impact\n\nAn attacker who can write into a directory the application registers as an NLTK data root (a shared or writable corpus directory, or a downloaded corpus) can plant a symbolic link at the expected resource location that points at a SQLite database elsewhere on the filesystem. When the application invokes `sql_query()` (directly or via `sql_demo()`) for that resource, SQLite follows the link and the query executes against the out-of-sandbox database, returning its rows to the caller. This escapes the pathsec confidentiality boundary. The read primitive is bounded to SQLite-format files that are readable by the process user: a non-SQLite target raises `sqlite3.DatabaseError` rather than leaking content. A caller-supplied write query would be redirected onto the out-of-sandbox target and SQLite may create sidecar files (`-wal`, `-journal`) next to it, which is a plausible integrity side effect rather than a demonstrated arbitrary-write primitive. Exploitation requires the same local write capability into a trusted data root as the related symlink-read sandbox-escape issues already recorded for this project.\n\n## Proof of Concept\n\n`Requires the published nltk 3.10.3 wheel and a writable directory registered as an NLTK data root. No network access is needed.`\n\n1. Create a throwaway data root with the expected corpus subdirectory.\n2. Create a SQLite database outside that root and populate it.\n3. Plant an in-root symbolic link at `corpora/city_database/city.db` pointing at the outside database.\n4. Register the data root and call `sql_query()` for the in-root resource name.\n\n```python\nimport os, tempfile, sqlite3, nltk, nltk.data\nfrom nltk.sem import chat80\n\nwork = tempfile.mkdtemp()\nroot = os.path.join(work, \"nltk_data\")\ncorp = os.path.join(root, \"corpora\", \"city_database\")\nos.makedirs(corp)\n\nsecret = os.path.join(work, \"outside\", \"secret.db\")\nos.makedirs(os.path.dirname(secret))\ncon = sqlite3.connect(secret)\ncon.execute(\"CREATE TABLE t (x text)\")\ncon.execute(\"INSERT INTO t VALUES (\u0027OUT-OF-SANDBOX-SECRET\u0027)\")\ncon.commit(); con.close()\n\nos.symlink(secret, os.path.join(corp, \"city.db\"))\nnltk.data.path.insert(0, root)\n\nptr = nltk.data.find(\"corpora/city_database/city.db\")\ntry:\n ptr.open().read() # pathsec route: blocked\nexcept Exception as e:\n print(\"open() blocked:\", type(e).__name__)\n\ncur = chat80.sql_query(\"corpora/city_database/city.db\", \"SELECT * FROM t\")\nprint(\"sql_query rows:\", cur.fetchall()) # sink route: follows the symlink\n```\n\n```text\nopen() blocked: PermissionError\nsql_query rows: [(\u0027OUT-OF-SANDBOX-SECRET\u0027,)]\n```\n\n## Attack Chain\n\n1. **Exposure:** The application exposes `sql_query()` (or `sql_demo()`, which calls it) and resolves the target database through `nltk.data.find`, using at least one directory the attacker can write to as a data root.\n2. **Control:** The attacker controls the on-disk object at the in-root resource path, replacing it with a symbolic link whose target is chosen freely. The resource-name argument stays a clean, in-root string.\n3. **Path:** `nltk.data.find` applies its lexical name guards (`_UNSAFE_NO_PROTOCOL_RE`, encoded and normalized-form checks), which inspect only the name string and pass, then returns a `FileSystemPathPointer` whose `__init__` applies `os.path.abspath` and an existence check without resolving the symlink.\n4. **Guard:** The containment guard (`FileSystemPathPointer.open()` delegating to `nltk.pathsec.open`, which resolves the real path and rejects out-of-root targets) is never invoked, because `sql_query()` passes the raw pointer string to `sqlite3.connect()` instead of opening through the pointer.\n5. **Primitive:** `sqlite3.connect(str(path))` opens the symlink target; the kernel follows the link out of every data root and the cursor executes the query against the outside database.\n6. **Result:** Rows from a SQLite database outside the sandbox are returned to the caller, escaping the pathsec confidentiality boundary for SQLite-format files readable by the process user.\n\n## Bypass Evidence\n\nThe relevant guard is the pathsec containment enforced by `nltk.pathsec.open`/`validate_path`, reached through `FileSystemPathPointer.open()`. On an identical pointer produced from the planted symlink, `ptr.open()` raises `PermissionError` with an \"Unauthorized path\" security violation, confirming the guard is active and correct for the sandbox route. `sql_query()` does not call `.open()` and does not call `validate_path`; it passes the unresolved pointer string directly to `sqlite3.connect()`, so the guard never runs on this path and the read succeeds. Attempts to invalidate the finding were made and failed: `nltk.data.find` was checked for a hidden containment or real-path resolution and has none (its guards are name-string only, and `FileSystemPathPointer.__init__` uses `abspath`, not `realpath`); SQLite was confirmed to follow the link and read the outside file rather than opening the link node; and the possibility that an existing published fix already covers this sink was refuted by inspecting the published artifacts, where no containment check is present on `sql_query`. The behavior was reproduced against the exact published 3.10.3 wheel (verified by its published SHA-256 digest).\n\n## Affected Versions\n\n- `Ecosystem: PyPI`\n- `Package: nltk`\n- `Confirmed affected range: \u003e= 3.9.4, \u003c= 3.10.3`\n- `Latest release checked: 3.10.3 (PyPI, wheel SHA-256 ff9598a8e20518ee0d557745890cc4435b9578489e2dcbc69c4f81fa060caf7c)`\n- `Fix status: 3.10.4`\n\nThe pathsec sandbox that this issue bypasses was introduced in 3.9.4; the immediately preceding release 3.9.3 does not ship `nltk/pathsec.py` and therefore does not present this sandbox-escape surface. Every published release from 3.9.4 through the current latest 3.10.3 ships `nltk/pathsec.py` with `ENFORCE = True` and ships `sql_query()` without any containment check, so all of them are affected. Each affected wheel was fetched from PyPI and inspected directly. No published release removes the sink or adds the guard, so no fixed version exists at the time of review.\n\n## Suggested Fix\n\nEnforce the data-root containment invariant on the resolved database path before opening it. In `sql_query()`, validate the path through the same mechanism the sibling functions use (for example `validate_path(str(path), context=\"chat80.sql_query\")`) or open the database through the pointer\u0027s sandboxed open path rather than passing the raw string to `sqlite3.connect()`. The remediation should resolve symbolic links (real-path resolution) and reject targets outside the registered data roots, and it should cover any other read sinks that connect to on-disk databases resolved through `nltk.data.find`. As an interim mitigation, applications should ensure that no attacker-writable directory is registered as an NLTK data root and should avoid calling `sql_query`/`sql_demo` on resources that live in shared or untrusted locations.\n\nReported by zx (GitHub: @manus-pi).\n\n## Fix status (2026-09-28)\n\nStatus: IN PROGRESS (fix on an open pull request, not yet on develop).\n\nPR: #3888 \"Validate chat80.sql_query dbname for path containment (CWE-59/73)\", open; head e0e890f51 at the time of this note. This is the same sink and vector as GHSA-xv54-447f-mj22 (now closed).\n\nFix commits: 9f5d2ea6d (sql_query calls validate_path before nltk.data.find, as cities2table, val_dump and val_load already do) and 47bd0476e (the file behind a sql_query resource name is resolved through the data roots and validated, and its store is pinned).\n\nThe advisory PoC (an in-root corpora/city_database/city.db symlink to an out-of-root SQLite file, resolved through find()) re-run on the PR head e0e890f51: refused with PermissionError (Security Violation [chat80.sql_query]: Unauthorized path, naming the symlink\u0027s resolved out-of-root target); the same resource name backed by a real in-root database still returns its rows on that head. On develop 2fa3f48fe the PoC returns the rows of the out-of-root database, so develop is VULNERABLE.\n\nProbe: nltk/test/unit/security_probes/ghsa_xv54_447f_mj22.py on the PR (the sibling advisory GHSA-xv54-447f-mj22), FIXED on the PR head (absolute path, traversal and a symlink inside a scratch directory are all security-rejected). Those three cases are also rejected on develop by find() itself; the in-root symlink above is the case that only the PR closes.\n\nRelease: none.",
"id": "GHSA-xmfg-f9cm-w86q",
"modified": "2026-11-16T14:47:23Z",
"published": "2026-11-16T14:47:23Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/nltk/nltk/security/advisories/GHSA-xmfg-f9cm-w86q"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-126302"
},
{
"type": "PACKAGE",
"url": "https://github.com/nltk/nltk"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/nltk-3.9.4-before-3.10.4-symlink-sandbox-escape-via-chat80-sql-query"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N",
"type": "CVSS_V3"
}
],
"summary": "NLTK: Symlink escape in chat80.sql_query bypasses the pathsec data-root sandbox to read out-of-root SQLite databases"
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.