CVE-2023-7018: Transformers: unsafe deserialization enables RCE on load
HIGH PoC AVAILABLEAny team using HuggingFace Transformers before 4.36 is exposed to arbitrary code execution whenever a model file is loaded — a routine operation in every ML workflow. The attack surface is broad: malicious models can be distributed via HuggingFace Hub, shared repositories, or internal model registries with no network-level indicator of compromise. Patch immediately to 4.36+ and enforce model provenance controls across all pipelines.
What is the risk?
High risk for organizations with active ML pipelines. Exploitation requires only that a practitioner or automated job loads a crafted model file — a trivially triggered action requiring no attacker privileges. Pickle-based deserialization exploits are well-documented and tooling exists; sophistication barrier is low. Blast radius extends to the full execution environment: workstation, training cluster, or inference server, including cloud credentials and proprietary model weights stored in memory.
What systems are affected?
| Package | Ecosystem | Vulnerable Range | Patched |
|---|---|---|---|
| Transformers | pip | — | No patch |
Do you use Transformers? You're affected.
How severe is it?
What is the attack surface?
What should I do?
6 steps-
Upgrade to transformers >= 4.36 immediately across all environments (dev, staging, production).
-
Audit all model loading code paths — identify where models are loaded from external, shared, or user-supplied sources.
-
Enforce model provenance: restrict loading to internally verified registries; block arbitrary from_pretrained() calls to public Hub in production.
-
Adopt safetensors format: use safe_serialization=True when saving models to avoid pickle entirely.
-
Deploy ModelScan or equivalent tooling to scan model files before loading in CI/CD and production.
-
Detection: monitor for unexpected subprocess spawns, outbound connections, or file writes originating from ML training/inference processes.
How is it classified?
Which compliance frameworks are affected?
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2023-7018?
Any team using HuggingFace Transformers before 4.36 is exposed to arbitrary code execution whenever a model file is loaded — a routine operation in every ML workflow. The attack surface is broad: malicious models can be distributed via HuggingFace Hub, shared repositories, or internal model registries with no network-level indicator of compromise. Patch immediately to 4.36+ and enforce model provenance controls across all pipelines.
Is CVE-2023-7018 actively exploited?
Proof-of-concept exploit code is publicly available for CVE-2023-7018, increasing the risk of exploitation.
How to fix CVE-2023-7018?
1. Upgrade to transformers >= 4.36 immediately across all environments (dev, staging, production). 2. Audit all model loading code paths — identify where models are loaded from external, shared, or user-supplied sources. 3. Enforce model provenance: restrict loading to internally verified registries; block arbitrary from_pretrained() calls to public Hub in production. 4. Adopt safetensors format: use safe_serialization=True when saving models to avoid pickle entirely. 5. Deploy ModelScan or equivalent tooling to scan model files before loading in CI/CD and production. 6. Detection: monitor for unexpected subprocess spawns, outbound connections, or file writes originating from ML training/inference processes.
What systems are affected by CVE-2023-7018?
This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, fine-tuning workflows, agent frameworks, MLOps/CI-CD pipelines.
What is the CVSS score for CVE-2023-7018?
CVE-2023-7018 has a CVSS v3.1 base score of 7.8 (HIGH). The EPSS exploitation probability is 0.73%.
What is the AI security impact?
Affected AI Architectures
MITRE ATLAS Techniques
AML.T0010.001 AI Software AML.T0011 User Execution AML.T0011.000 Unsafe AI Artifacts AML.T0018.002 Embed Malware AML.T0058 Publish Poisoned Models Compliance Controls Affected
What are the technical details?
Original Advisory
Deserialization of Untrusted Data in GitHub repository huggingface/transformers prior to 4.36.
Exploitation Scenario
An adversary crafts a malicious Transformers model file embedding a Python pickle payload with __reduce__ hooks that execute arbitrary shell commands on deserialization. The file is published to HuggingFace Hub under a typosquatted name resembling a popular model (e.g., 'bert-base-uncaseed'). A data scientist runs AutoModel.from_pretrained('attacker/bert-base-uncaseed') and RCE fires silently during deserialization — before any weights are processed and without raising obvious errors. The attacker gains shell access to the ML workstation or cloud training instance, pivoting to cloud IAM credentials, training data stores, and proprietary fine-tuned model weights.
Weaknesses (CWE)
CWE-502 — Deserialization of Untrusted Data: The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.
- [Architecture and Design, Implementation] If available, use the signing/sealing features of the programming language to assure that deserialized data has not been tainted. For example, a hash-based message authentication code (HMAC) could be used to ensure that data has not been modified.
- [Implementation] When deserializing data, populate a new object rather than just deserializing. The result is that the data flows through safe input validation and that the functions are safe.
Source: MITRE CWE corpus.
CVSS Vector
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H References
Timeline
Related Vulnerabilities
CVE-2026-26210 9.8 KTransformers: pickle RCE via unauthenticated ZMQ socket
Same package: transformers CVE-2024-3568 9.6 HuggingFace Transformers: RCE via pickle deserialization
Same package: transformers CVE-2026-5241 9.6 transformers: trust_remote_code bypass enables RCE via model load
Same package: transformers CVE-2024-11392 8.8 HuggingFace Transformers: RCE via config deserialization
Same package: transformers CVE-2023-6730 8.8 HuggingFace Transformers: RCE via unsafe deserialization
Same package: transformers