NLTK: command injection
Summary
NLTK 3.10.3 contains security hardening intended to close JVM argument-injection and untrusted JAR/classpath execution paths in nltk.internals.java(), including the issue published as GHSA-m4rf-3fr8-xwx3.
The patched options channel correctly rejects Java argument-file references such as @/path/to/args and launcher modes such as -jar. However, an additional argument channel remains: the caller-provided cmd sequence is appended to the Java command after the validated option and classpath channels, without enforcing that its first item is a Java main-class name.
I am reporting this as an additional post-fix bypass / incomplete-fix path affecting the 3.10.3 remediation, rather than as an unrelated vulnerability family.
As a result, the same launcher token that is rejected through options can be supplied as the first cmd item. I confirmed two reachable forms against the official nltk-3.10.3-py3-none-any.whl:
1. direct use of the public nltk.internals.java() helper with cmd=["-jar", ...]; and
2. the higher-level StanfordSegmenter, whose public java_class constructor argument becomes the first cmd item and accepts an @argfile launcher token.
Both paths execute an external researcher-controlled JAR without setting NLTK_ALLOW_UNSAFE_JARS, NLTK_ALLOW_UNSAFE_CLASSPATH, or using trusted_raw_options. The original explicit...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| nltk PyPI | >= 3.10.3, < 3.10.4 | 3.10.4 |
Details and references
## Summary NLTK 3.10.3 contains security hardening intended to close JVM argument-injection and untrusted JAR/classpath execution paths in `nltk.internals.java()`, including the issue published as GHSA-m4rf-3fr8-xwx3. The patched `options` channel correctly rejects Java argument-file references such as `@/path/to/args` and launcher modes such as `-jar`. However, an additional argument channel remains: the caller-provided `cmd` sequence is appended to the Java command after the validated option and classpath channels, without enforcing that its first item is a Java main-class name. I am reporting this as an additional post-fix bypass / incomplete-fix path affecting the 3.10.3 remediation, rather than as an unrelated vulnerability family. As a result, the same launcher token that is rejected through `options` can be supplied as the first `cmd` item. I confirmed two reachable forms against the official `nltk-3.10.3-py3-none-any.whl`: 1. direct use of the public `nltk.internals.java()` helper with `cmd=["-jar", ...]`; and 2. the higher-level `StanfordSegmenter`, whose public `java_class` constructor argument becomes the first `cmd` item and accepts an `@argfile` launcher token. Both paths execute an external researcher-controlled JAR without setting `NLTK_ALLOW_UNSAFE_JARS`, `NLTK_ALLOW_UNSAFE_CLASSPATH`, or using `trusted_raw_options`. The original explicit outside-classpath route is blocked in 3.10.3, while the alternate command channel executes the JAR 3/3 times. ## Affected artifact ```text Package: nltk Confirmed affected version: 3.10.3 Wheel: nltk-3.10.3-py3-none-any.whl SHA-256: ff9598a8e20518ee0d557745890cc4435b9578489e2dcbc69c4f81fa060caf7c ``` Baseline artifact: ```text Version: 3.10.2 Wheel: nltk-3.10.2-py3-none-any.whl SHA-256: 2c7ccacb765c5e26b0cb60fb1b57080af522c6924d12a714a243305ba3637412 ``` ## Relationship to the 3.10.3 security fixes The existing 3.10.3 hardening validates the dedicated per-call `options` list before it reaches `subprocess.Popen`. In particular, the exact `@argfile` token used in this report is rejected through `options` with a `ValueError` that references CVE-2026-12841 and CWE-88. The command is subsequently assembled in this order: ```python final_cmd.extend(validated_options) if classpath_arg is not None: final_cmd.extend(["-cp", classpath_arg]) final_cmd.extend(cmd_list) ``` `cmd_list` is copied from the public `cmd` argument but its first token is not checked to ensure that it is an ordinary Java main class. Java therefore interprets leading `-jar`, `@argfile`, module-mode, or classpath-mode tokens as launcher control arguments rather than application arguments. This is an alternate argument channel around the same JVM argument/JAR execution boundary protected by the 3.10.3 changes. ## Confirmed API paths ### Direct public helper ```python nltk.internals.java( ["-jar", "/outside/trusted/roots/controlled.jar"], classpath=None, stdout="pipe", stderr="pipe", ) ``` The external JAR executed in all three subject runs. ### Higher-level `StanfordSegmenter` path `StanfordSegmenter` exposes a public `java_class` constructor argument, stores it, and later places it at the beginning of the `cmd` sequence passed to `nltk.internals.java()`. A controlled argument file containing a `-jar` launcher invocation was supplied as: ```python 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 passed the wrapper's checksum and classpath checks. The `@argfile` then switched the Java launcher to the external JAR, which executed in all three runs. The deprecated wrapper subsequently raised an unrelated post-launch `AttributeError` while processing its output. The external marker had already been written by the child JVM before that exception. ## Proof matrix ```text R1 NLTK 3.10.2 + explicit external classpath -> control