HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class
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.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Python (PyPI) | transformers | < 5.0.0rc3 | 5.0.0rc3 |
References
- https://github.com/huggingface/transformers/commit/03c8082ba4594c9b8d6fe190ca9bed0e5f8ca396
- https://huntr.com/bounties/3c77bb97-e493-493d-9a88-c57f5c536485
- https://github.com/advisories/GHSA-69w3-r845-3855
- https://nvd.nist.gov/vuln/detail/CVE-2026-1839
- https://github.com/huggingface/transformers
- https://github.com/huggingface/transformers/releases/tag/v5.0.0rc3
- CVSS vector
CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:H- Weakness (CWE)
CWE-502- Platform
- Python (PyPI)
- Package
transformers- Disclosed
- 07.04.2026
- Updated
- 11.10.2026 15:17
Sources and licenses
OSV / GitHub Advisory Database - PYSEC-2026-2288 - PyPA Advisory Database; CC BY 4.0
OSV / GitHub Advisory Database - GHSA-69w3-r845-3855 - CC BY 4.0
Vulnerability history: transformers
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
- 32
- First → latest
- 05.2023 09.2026
- Without a fix
- 9
- Exploited in attacks
- 0
Severity breakdown
- High 18
- Medium 12
- Low 2
Disclosures per year
- 2023: 3
- 2024: 4
- 2025: 20
- 2026: 5
-
HuggingFace Transformers allows for arbitrary code execution in the `Trainer` class this entry
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.