Arbitrary Code Execution via Unsafe torch.load() in Trainer Checkpoint Loading in huggingface/transformers
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.
- Products
- Not specified
- Affected versions
- Not specified
- Fixed versions
- Not specified
- CVEs
- CVE-2026-1839
- Confirmed fixed CVEs
- Not specified
- Updated in this feed
- 5 Nov 2026, 04:25 UTC · Revision 1
Source evidence
Arbitrary Code Execution via Unsafe torch.load() in Trainer Checkpoint Loading in huggingface/transformers
core-osv · Original sourcePublished 7 Apr 2026, 05:22 UTC
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.
osv:CVE-2026-1839
Complete source record
{
"id": "f98c3fe258f9397198cd04f82edee7e379977f00ff51f6491bedb8931eb75623",
"url": "https://osv.dev/vulnerability/CVE-2026-1839",
"method": "structured",
"payload": {
"kind": "advisory",
"title": "Arbitrary Code Execution via Unsafe torch.load() in Trainer Checkpoint Loading in huggingface/transformers",
"summary": "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.",
"evidence": "osv:CVE-2026-1839",
"products": [],
"severity": "medium",
"structured": {
"id": "CVE-2026-1839",
"aliases": [
"CVE-2026-1839",
"GHSA-69w3-r845-3855",
"PYSEC-2026-2288"
],
"metrics": [
{
"type": "CVSS_V3",
"score": "CVSS:3.0/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:H"
}
],
"affected": [
{
"ranges": [
{
"repo": "https://github.com/huggingface/transformers",
"type": "GIT",
"events": [
{
"introduced": "0"
},
{
"fixed": "08810b1e278938278c50153ee1edfd7a20a759da"
},
{
"introduced": "cbc6716945cff1d8e124d344ba0150e6e27f8b6e"
},
{
"fixed": "03c8082ba4594c9b8d6fe190ca9bed0e5f8ca396"
}
],
"database_specific": {
"extracted_events": [
{
"cpe": "cpe:2.3:a:huggingface:transformers:*:*:*:*:*:*:*:*",
"range": [
{
"introduced": "0"
},
{
"fixed": "5.0.0"
}
],
"source": "CPE_RANGE"
},
{
"cpe": "cpe:2.3:a:huggingface:transformers:5.0.0:rc0:*:*:*:*:*:*",
"range": [
{
"introduced": "5.0.0-rc0"
},
{
"last_affected": "5.0.0-rc0"
}
],
"source": "CPE_STRING"
},
{
"cpe": "cpe:2.3:a:huggingface:transformers:5.0.0:rc1:*:*:*:*:*:*",
"range": [
{
"introduced": "5.0.0-rc1"
},
{
"last_affected": "5.0.0-rc1"
}
],
"source": "CPE_STRING"
},
{
"cpe": "cpe:2.3:a:huggingface:transformers:5.0.0:rc2:*:*:*:*:*:*",
"range": [
{
"introduced": "5.0.0-rc2"
},
{
"last_affected": "5.0.0-rc2"
}
],
"source": "CPE_STRING"
},
{
"range": [
{
"fixed": "03c8082ba4594c9b8d6fe190ca9bed0e5f8ca396"
}
],
"source": "REFERENCES_COMMIT"
}
]
}
}
],
"versions": [
"5.0.0-rc0",
"5.0.0-rc1",
"5.0.0-rc2",
"v4.56.1-Vault-Gemma-preview",
"4.55.0-GLM-4.5V-preview-GLM-4.5V-preview",
"4.55.0-GLM-4.5V-preview",
"v4.53.2-Ernie-4.5-preview",
"v4.53.2-modernbert-decoder-preview",
"v4.52.4-Kyutai-STT-preview",
"v4.52.4-VJEPA-2-preview",
"v4.52.4-ColQwen2-preview",
"v4.51.3-CSM-preview",
"v4.51.3-GraniteMoeHybrid-preview",
"v4.51.3-LlamaGuard-preview",
"v4.51.3-D-FINE-preview",
"v4.51.3-SAM-HQ-preview",
"v4.51.3-BitNet-preview",
"v4.51.3-InternVL-preview",
"v4.51.3-Janus-preview",
"v4.51.3-TimesFM-preview",
"v4.51.3-MLCD-preview",
"v4.51.3-Qwen2.5-Omni-preview",
"v4.50.3-DeepSeek-3",
"v4.49.0-Mistral-3",
"v4.49.0-AyaVision",
"v4.49.0-SigLIP-2",
"v4.49.0-SmolVLM-2",
"v4.33.1",
"v4.16.0",
"v4.15.0",
"v4.14.0",
"v4.13.0",
"v4.12.0",
"v4.11.0",
"v4.10.0",
"v4.9.0",
"v4.8.0",
"v4.7.0",
"v4.6.0",
"v4.5.0",
"v4.4.0",
"v4.3.0.rc1",
"4.3.0.rc1",
"v4.2.0",
"v4.1.1",
"v4.1.0",
"v3.5.0",
"v3.4.0",
"v3.3.1",
"v3.3.0",
"v3.2.0",
"v3.1.0",
"v3.0.2",
"v3.0.1",
"3.0.1",
"v3.0.0",
"v2.11.0",
"v2.10.0",
"v2.9.1",
"v2.9.0",
"v2.8.0",
"v2.7.0",
"v2.6.0",
"v2.5.1",
"v2.5.0",
"v2.4.1",
"v2.4.0",
"v2.3.0",
"v2.2.2",
"v2.2.1",
"v2.2.0",
"v2.1.1",
"v2.1.0",
"v2.0.0",
"1.2.0",
"1.1.0",
"1.0",
"v0.6.2",
"v0.6.1",
"v0.6.0",
"v0.5.1",
"v0.5.0",
"0.5.0",
"v0.4.0",
"v0.3.0",
"v0.2.0",
"v0.1.2",
"0.1.2"
],
"database_specific": {
"source": "https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-1839.json"
}
}
],
"modified": "2026-10-28T02:30:42.509447413Z",
"provider": "osv",
"references": [
"https://huntr.com/bounties/3c77bb97-e493-493d-9a88-c57f5c536485",
"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/1xxx/CVE-2026-1839.json",
"https://nvd.nist.gov/vuln/detail/CVE-2026-1839",
"https://github.com/huggingface/transformers/commit/03c8082ba4594c9b8d6fe190ca9bed0e5f8ca396"
],
"provider_metadata": {
"cwe_ids": [
"CWE-502"
],
"cna_assigner": "@huntr_ai",
"osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/1xxx/CVE-2026-1839.json"
}
},
"related_cves": [
{
"value": "CVE-2026-1839",
"evidence": "/id"
}
],
"security_relevant": true,
"severity_evidence": "/severity/0/score"
},
"source_id": "core-osv",
"document_id": 510293,
"published_at": "2026-04-07T05:22:00.959+00:00"
}