Summary
NLTK: Allowlisted pickle loaders still permit code execution in current source
The current source tree still allows arbitrary code execution during supposedly safer allowlisted pickle loading. The allowlist trusts whole module namespaces instead of exact safe globals, so crafted pickles can invoke dangerous in-namespace callables through pickle REDUCE.
Details
- Vulnerability type: Remote code execution via unsafe deserialization
- Affected component:
nltk.picklesec.allowlisted_pickle_load,nltk.tokenize.punkt.punkt_pickle_load,nltk.parse.transitionparser.TransitionParser.parse - Affected versions: Current source
v3.10.0-rc2; published3.9.4was not the claim target for this bypass. - Patched versions: Not yet patched
- Root cause: Module-prefix allowlists include dangerous callables such as
nltk.tokenize.repp.ReppTokenizer._executeandnumpy.f2py.crackfortran.myeval.
punkt_pickle_load() allowlists both nltk.tokenize.punkt and the whole nltk.tokenize namespace, which exposes ReppTokenizer._execute() and its subprocess.Popen(...) sink during unpickling. TransitionParser.parse() uses allowlisted_pickle_load(..., allowed_modules=("numpy", "scipy", "sklearn")), which permits numpy.f2py.crackfortran.myeval() and its attacker-controlled eval(...) path. I confirmed both gadgets create marker files before the caller returns or later aborts on type misuse.
PoC
Preconditions
- The application loads an attacker-controlled tokenizer or model artifact through these public loaders.
Steps
- Create a pickle whose REDUCE callable is
ReppTokenizer._executeand point its command to a harmless marker-file write. - Pass that payload to
punkt_pickle_load(BytesIO(payload))and observe the marker file is created during unpickling. - Create a second pickle whose REDUCE callable is
numpy.f2py.crackfortran.myevaland load it throughTransitionParser.parse(). - Observe the second marker file is created before
TransitionParser.parse()later fails on the returned object type.
Minimal reproducible excerpt
{'punkt_marker': 'PUNKT_RCE', 'transitionparser_marker': 'TP_RCE'}
Resources
- https://github.com/nltk/nltk/blob/v3.10.0-rc2/nltk/tokenize/punkt.py#L120-L134
- https://github.com/nltk/nltk/blob/v3.10.0-rc2/nltk/tokenize/repp.py#L111-L115
- https://github.com/nltk/nltk/blob/v3.10.0-rc2/nltk/parse/transitionparser.py#L26-L30
- https://github.com/nltk/nltk/blob/v3.10.0-rc2/nltk/parse/transitionparser.py#L565-L571
Fix + attack demonstration (verified)
- tightened callers
find_classnow, before the allowlists:
- Rejects any dotted
name→ closes 4489 with zero legit impact. - Denies dangerous modules (
os,subprocess,sys,builtins,numpy.f2py,nltk.tokenize.repp, …) even under a broadallowed_modules, a defense-in-depth backstop so a future too-broad allowlist can't silently reopen RCE. builtinsdenied wholesale; safe primitives (int,str, …) must be named exactly viaallowed_globals.
Callers tightened: punkt drops the broad nltk.tokenize (keeps nltk.tokenize.punkt + exact collections.defaultdict/builtins.int); transitionparser keeps numpy/scipy/sklearn (array unpickling needs their submodules) with the new guards blocking the gadgets.
Full pickle-sink audit
Every deserialization sink in the tree was reviewed: no raw pickle.load anywhere, and no joblib/numpy/torch/dill/yaml/marshal loaders. data.load + wordnet_app use RestrictedUnpickler (blocks all globals, safe); the remaining pickle_load sites (chartparser_app, tbl/demo) load user-selected or self-written files and keep their warning.
Attack demonstration (captured; fork clone)
=== EXPLOITS blocked ===
4489 sklearn.os.system (dotted) -> BLOCKED
x99w numpy.f2py.crackfortran.myeval -> BLOCKED
x99w nltk.tokenize.repp._execute -> BLOCKED
backstop os.system (os allowlisted) -> BLOCKED
backstop builtins.eval (exact global)-> BLOCKED
=== LEGIT loads still work ===
punkt round-trip via punkt_pickle_load -> OK
builtins.int (safe primitive) -> OK
Tests
test_pickle_allowlist_security.py, added 5 regressions (dotted traversal, both namespace gadgets, denied-module backstop, legit round-trip). Suite: 122 passed / 9 skipped (sklearn-dependent) across pickle/punkt/transition/tokenize. pre-commit (black/isort/ruff) clean.
Impact
Any caller that trusts these current allowlisted loaders can still execute attacker-controlled commands while loading model or tokenizer artifacts. This defeats the protection mechanism that replaced unrestricted pickle loading and creates a dangerous false sense of safety.
Untrusted serialized data is processed by a deserializer that can instantiate arbitrary objects or execute code as a side effect. Typical impact: arbitrary code execution or logic abuse.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Replace broad module-prefix allowlists with exact (module, qualname) pairs for the few safe classes or functions genuinely required. Do not allow entire namespaces such as nltk.tokenize or numpy, and keep post-load type validation only as a secondary defense.
Frequently Asked Questions
- What is CVE-2026-79657? CVE-2026-79657 is a critical-severity insecure deserialization vulnerability in nltk (pip), affecting versions <= 3.10.2. It is fixed in 3.10.3. Untrusted serialized data is processed by a deserializer that can instantiate arbitrary objects or execute code as a side effect.
- Which versions of nltk are affected by CVE-2026-79657? nltk (pip) versions <= 3.10.2 is affected.
- Is there a fix for CVE-2026-79657? Yes. CVE-2026-79657 is fixed in 3.10.3. Upgrade to this version or later.
- Is CVE-2026-79657 exploitable, and should I be worried? Whether CVE-2026-79657 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-79657 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-79657? Upgrade
nltkto 3.10.3 or later.