# NLTK incomplete fix: additional JVM/JAR sandbox bypass through unvalidated launcher tokens in java() command arguments

NLTK 3.10.3's java() hardening validated the options channel but not the leading cmd token, so `-jar` or `@argfile` there still launched attacker JARs.

- Payout: Research
- Severity: critical
- Program: NLTK
- Found by: kokomaru167
- Disclosed: 2026-11-19
- CVE: CVE-2026-128138
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-x8q7-6c7m-52gw
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-x8q7-6c7m-52gw
- Tags: area:oss domain:oss impact:rce kind:research platform:ghsa sev:critical tech:java tech:python technique:incomplete-fix technique:source-review vuln:command-injection vuln:sandbox-escape

**Target:** nltk.internals.java() helper and StanfordSegmenter java_class argument
**Root cause:** The 3.10.3 fix validated only the per-call `options` list; the caller-supplied `cmd` sequence is appended to the Java command without checking that its first token is a main class, so launcher switches like `-jar` and `@argfile` are interpreted by the JVM.
**Steps:**
1. Install nltk==3.10.3 and a JDK (java, javac, jar).
2. Build a controlled external JAR that writes a marker file.
3. Call `nltk.internals.java(["-jar", "/outside/trusted/roots/controlled.jar"], classpath=None, stdout="pipe", stderr="pipe")` — external JAR executes.
4. Alternatively call `StanfordSegmenter(path_to_jar=trusted_segmenter_jar, java_class="@/path/to/controlled-launcher.args", path_to_model="dummy-model", java_options=[])` where the argfile contains a `-jar` invocation — external JAR executes after checksum/classpath checks pass.
5. Confirm `options=["@argfile"]` is rejected with ValueError while the cmd/java_class channel executes 3/3.
**How found:** After the 3.10.3 fix blocked `@argfile` and `-jar` through `options`, the researcher read the command assembly order (`final_cmd.extend(validated_options)`, then `-cp`, then `final_cmd.extend(cmd_list)`) and noticed cmd_list's first token was never validated as a main class — the same launcher tokens reach the JVM through a different channel.
**Exploitation:** An embedding application that lets untrusted input reach the first item of java(cmd=...) or StanfordSegmenter(java_class=...) lets the attacker supply `-jar <path>` or an `@argfile` pointing at a readable JAR/argfile; the child JVM launches attacker bytecode with the NLTK process's privileges, bypassing NLTK_ALLOW_UNSAFE_JARS/CLASSPATH and trusted_raw_options.
**Insight:** When a fix validates one argument channel, enumerate every other list appended to the same subprocess argv and check whether the first token is constrained; wrapper classes that forward a public string (like java_class) into that position are the reachable path.

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

**Direct java() call with -jar launcher token**

```
nltk.internals.java(
    ["-jar", "/outside/trusted/roots/controlled.jar"],
    classpath=None,
    stdout="pipe",
    stderr="pipe",
)
```

**StanfordSegmenter java_class @argfile launcher bypass**

```
StanfordSegmenter(
    path_to_jar=trusted_segmenter_jar,
    java_class="@/path/to/controlled-launcher.args",
    path_to_model="dummy-model",
    java_options=[],
)
```

