Skip to content

Avoid importing torch.package

Description

Importing torch.package can result in arbitrary code execution via pickle deserialization of untrusted data. This is a potential security risk as it allows an attacker to execute arbitrary code.

Examples

Insecure Code

python
import torch.package

Secure Code

python
Use alternative methods for packaging and distributing PyTorch models, such as torch.save() and torch.load()

Remediation

Avoid using torch.package and instead use alternative methods for packaging and distributing PyTorch models.

Rule Details

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

References