CVE-2026-1839 Arbitrary Code Execution via Unsafe torch.load() in Trainer Checkpoint Loading in huggingface/transformers

Medium 6.5 Published Updated

Attackers can execute arbitrary code by supplying malicious checkpoint files to the Trainer class due to unsafe deserialization in torch.load.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Local or same network only
Victim action needed
A user has to click or open something
Fix
Available

What is CVE-2026-1839?

CVE-2026-1839 is a medium-severity unsafe deserialization vulnerability in huggingface/transformers, published on 7 Apr 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

Official description

A vulnerability in the HuggingFace Transformers library, specifically in the `Trainer` class, allows for arbitrary code execution. The `_load_rng_state()` method in `src/transformers/trainer.py` at line 3059 calls `torch.load()` without the `weights_only=True` parameter. This issue affects all versions of the library supporting `torch>=2.2` when used with PyTorch versions below 2.6, as the `safe_globals()` context manager provides no protection in these versions. An attacker can exploit this vulnerability by supplying a malicious checkpoint file, such as `rng_state.pth`, which can execute arbitrary code when loaded. The issue is resolved in version v5.0.0rc3.

Weakness: CWE-502

Which versions are affected by CVE-2026-1839?

3 open source packages ship an affected version, including transformers. It affects 1 product.

PackageAffectedFixed in
transformers PyPIAll versions5.0.0
transformers PyPIAll versions5.0.0rc3
transformers PyPIAll versions5.0.0rc3

Products include Huggingface Transformers.

How do I fix CVE-2026-1839?

Upgrade transformers to a fixed version for your release line: 5.0.0 or 5.0.0rc3.

Upgrade, and only deserialise data from trusted sources or with an allow-list of types. More about Unsafe deserialization.

Is CVE-2026-1839 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-1839 exists.

Sources

Also known as CLSA-2026-1779065183, ECHO-9bd3-047a-4b4a, GHSA-69w3-r845-3855, PYSEC-2026-2288.

Is CVE-2026-1839 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free