Summary
Malicious pickle files can bypass detection in vulnerable versions of picklescan, allowing embedded code to execute when pickle.load is called.
When untrusted or third-party model artifacts are scanned with an affected picklescan version, attackers may achieve remote code execution and perform supply chain attacks.
Affected context
This vulnerability appears in environments that rely on picklescan (before 0.0.30) to detect malicious Python pickle payloads, particularly around machine learning model loading.
It is most relevant where:
- PyTorch or other frameworks load pickled models or artifacts
- Artifacts are obtained from external or semi-trusted sources
- Security checks depend on picklescan's analysis to flag dangerous reduce methods
In these contexts, malicious code hidden inside pickle files may pass validation and execute at load time.
Exploit preconditions
- Attack surface: Deserialization of attacker-controlled pickle files (e.g., ML models, datasets, cached objects).
- Required access: Ability to supply or modify pickle files that a target application will scan with picklescan and then load using pickle.load.
- Trigger point: Invocation of pickle.load or equivalent deserialization routines on a crafted pickle that uses idlelib.run.Executive.runcode in its reduce method.
- Why exploitation is possible: The vulnerable picklescan versions do not recognize this reduce-based execution path as malicious, allowing dangerous code to remain undetected and execute during normal deserialization.
Why this happens
The core issue is an incomplete detection strategy for unsafe deserialization patterns in Python pickle files.
picklescan before 0.0.30 fails to account for the use of idlelib.run.Executive.runcode inside reduce methods, a pattern that can execute arbitrary Python code at unpickle time.
This maps to CWE-502: Unsafe Deserialization, where serialized data is treated as benign input, while embedded logic can run during object reconstruction without being flagged or constrained by security checks.
Potential impact
- Attackers may execute arbitrary Python code on systems loading crafted pickle files.
- PyTorch models and other ML artifacts can be weaponized to perform supply chain attacks.
- Compromise of the application process running the deserialization, leading to data theft or tampering.
- Installation of backdoors or persistence mechanisms through malicious model loading pipelines.
General mitigation guidance
Defenses should focus on reducing trust in serialized artifacts and constraining deserialization behavior rather than relying solely on detection tools.
Common mitigation patterns include:
- Avoiding generic pickle-based deserialization for data or models from untrusted or third-party sources.
- Using serialization formats that lack executable behavior (e.g., JSON, protocol buffers, or framework-specific safe formats) for interchange.
- Enforcing strict separation between code and model data, ensuring that model loading does not implicitly execute arbitrary logic.
- Applying least-privilege principles to processes that must deserialize pickle files, limiting OS-level capabilities in case execution occurs.
- Incorporating layered validation and sandboxing around ML artifact loading pipelines to reduce the blast radius of a compromised artifact.
How teams detect issues like this
Detection typically involves analyzing deserialization flows and serialized artifacts for execution-capable constructs.
Effective strategies can include:
- Static analysis rules that identify unsafe use of pickle.load, especially on data sourced from external or semi-trusted locations.
- Code review practices that flag reliance on pickle for cross-boundary data exchange or model distribution.
- Artifact scanning policies that look for suspicious reduce methods or references to execution helpers such as idlelib.run.Executive.runcode.
- CI/CD checks that prevent introducing new pickle-based interfaces for remote or user-supplied data without explicit security review.
- Use of automated review tools configured to highlight CWE-502 patterns and deserialization hotspots in ML pipelines.

