CVE-2026-31218: optimate: unsafe torch.load() enables RCE via model file
AWAITING NVDThe optimate neural network optimization framework contains an insecure deserialization flaw where model state dictionaries are loaded using PyTorch's torch.load() without the weights_only=True safety parameter, enabling arbitrary Python code execution during model loading. This is a well-understood and extensively documented attack class in ML pipelines — crafting a malicious pickle-embedded .pt file requires no advanced skills, meaning the exploitation barrier is trivially low for any attacker who can supply a model file to your training infrastructure. No public exploit exists and the package is not in CISA KEV, but urgency extends beyond optimate itself: this CVE signals a pervasive pattern across ML codebases where insecure torch.load() usage is endemic. Audit all torch.load() calls in your codebase for missing weights_only=True, enforce cryptographic model provenance verification, and evaluate migrating to safetensors format which eliminates pickle-based deserialization entirely.
Risk Assessment
Effective severity is Critical despite no assigned CVSS score — insecure deserialization yielding arbitrary code execution is among the highest-impact vulnerability classes. Exploitation complexity is low once an attacker can deliver a crafted .pt file to the target environment, which is realistic in collaborative ML workflows, shared model repositories, or any pipeline consuming artifacts from external sources. The narrow attack surface (specific to optimate users loading external models via --model) limits immediate blast radius, but the underlying pattern mirrors dozens of similar CVEs across ML tooling and warrants broad codebase audits beyond this single package.
Attack Kill Chain
Severity & Risk
Recommended Action
6 steps-
Immediate patch: In neural_magic_training.py and all torch.load() call sites, add weights_only=True to restrict deserialization to safe tensor data only.
-
Broad codebase audit: Run 'grep -r "torch.load(" . | grep -v "weights_only=True"' across all ML projects to identify the same pattern elsewhere.
-
Model provenance: Implement SHA-256 hash verification for all model files before loading; maintain a manifest of expected hashes for approved artifacts.
-
Format migration: Evaluate migrating model storage to safetensors format, which does not use pickle and cannot execute arbitrary code during loading.
-
Environment hardening: Ensure ML training processes run with least-privilege credentials and cannot reach external networks post-exploitation.
-
Detection: Monitor for unexpected process spawning, outbound network connections, or file system writes during model loading operations.
Classification
Compliance Impact
This CVE is relevant to:
Frequently Asked Questions
What is CVE-2026-31218?
The optimate neural network optimization framework contains an insecure deserialization flaw where model state dictionaries are loaded using PyTorch's torch.load() without the weights_only=True safety parameter, enabling arbitrary Python code execution during model loading. This is a well-understood and extensively documented attack class in ML pipelines — crafting a malicious pickle-embedded .pt file requires no advanced skills, meaning the exploitation barrier is trivially low for any attacker who can supply a model file to your training infrastructure. No public exploit exists and the package is not in CISA KEV, but urgency extends beyond optimate itself: this CVE signals a pervasive pattern across ML codebases where insecure torch.load() usage is endemic. Audit all torch.load() calls in your codebase for missing weights_only=True, enforce cryptographic model provenance verification, and evaluate migrating to safetensors format which eliminates pickle-based deserialization entirely.
Is CVE-2026-31218 actively exploited?
No confirmed active exploitation of CVE-2026-31218 has been reported, but organizations should still patch proactively.
How to fix CVE-2026-31218?
1. Immediate patch: In neural_magic_training.py and all torch.load() call sites, add weights_only=True to restrict deserialization to safe tensor data only. 2. Broad codebase audit: Run 'grep -r "torch.load(" . | grep -v "weights_only=True"' across all ML projects to identify the same pattern elsewhere. 3. Model provenance: Implement SHA-256 hash verification for all model files before loading; maintain a manifest of expected hashes for approved artifacts. 4. Format migration: Evaluate migrating model storage to safetensors format, which does not use pickle and cannot execute arbitrary code during loading. 5. Environment hardening: Ensure ML training processes run with least-privilege credentials and cannot reach external networks post-exploitation. 6. Detection: Monitor for unexpected process spawning, outbound network connections, or file system writes during model loading operations.
What systems are affected by CVE-2026-31218?
This vulnerability affects the following AI/ML architecture patterns: Training pipelines, Model optimization workflows, Model fine-tuning environments, CI/CD ML artifact pipelines, Collaborative model development environments.
What is the CVSS score for CVE-2026-31218?
No CVSS score has been assigned yet.
Technical Details
NVD Description
The _load_model() function in the neural_magic_training.py script of the optimate project in commit a6d302f912b481c94370811af6b11402f51d377f (2024-07-21) is vulnerable to insecure deserialization (CWE-502). When loading a model state dictionary from a state_dict.pt file via torch.load(), the function does not enable the weights_only=True security parameter. This allows the deserialization of arbitrary Python objects through the Pickle module. A remote attacker can exploit this by providing a maliciously crafted state_dict.pt file within a directory specified via the --model argument, leading to arbitrary code execution during the deserialization process on the victim's system.
Exploitation Scenario
An adversary targeting an organization's ML optimization infrastructure crafts a malicious state_dict.pt file by serializing a Python object whose __reduce__ method executes a reverse shell or credential harvesting command. The attacker uploads this file to a Hugging Face repository, S3 bucket, or shared NFS mount that the victim's training pipeline consumes. When a data scientist or automated CI/CD job runs neural_magic_training.py with --model pointing to the directory containing the malicious file, torch.load() — absent the weights_only safeguard — passes the pickle stream to Python's Pickle module, which instantiates the adversary's object and executes the embedded payload. The training process, often running with cloud IAM permissions scoped to access model stores and training data, then becomes a pivot point for credential theft, lateral movement to other services, or persistent backdoor installation in the ML environment.
Timeline
Related Vulnerabilities
CVE-2025-59528 10.0 Flowise: Unauthenticated RCE via MCP config injection
Same attack type: Supply Chain CVE-2024-2912 10.0 BentoML: RCE via insecure deserialization (CVSS 10)
Same attack type: Supply Chain CVE-2023-3765 10.0 MLflow: path traversal allows arbitrary file read
Same attack type: Supply Chain CVE-2025-5120 10.0 smolagents: sandbox escape enables unauthenticated RCE
Same attack type: Supply Chain CVE-2026-21858 10.0 n8n: Input Validation flaw enables exploitation
Same attack type: Code Execution
AI Threat Alert