Summary
An unsafe deserialization weakness in picklescan through 0.0.26 allows malicious pickle payloads to bypass scanning and execute attacker-controlled code via idlelib.pyshell.ModifiedInterpreter.runcode.
When untrusted or third-party pickle files are loaded with pickle.load(), this blind spot can enable supply-chain attacks on PyTorch models and other serialized Python objects.
Affected context
This vulnerability appears in environments that rely on picklescan (≤ 0.0.26) to vet pickle files before using pickle.load() or equivalent APIs.
It is most relevant in workflows that import externally provided PyTorch model checkpoints, machine learning artifacts, or serialized Python objects from partners, public repositories, or CI/CD pipelines.
Risk increases when teams implicitly trust picklescan's results as a security gate and continue to deserialize pickle files originating outside their direct control.
Exploit preconditions
- Attack surface: Any Python process that deserializes pickle data using pickle.load() or similar functions.
- Required access: Ability to supply or modify pickle files consumed by the application (e.g., model files, cached objects, artifacts in pipelines).
- Trigger point: Loading a crafted pickle file with a vulnerable environment that either uses picklescan as its primary guardrail or skips additional validation.
- Why exploitation is possible: picklescan ≤ 0.0.26 does not recognize payloads that leverage idlelib.pyshell.ModifiedInterpreter.runcode in __reduce__, allowing arbitrary code execution during deserialization despite a "clean" scan result.
Why this happens
The underlying issue is incomplete coverage of dangerous deserialization patterns in the picklescan library.
Pickle deserialization executes object reconstruction logic, including __reduce__ methods, which can embed callable references that run arbitrary code when an object is unpickled.
In this case, payloads using idlelib.pyshell.ModifiedInterpreter.runcode were not modeled or flagged, mapping directly to CWE-502 (Unsafe Deserialization): untrusted serialized data is interpreted as executable behavior without a comprehensive threat model or strict allowlist of safe constructs.
Potential impact
- Attackers may execute arbitrary commands within the Python process loading the pickle file.
- Supply-chain compromise of PyTorch models and ML artifacts can alter training or inference behavior.
- Malicious code can exfiltrate data, credentials, or API keys accessible to the process.
- CI/CD pipelines or batch processing jobs that deserialize artifacts can be subverted.
- Local developer environments and shared research platforms may be silently backdoored.
General mitigation guidance
Mitigation centers on reducing trust in pickle inputs and hardening deserialization workflows rather than relying on a single scanning tool.
Common defensive patterns include:
- Treat pickle data as untrusted by default and avoid deserializing inputs from unknown or unverified sources.
- Favor safer, non-executable serialization formats (e.g., JSON, protocol buffers) for data interchange whenever possible.
- When pickle is unavoidable, constrain the deserialization environment by limiting available modules, using strict allowlists of expected classes, or sandboxing execution.
- Integrate multiple layers of scrutiny (content validation, integrity checks, provenance verification) before deserialization, especially for supply-chain artifacts.
- Run deserialization in low-privilege contexts, separating it from sensitive services or credentials to minimize blast radius.
How teams detect issues like this
Effective detection focuses on both code-level patterns and operational signals:
- Use static analysis and code review to identify any use of pickle.load(), pickle.loads(), or similar APIs handling data from external or loosely controlled sources.
- Flag security assumptions that depend solely on one scanner or heuristic and require explicit discussion of deserialization risks.
- Analyze serialized artifacts (model checkpoints, cache files, pipeline outputs) with multiple inspection tools and sanity checks rather than trusting a single result.
- Enforce policy-level guidance that discourages executable serialization formats for shared or third-party artifacts, and require provenance tracking for ML models.
- Automated security review systems can be configured to alert when new deserialization entry points are introduced or when unsafe patterns are reintroduced in the codebase.

