Summary
picklescan before version 0.0.28 fails to recognize malicious pickle payloads that leverage torch.utils.data.datapipes.utils.decoder.basichandlers in reduce methods, allowing them to pass safety checks.
Remote attackers can embed undetected executable code into specially crafted pickle files, which may run during deserialization and lead to remote code execution in environments that trust picklescan's validation.
Affected context
This vulnerability impacts environments that rely on picklescan for security screening of Python pickle files, especially in ML and data processing pipelines that use PyTorch data utilities.
It becomes relevant when untrusted or semi-trusted pickle data is accepted from external sources and validated using picklescan, under the assumption that unsafe payloads will be reliably detected and blocked.
Exploit preconditions
- Attack surface: Any application or service that accepts pickle files and uses picklescan (pre-0.0.28) to vet them before deserialization.
- Required access: Ability to supply or influence serialized pickle content, such as uploading datasets, model artifacts, or configuration pickles.
- Trigger point: The vulnerable condition occurs when a crafted pickle using
torch.utils.data.datapipes.utils.decoder.basichandlersin its reduce methods is scanned by picklescan and then deserialized. - Why exploitation is possible: picklescan's detection logic does not recognize this handler-based pattern as malicious, allowing the payload to bypass checks and execute code during the normal unpickling process.
Why this happens
The underlying issue is incomplete coverage in the unsafe deserialization detection logic for Python pickles.
picklescan focuses on known dangerous patterns but fails to account for object construction paths that invoke torch.utils.data.datapipes.utils.decoder.basichandlers functions via reduce methods, which can be abused to run attacker-controlled code.
This maps to CWE-502: Unsafe Deserialization, where security tooling and application logic treat serialized data as safe and fail to constrain what objects and behaviors can be instantiated during deserialization.
Potential impact
- Remote attackers may execute arbitrary Python code on systems that deserialize attacker-controlled pickle files.
- Malicious pickles could modify or exfiltrate sensitive data processed by ML workflows and data pipelines.
- Attackers can potentially deploy backdoors or alter model artifacts and datasets, leading to data poisoning or model integrity compromises.
- Compromise of the hosting application or service, with possible lateral movement depending on runtime permissions and network access.
General mitigation guidance
Mitigation patterns should focus on reducing trust in serialized data and constraining deserialization behavior.
Common secure design approaches include:
- Avoiding pickle for untrusted or user-supplied data, favoring safer, declarative formats such as JSON or protocol buffers.
- Enforcing strict allowlists for deserializable types and modules, so that only benign, expected objects can be instantiated.
- Treating security scanning tools like picklescan as one defensive layer, not a sole gatekeeper, and combining them with runtime isolation and least privilege.
- Running deserialization code in tightly sandboxed environments with minimal filesystem, network, and process capabilities.
- Applying explicit validation on data structures after deserialization and rejecting unexpected or opaque objects that expose dynamic behavior.
How teams detect issues like this
Detection efforts can target both application code and serialized data flows:
- Use static analysis or code search to flag any use of Python's
pickle,torch.load, or similar deserialization APIs on untrusted inputs, especially when guarded only by picklescan. - During code reviews, treat reliance on security scanners for pickle safety as a smell; look for explicit type restrictions, sandboxing, and safer data formats.
- Apply policy-based checks in CI/CD that disallow or require justification for new pickle-based inputs, particularly in remote or multi-tenant services.
- Incorporate automated scanning tools that analyze serialized artifacts for suspicious constructors and reduce methods, augmenting picklescan with additional rule sets where appropriate.

