PyPI: transformers

CVE-2026-1839

Safety vulnerability ID: SFTY-20260407-58349

Safety legacy ID: pyup.io-93822

Affected versions of the transformers package are vulnerable to Deserialization of Untrusted Data due to an unsafe torch.load() invocation within the Trainer class that omits the weights_only=True parameter. The _load_rng_state() method in src/transformers/trainer.py at line 3059 calls torch.load() without weights_only=True, and the safe_globals() context manager offers no protection when running on PyTorch versions below 2.6, so a malicious checkpoint file, such as rng_state.pth, is deserialized without restriction. An attacker who supplies a crafted checkpoint file can achieve arbitrary code execution when the Trainer loads it.

Created at: Apr 28, 2026Updated at: Apr 28, 2026

Overview

HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class

Advisory

Affected versions of the transformers package are vulnerable to Deserialization of Untrusted Data due to an unsafe torch.load() invocation within the Trainer class that omits the weights_only=True parameter. The _load_rng_state() method in src/transformers/trainer.py at line 3059 calls torch.load() without weights_only=True, and the safe_globals() context manager offers no protection when running on PyTorch versions below 2.6, so a malicious checkpoint file, such as rng_state.pth, is deserialized without restriction. An attacker who supplies a crafted checkpoint file can achieve arbitrary code execution when the Trainer loads it.

Affected Package

Affecting transformers package, versions
<5.0.0rc3

Also affects

---

How to Fix

Upgrade
transformers
to
5.0.0rc3
or higher.

Mitigation and Workarounds

---

Vulnerable Functions

Functions linked to known vulnerabilities.

Vulnerable function data is available for Enterprise customers

Book a call with us to see Safety in action.

Safety

Verified by Safety

Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.

Learn more