Summary
NLTK's Java launcher can pass caller-controlled command arguments to Java without requiring the first argument to identify a main class. If an attacker can influence that argument sequence or the relevant Java class setting, options such as -jar or an argument-file reference may cause attacker-selected Java bytecode to run.
Affected context
The issue is in NLTK's Java-launching paths, including nltk.internals.java and StanfordSegmenter.java_class, in the affected release range described for NLTK 3.10.3 before the fix in 3.10.4. Launcher tokens in the options channel are validated, but the caller-controlled command sequence is appended without requiring its first token to be a main class. The risk depends on whether an attacker can influence that sequence or the related configuration.
Exploit preconditions
- Attack surface: NLTK code that launches Java through the affected launcher paths
- Required access: Ability to influence the caller-controlled command sequence or relevant Java class setting; the description does not establish a particular access level
- Trigger point: Java process launch
- Why exploitation is possible: The command sequence is appended without enforcing that its first token is a main class, allowing Java launcher options such as
-jaror an argument-file reference to alter what Java executes
Why this happens
This is an argument-injection flaw, primarily mapping to CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection'). The launcher validates one channel of Java options but does not sufficiently constrain a separate caller-controlled argument sequence. As a result, values intended as ordinary command arguments may be interpreted as Java launcher directives. The behavior is also related to CWE-77: Improper Neutralization of Special Elements used in a Command.
Potential impact
- Attacker-selected Java bytecode may execute in the context of the NLTK process
- The running process or its accessible data and resources could be compromised
- Further systems or services may be affected if the process has access to them
General mitigation guidance
Defensive patterns include treating launcher arguments and class settings as untrusted, enforcing an explicit allowlist of permitted entry points, and rejecting launcher-control options or argument-file references where they are not required. Prefer APIs that keep executable selection separate from validated arguments, validate inputs before process creation, and run Java processes with only the privileges and resource access they need.
How teams detect issues like this
- Use static analysis to flag process-launch code that combines caller-controlled values with Java launcher arguments.
- Review code paths that append command sequences after validating a separate options channel, especially where a main class is not enforced.
- Add policy checks for unexpected launcher-control options, argument-file references, and unapproved Java entry points.
- Use automated code review tools as an additional way to surface risky process-argument construction.

