Skip to content

Insecure Deserialization in PyTorch

Description

Functions reliant on pickle can result in arbitrary code execution. Consider loading from `state_dict`, using fickling, or switching to a safer serialization method like ONNX

Examples

Insecure Code

python
torch.save(model)
torch.load('model.pkl')

Secure Code

python
torch.save(model.state_dict(), 'model.pth')
model.load_state_dict(torch.load('model.pth'))

Remediation

Use `state_dict` to load models or switch to a safer serialization method like ONNX

Rule Details

FieldValue
IDCODE-0800
CategoryDeserialization
SeverityCRITICAL
CWECWE-502
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagspickle, deserialization
OWASPN/A

References