Summary
The vulnerability in picklescan allows malicious pickle files invoking torch.utils._config_module.load_config inside custom reduce methods to bypass detection.
When such pickles are loaded, embedded arbitrary code may execute, enabling remote code execution in contexts like model loading or supply chain workflows.
Affected context
This issue arises in environments that rely on picklescan (before 0.0.28) to vet Python pickle files for malicious behavior.
It primarily affects workflows that:
- Load untrusted or semi-trusted pickle artifacts (e.g., ML models, serialized objects)
- Depend on picklescan to detect dangerous reduce-based execution paths
- Use PyTorch or related tooling where
torch.utils._config_module.load_configis available
In such contexts, attackers can deliver crafted pickle files that appear safe to picklescan but still execute arbitrary code at load time.
Exploit preconditions
- Attack surface: Consumption of pickle files from external or less-trusted sources (e.g., model hubs, third-party datasets, CI artifacts).
- Required access: Ability to supply or influence pickle files that are scanned with picklescan and later loaded with
pickle.load(or equivalent). - Trigger point: Deserialization of the crafted pickle by the application, often during model loading or configuration restoration.
- Why exploitation is possible: picklescan's detection logic does not recognize invocation of
torch.utils._config_module.load_configwithin reduce methods as a dangerous execution sink, allowing attacker-controlled code to run during deserialization.
Why this happens
The underlying bug class is unsafe deserialization combined with incomplete detection coverage of dangerous execution primitives.
picklescan relies on pattern-based analysis of pickle opcodes and reduce methods to identify code execution paths, but it fails to treat torch.utils._config_module.load_config as a high-risk sink.
This maps to CWE-502: Deserialization of Untrusted Data, where a defensive control (the scanner) does not fully account for all ways untrusted data can trigger code execution, allowing crafted objects to bypass checks and run arbitrary logic during pickle.load.
Potential impact
- Remote code execution when vulnerable systems deserialize attacker-controlled pickle files
- Compromise of ML training or inference environments via malicious models or artifacts
- Supply chain attacks through poisoned artifacts in registries, model hubs, or CI/CD pipelines
- Data exfiltration, credential theft, or lateral movement from compromised runtime environments
General mitigation guidance
Mitigation typically centers on minimizing trust in pickle content and hardening deserialization workflows rather than relying on a single scanning tool.
Common defensive patterns include:
- Avoiding deserialization of untrusted pickle data entirely, preferring safer, structured formats (e.g., JSON, protobuf) where feasible
- Treating pickle deserialization as a privileged operation, running it in isolated or sandboxed environments with reduced permissions
- Layering defenses by combining scanners with strict allowlists of permissible modules, functions, and classes during deserialization
- Explicitly limiting or disabling access to configuration-loading or execution-oriented functions when processing external artifacts
- Applying least-privilege to services responsible for loading ML models or serialized objects so that a compromise yields minimal system control
How teams detect issues like this
Effective detection of similar issues generally involves:
- Static analysis rules that flag use of pickle (and equivalent serializers) on data sourced from external or less-trusted inputs
- Code review checklists that require justification for any use of pickle, especially in supply chain or artifact ingestion paths
- Policies that identify and monitor dangerous sinks (such as configuration loaders, dynamic import mechanisms, or code evaluation functions) reachable during deserialization
- Automated security testing that feeds crafted pickle samples into pipelines to verify that scanners and controls detect or block execution
- Inventory and monitoring of deserialization endpoints, including logging of artifact origins and integrity checks, to identify anomalous or unapproved pickle consumption

