NLTK JAR Sandbox Bypass, Fixed in 3.10.4 (CVE-2026-128138)
NLTK 3.10.3's java() helper trusts the first cmd token, so a crafted -jar or @argfile runs an external JAR; fixed in 3.10.4.
TL;DR
- NLTK 3.10.3 validates JVM options but appends the caller's
cmdsequence after them without checking its first token. Acmdthat starts with-jaror@argfileruns an external JAR. - Only NLTK 3.10.3 is affected by this CVE. The fix is in 3.10.4, released on 2026-10-21.
- GitHub rates it CVSS v3.1 9.8 Critical (CWE-77 and CWE-88). The advisory includes a public proof of concept, no exploitation is known, CISA records Exploitation: poc and the CVE is not in KEV as of 2026-11-20.
- Upgrade to 3.10.4. If the application passes user-influenced values into
nltk.internals.java()orStanfordSegmenter.java_class, treat that path as code execution until the upgrade is applied.
Am I affected?
All of these must hold:
- The application runs NLTK 3.10.3.
- The application calls
nltk.internals.java()with acmdsequence, directly or through a Stanford wrapper. - An attacker can influence the first item of that
cmdsequence, or thejava_classargument ofStanfordSegmenter.
NLTK is widely deployed. PyPI recorded 48,827,217 downloads in the last month and 12,986,010 in the last week when checked on 2026-11-20.
NLTK is a library, not a network service. The score assumes a caller that puts attacker-influenced values into the Java command. A command-line script that passes fixed class names is not exposed in the same way. A service that builds java_class or cmd from a request is.
Consider a document-processing service that lets a tenant choose a Stanford model, a tokenizer class or a JAR path. The service is the caller, and NLTK turns those choices into a command line. If the service does not validate the choice, the tenant's input reaches the Java launcher.
The same pattern appears in batch pipelines that read a class name from a job definition and in plugins that accept a Java helper from a configuration file.
| Branch | Affected versions | Fixed version |
|---|---|---|
| NLTK 3.10 | 3.10.3 only | 3.10.4 |
| NLTK 3.9 and earlier | not affected by this CVE | not applicable |
Check the installed version:
python -c "import nltk; print(nltk.__version__)"
pip show nltk | grep -E '^(Version|Location)'
Then search the codebase for both entry points:
grep -R "nltk.internals.java\|from nltk.internals import java\|StanfordSegmenter" --include='*.py' .
grep -R "java_class\s*=" --include='*.py' .
A hit is not a vulnerability by itself. Check whether the value comes from a request, a file, a database field or another source the attacker can change. In a multi-tenant service, trace every path that builds a Java command. Confirm that the class name and the JAR path come from a fixed allow-list, not from tenant data.
How do I fix it?
Upgrade to NLTK 3.10.4 or later:
pip install --upgrade "nltk>=3.10.4"
- Update every environment that installs NLTK, including containers and batch workers.
- Rebuild any image that pins 3.10.3.
- Recheck the two entry points in "Am I affected?" after the upgrade.
- If the application cannot upgrade immediately, stop passing attacker-influenced values into
cmdorjava_class. Use a fixed main class and a fixed JAR path.
There is no configuration switch that closes the flaw in 3.10.3. The library does not expose a runtime setting that validates the cmd channel. The only fix is the 3.10.4 code.
The upgrade also needs to reach the environments that run the code, not only the developer workstation. Rebuild container images that pin nltk==3.10.3, update the lock file used by the service, and check the virtual environment of every worker. A package installed in a base image can survive an application deployment.
What is the root cause?
nltk.internals.java() is a thin wrapper around the Java launcher. It builds a command from three sources: a validated options list, an optional classpath, and the caller's cmd sequence. The 3.10.3 hardening checked the options and the JAR sandbox, but it appended cmd_list to the final command without validating its first token.
The JAR sandbox checks the files named by path_to_jar and classpath. It confirms that they are inside the trusted data roots and refuses the unsafe-JAR and unsafe-classpath modes unless the application opts in. It does not inspect the cmd sequence, because that sequence is meant to name the main class and its program arguments, not to select a launcher mode.
The relevant code at NLTK 3.10.3 is:
final_cmd = []
if isinstance(_java_bin, str):
final_cmd.append(_java_bin)
else:
final_cmd.extend(_java_bin if _java_bin else ["java"])
final_cmd.extend(opt_list)
if classpath_arg is not None:
final_cmd.extend(["-cp", classpath_arg])
final_cmd.extend(cmd_list)
The Java launcher treats the first non-option token as the main class. If cmd_list[0] is -jar, the launcher switches to JAR mode and runs the JAR named by the next token. If it is @file, the launcher expands the argument file and takes its contents as launcher arguments. Both forms bypass the options validator, which only sees the options channel.
The @argfile form is the more flexible of the two. The Java launcher expands an argument file wherever it appears, so the token can follow a legitimate main class and still add launcher arguments. The 3.10.4 fix therefore rejects @ in any position, not only in the first item.
StanfordSegmenter places its public java_class argument at the front of cmd. In 3.10.3 the constructor stores the value without checking it, and segment_file() and segment_string() build a command whose first item is that value. An attacker who controls java_class controls the first launcher token.
The prior fixes explain the gap. CVE-2026-12841 added validation for global JVM options. CVE-2026-79675 fixed the unvalidated per-call options channel in 3.10.3. CVE-2026-128138 is the third channel: the cmd sequence, which the earlier fixes did not cover.
How is it exploited?
The advisory publishes a working proof of concept for the direct helper:
nltk.internals.java(
["-jar", "/outside/trusted/roots/controlled.jar"],
classpath=None,
stdout="pipe",
stderr="pipe",
)
The Java process starts the external JAR. The classpath is empty, and the NLTK JAR sandbox flags are not set. The JAR sits outside the trusted data roots that path_to_jar is checked against. The same result is reachable through the higher-level wrapper:
StanfordSegmenter(
path_to_jar=trusted_segmenter_jar,
java_class="@/path/to/controlled-launcher.args",
path_to_model="dummy-model",
java_options=[],
)
The trusted segmenter JAR passes the checksum and classpath checks. The argument file supplied as java_class then tells the launcher to run a different JAR. The advisory reports that the external marker was written in all three test runs before the wrapper raised an unrelated error.
The attacker needs control of the cmd first item or of java_class. That is an application-level condition, not a default NLTK behavior. The advisory does not name a vulnerable network service or a victim. No in-the-wild exploitation is known.
The attacker also needs the application to reach the call. A service that exposes a fixed endpoint with a fixed class name gives the attacker no control over the command. A service that accepts a model path, a class name or a list of extra arguments for a Java tool gives the attacker the channel this flaw needs.
How does the attack flow?
An attacker-controlled main-class token turns into a Java launcher switch, the launcher runs an external JAR, and the code runs as the Python process user.
What can an attacker do?
An attacker who controls the first cmd token can run an arbitrary JAR in a new Java process. That process runs as the same operating-system user as the Python application. It inherits the application's environment, including credentials and file access. It runs outside the JAR and classpath checks that NLTK applies to path_to_jar and classpath.
The child JVM is a normal operating-system process. It can read the application's environment variables, open any file the user can open and make outbound network connections. It can write a persistence file, start a background process or read a mounted secret.
NLTK's JAR flags are application-level checks on which JARs the wrapper will run. They are not a Java security sandbox and they do not restrict what a running JVM can do.
The same access is available through StanfordSegmenter.java_class when an application builds that value from untrusted input. The advisory demonstrates the direct helper and the wrapper path.
The conditions are NLTK 3.10.3, a call into java() or a Stanford wrapper, and attacker influence over the command's first token. Without that influence, the attacker has no path. The advisory does not show a default configuration that exposes the flaw over the network.
Why does the fix work?
NLTK 3.10.4 adds a guard before the command is assembled. The fix commit is b3621279:
@@ -340,6 +340,37 @@ def _normalise(stream):
+ if not cmd_list:
+ raise ValueError("cmd must contain a Java main class")
+ first = cmd_list[0]
+ if (
+ not isinstance(first, str)
+ or not first.strip()
+ or first.strip().startswith(("-", "@"))
+ ):
+ raise ValueError(
+ f"cmd must begin with a Java main class, not a launcher switch or "
+ f"@argfile: {first!r} (CWE-88)"
+ )
+ for tok in cmd_list:
+ if isinstance(tok, str) and tok.strip().startswith("@"):
+ raise ValueError(
+ f"cmd may not contain an @argfile token: {tok!r}; the Java "
+ "launcher would expand it, injecting arguments (CWE-88)"
+ )
+
final_cmd = []
The guard rejects a missing or non-string first token, any first token that starts with - or @, and any @argfile anywhere in the list. It compares the stripped token, so leading whitespace cannot hide a launcher switch. It runs after the options and classpath validators, so a hostile option is still reported by its own error path.
The commit adds regression tests for launcher switches, argument files, empty and non-string tokens, whitespace-prefixed tokens and a legitimate main class with program arguments. A mutation test proves the option validator is load-bearing. Those tests cover the cases the advisory used and the whitespace variants that a naive string check would miss.
The fix keeps legitimate program arguments that start with - after a real main class, such as the Stanford -loadClassifier flag. It closes the cmd channel that the 3.10.3 options validator did not cover. The release notes for 3.10.4 describe the broader change as running Java only from trusted absolute locations with validated options and input.
How do I check if I was compromised?
The advisory publishes no indicators of compromise. A successful run leaves the same traces as any Java process started by the application.
# Processes and command lines that start with a launcher switch
ps -eo pid,user,args | grep -E '[j]ava .*(-jar|@)'
# Recent Java processes owned by the application user
ps -eo pid,user,lstart,args | grep '[j]ava'
Look for an unexpected -jar path or an @argfile that the application did not deploy. Check the application logs for requests that reached the cmd or java_class code paths. If the application does not log those values, a past attempt may leave no trace.
The absence of a suspicious process is not proof that nothing happened. A short-lived JAR can exit before a process check runs. Correlate with application logs, outbound network connections and file writes in the application's working directory. If the application logs the arguments passed to java(), search those logs for -jar, @ and class names that are not in the deployment.
Timeline
- 2026-08-12: NLTK 3.10.3 shipped the hardening for CVE-2026-79675.
- 2026-08-19: The fix commit for the
cmdchannel was authored. - 2026-10-21: NLTK 3.10.4 was released on PyPI.
- 2026-11-19: GitHub published GHSA-x8q7-6c7m-52gw and the CVE-2026-128138 record.
FAQ
- Is NLTK 3.10.4 a security release? Yes. It closes the
cmdchannel described here, and its release notes describe a broad sandbox and input-validation hardening. - Does this affect every NLTK application? No. The application must pass attacker-influenced values into
java()orStanfordSegmenter.java_class. A script with fixed class names is not exposed. - Is it exploited in the wild? No exploitation is known, and the CVE is not in CISA KEV as of 2026-11-20. The advisory includes a public proof of concept.
- Is 3.10.3 the only affected version? Yes for this CVE. The advisory's affected range is 3.10.3 up to, but not including, 3.10.4.
- Can I keep 3.10.3 and validate the command myself? You can reject a
cmdwhose first token starts with-or@before callingjava(). That repeats the 3.10.4 guard in application code and is easy to miss on one call path, so the upgrade is safer. - Does the fix block legitimate Java options? No. It blocks launcher switches and argument files in the
cmdchannel. A real main class followed by-loadClassifierand other program arguments still works.
Find NLTK versions in your applications with Ostorlab
Ostorlab's software composition analysis and SBOM product inventories the libraries an application ships, including Python packages and their versions. It finds NLTK 3.10.3 before it reaches production: https://www.ostorlab.co/product/sca_sbom
References
- NLTK advisory GHSA-x8q7-6c7m-52gw: https://github.com/nltk/nltk/security/advisories/GHSA-x8q7-6c7m-52gw (checked November 20, 2026)
- CVE-2026-128138 record: https://www.cve.org/CVERecord?id=CVE-2026-128138 (checked November 20, 2026)
- NLTK fix commit b3621279: https://github.com/nltk/nltk/commit/b36212795a522d2b7b176cf0e0d9d8da489ba6e6 (checked November 20, 2026)
- NLTK pull request 3771: https://github.com/nltk/nltk/pull/3771 (checked November 20, 2026)
- NLTK 3.10.4 release: https://github.com/nltk/nltk/releases/tag/v3.10.4 (checked November 20, 2026)
internals.pyat NLTK 3.10.3: https://github.com/nltk/nltk/blob/v3.10.3/nltk/internals.py (checked November 20, 2026)stanford_segmenter.pyat NLTK 3.10.3: https://github.com/nltk/nltk/blob/v3.10.3/nltk/tokenize/stanford_segmenter.py (checked November 20, 2026)- Previous advisory GHSA-m4rf-3fr8-xwx3: https://github.com/nltk/nltk/security/advisories/GHSA-m4rf-3fr8-xwx3 (checked November 20, 2026)
- PyPI download statistics for NLTK: https://pypistats.org/packages/nltk (checked November 20, 2026)
- CISA KEV catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked November 20, 2026)