# NLTK dot2img runs Graphviz 'dot' without the trusted-exec chokepoint, enabling local code execution via a writable PATH element

NLTK's dot2img resolves Graphviz 'dot' via find_binary and runs it with raw subprocess.run, skipping spawn_trusted's ownership check and env scrub, so a trojan 'dot' in a writable PATH dir executes as the victim.

- Payout: Research
- Severity: high
- Program: NLTK
- Found by: manus-pi, manus-use
- Disclosed: 2026-11-16
- CVE: CVE-2026-128134
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-7mxv-7h3q-9324
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-7mxv-7h3q-9324
- Tags: area:oss domain:oss impact:privesc impact:rce kind:research platform:ghsa sev:high tech:python technique:incomplete-fix technique:source-review vuln:command-injection vuln:privilege-escalation

**Target:** nltk.parse.dependencygraph.dot2img Graphviz invoker
**Root cause:** dot2img calls find_binary("dot") (layer-1 CWD refusal only) then subprocess.run on the absolute path without env=, never routing through nltk.pathsec.spawn_trusted, so the ownership/writability check and loader-env scrub never run. The prior GHSA-6hwm-xvph-95vm fix hardened only the translate/api.py invoker.
**Steps:**
1. Create a world-writable dir and write an executable `dot` script that touches a MARKER and echoes fake SVG.
2. Prepend that dir to `PATH` and chdir to a neutral directory (e.g. `/`).
3. Call `dot2img("digraph G { a -> b }")`; the planted script runs and MARKER appears.
4. Confirm `resolve_trusted_executable(planted_dot)` returns None, proving the hardened path would refuse it.
**How found:** Audited NLTK's native-tool security model against the prior GHSA-6hwm-xvph-95vm remediation: noticed EXTERNAL_TOOL_SECURITY.md lists Graphviz dot only under translate/api.py, then read dependencygraph.py and found dot2img got the layer-1 find_binary change but not the spawn_trusted routing. Refuted duplicate/shadowing objections with a negative control (./dot with none on PATH raises LookupError) and confirmed both text and binary branches share the gap.
**Exploitation:** Local unprivileged attacker writes a trojan `dot` into any group/world-writable directory on the victim's PATH (e.g. Homebrew /usr/local/bin with drwxrwxr-x). When the victim renders a DependencyGraph (Jupyter `_repr_svg_` auto-invokes dot2img) or calls dot2img directly, the trojan executes as the victim with the full inherited environment, giving local code execution and a loader-injection surface (LD_PRELOAD, DYLD_*, GCONV_PATH).
**Escalation:** Unscrubbed child environment allows loader-injection variables to reach the child as an additional execution surface; local code exec in victim account enables lateral movement.
**Insight:** When a project standardizes a security chokepoint (spawn_trusted), enumerate every call site of the same external tool — grep for the binary name and for raw subprocess.run — and check the hardened-wrapper inventory doc; partial fixes leave sibling invokers exploitable. A negative control (planting ./dot with none on PATH) distinguishes a residual gap from a duplicate of the prior CWD fix.

## Proof of concept (copied exactly from the original report)

**Python PoC planting trojan dot on PATH**

```
import os, stat, tempfile, subprocess, sys
d = tempfile.mkdtemp()
dot = os.path.join(d, "dot")
with open(dot, "w") as f:
    f.write("#!/bin/sh\ntouch " + os.path.join(d, "MARKER") + "\necho '<svg><!-- planted dot ran --></svg>'\n")
os.chmod(dot, 0o777)
os.chmod(d, 0o777)
os.environ["PATH"] = d + os.pathsep + os.environ["PATH"]
os.chdir("/")
from nltk.pathsec import resolve_trusted_executable
from nltk.parse.dependencygraph import dot2img
print("resolve_trusted_executable(planted dot):", resolve_trusted_executable(os.path.join(d, "dot")))
out = dot2img("digraph G { a -> b }")
print("dot2img stdout:", repr(out))
print("planted dot executed (marker created):", os.path.exists(os.path.join(d, "MARKER")))
```

