Summary
PyTorch Lightning up to version 2.6.0 contains an unsafe deserialization flaw in its checkpoint loading mechanism, where LightningModule.load_from_checkpoint() calls torch.load() without restricting deserialization to weights only.
If an attacker can supply a malicious checkpoint file, this behavior can deserialize arbitrary Python objects via Pickle and may result in arbitrary code execution when the checkpoint is loaded.
Affected context
This vulnerability arises in environments that use PyTorch Lightning's checkpoint loading APIs, especially LightningModule.load_from_checkpoint() for restoring training state or deploying models.
It is most relevant when:
- Checkpoints come from sources that are not strictly controlled or validated
- Teams share model files across machines, services, or collaborators
- Automated pipelines load checkpoints without human review
The risk increases in multi-tenant, research, or ML-ops setups where model artifacts may be exchanged or downloaded dynamically.
Exploit preconditions
- Attack surface: Any code path that calls
LightningModule.load_from_checkpoint()or indirectly invokestorch.load()on untrusted checkpoint files - Required access: Ability to cause the application to read a crafted checkpoint (e.g., upload, share, or place a file where the process will load it)
- Trigger point: Execution of model loading logic that deserializes the attacker-supplied checkpoint
- Why exploitation is possible: The underlying
torch.load()call uses Pickle-style deserialization withoutweights_only=Trueor equivalent constraints, allowing arbitrary object construction and associated code execution during loading
Why this happens
The core issue is an unsafe deserialization pattern: treating serialized model checkpoints as inherently trustworthy and deserializing them using a general-purpose, code-capable mechanism.
PyTorch Lightning's LightningModule.load_from_checkpoint() delegates to torch.load() without enforcing a safe mode such as weights_only=True.
This maps directly to CWE-502: Deserialization of Untrusted Data, where user-controllable serialized input is passed to a deserializer that can instantiate arbitrary Python objects, some of which can execute code when constructed or restored.
Potential impact
- Execution of arbitrary Python code with the privileges of the process loading the checkpoint
- Compromise of the ML training or inference environment (e.g., exfiltrating data, credentials, or model IP)
- Modification or backdooring of models for data poisoning or model behavior sabotage
- Use of compromised systems as a foothold for lateral movement within the network
General mitigation guidance
Effective mitigation focuses on limiting trust in serialized artifacts and constraining deserialization behavior:
- Prefer safer checkpoint handling modes (e.g., options that load only tensor weights and not arbitrary objects) where available
- Treat checkpoints and model artifacts as untrusted input; only load files from authenticated, integrity-verified, and access-controlled sources
- Introduce a validation or staging step for model artifacts (e.g., out-of-band scanning, signature verification, or checksum validation) before loading them into production workloads
- Run training and inference workloads with the principle of least privilege so that, even if deserialization is abused, system-level impact is reduced
- Separate model loading components from highly sensitive resources (e.g., isolate in containers or dedicated service accounts) to limit blast radius
How teams detect issues like this
Organizations can look for this issue through both preventive and detective controls:
- Static analysis / code scanning:
- Flag calls to
torch.load()orLightningModule.load_from_checkpoint()where the source of the checkpoint is not clearly trusted or validated - Identify deserialization of files or streams that originate from user input, network locations, or shared storage
- Code review signals:
- Model loading utilities that accept arbitrary file paths, URLs, or user-uploaded artifacts
- Pipelines that automatically fetch and load checkpoints from external registries, experiment tracking systems, or object storage without integrity checks
- Policy and tooling:
- Enforce internal guidelines that serialized artifacts must be signed or verified before loading
- Use automated review tools or CI checks to highlight unsafe deserialization patterns and require explicit justification or safer alternatives

