Summary
picklescan before 1.0.1 contains an unsafe pickle deserialization flaw that allows attackers to hide eval-based payloads inside callable objects accessed via getattr.
When applications rely on picklescan to vet untrusted pickle files, malicious code can bypass detection and execute during pickle loading, leading to remote code execution.
Affected context
This vulnerability affects environments where picklescan is used to assess or filter pickle files, especially in workflows that presume its checks are sufficient to treat pickles as safe.
The risk is elevated when:
- Pickle data originates from untrusted or semi-trusted sources (e.g., user uploads, external services, shared datasets)
- Applications automatically load or unpickle data after scanning
- Security decisions rely on picklescan's ability to detect dangerous constructs rather than treating all pickles as untrusted code
Exploit preconditions
- Attack surface: Any application or service that processes untrusted pickle files and uses picklescan for safety checks.
- Required access: Ability to supply or influence pickle content (e.g., file upload, API input, shared storage).
- Trigger point: The vulnerable pickle is loaded/unpickled after being scanned and incorrectly deemed safe.
- Why exploitation is possible: picklescan's detection logic can be bypassed by nesting eval-like behavior under callable objects accessed via getattr, allowing dangerous operations to be hidden from the scanner while remaining executable during deserialization.
Why this happens
The issue stems from incomplete modeling of Python pickle execution semantics within picklescan's analysis logic.
While the tool attempts to identify dangerous patterns (such as eval calls), it does not fully account for indirection via callable objects and getattr chains, allowing attackers to conceal malicious behavior.
This aligns with CWE-502: Unsafe Deserialization, where untrusted serialized data is treated as safe because security controls focus on limited patterns rather than adopting a strict "code execution by design" posture for the format.
Potential impact
- Remote code execution within the context of the process that loads the pickle
- Compromise of application data, including reading or modifying sensitive information
- Deployment of backdoors or persistence mechanisms on affected hosts
- Lateral movement within the environment using the compromised application as a foothold
- Abuse of available credentials, API keys, or cloud metadata accessible to the process
General mitigation guidance
Effective mitigation focuses on treating pickle as inherently unsafe and reducing trust in security scanning alone.
Recommended defensive patterns include:
- Avoiding pickle for data interchange across trust boundaries; prefer safer, non-executable formats (e.g., JSON, MessagePack, Protobuf) where feasible.
- Treating all pickle data as potentially malicious and only loading it from fully trusted, controlled sources.
- Isolating any unavoidable pickle deserialization in hardened sandboxes or constrained worker processes with minimal privileges and no access to secrets.
- Applying strict input validation and whitelisting for allowed object types or modules when using custom reducers or restricted unpicklers.
- Designing systems so that security does not depend solely on static scanners; layering runtime controls such as SELinux, AppArmor, or container isolation to limit blast radius.
How teams detect issues like this
Detection strategies should combine code-level review with architectural checks:
- Use static analysis and code search to identify all usage of pickle, cPickle, dill, or similar serialization libraries, especially where data originates from external inputs.
- Review application flows where picklescan results are used as a gate to decide whether deserialization is "safe," and flag any automatic unpickling based solely on scanner output.
- Incorporate security reviews that question why pickle is needed and verify that unpickling only occurs in trusted contexts or isolated components.
- Consider integrating automated security testing (SAST/DAST) that looks for unsafe deserialization patterns and policy violations (e.g., "no unpickling of user-controlled data").

