GitHub advisory · PyPI
NLTK: JVM argument injection bypass via per-call options in the NLTK Stanford wrappers (incomplete fix of CVE-2026-12841)
Description
The fix for CVE-2026-12841 (CWE-88, JVM argument injection) added _validate_java_options() to block dangerous JVM flags such as -agentlib, -agentpath, -javaagent, -Xrunjdwp, and @argfile references. However, the validation is only applied when setting global options via config_java(). The java() function's per-call options parameter -- added by PR #3683 (CVE-2026-12615 fix) -- passes options directly to subprocess.Popen without calling _validate_java_options().
All four Stanford Java wrapper classes accept user-supplied java_options and route them through the unvalidated per-call path, bypassing the CVE-2026-12841 fix entirely.
In nltk/internals.py, the java() function (line 128) accepts an options keyword argument. When options is not None, it is converted to a list and prepended to the JVM command (lines 211-217) without any validation:
# nltk/internals.py, lines 211-217 (HEAD)
if options is None:
java_options = _java_options # validated by config_java()
else:
if isinstance(options, str):
options = options.split()
java_options = list(options) # NO validation
cmd = [_java_bin] + java_options + cmd
Compare with config_java() (line 92) which does validate:
# nltk/internals.py, lines 122-123
_validate_java_options(options)
_java_options[:] = options
The four affected wrapper classes store user-supplied java_options without validation and pass them through the unvalidated per-call path:
GenericStanfordParser (nltk/parse/stanford.py): constructor parameter at line 39, stored at line 78, passed at lines 247 and 256StanfordTagger (nltk/tag/stanford.py): constructor parameter at line 51, stored at line 79, passed at line 118StanfordTokenizer (nltk/tokenize/stanford.py): constructor parameter at line 43, stored at line 66, passed at line 109StanfordSegmenter (nltk/tokenize/stanford_segmenter.py): constructor…Manual fix · PyPI
pip install --upgrade "nltk>=3.10.3"Sources