Summary
A detection gap in picklescan before version 0.0.29 allows specially crafted pickle files using idlelib.autocomplete.AutoComplete.fetch_completions in reduce methods to evade scanning.
If a victim loads these undetected pickle files, embedded code can run and execute arbitrary commands, making environments that deserialize untrusted pickles particularly risky.
Affected context
The vulnerability appears in workflows that rely on picklescan as a safeguard when handling Python pickle files, especially where pickles may originate from semi-trusted or unknown sources.
It is most relevant in environments that:
- Automatically load or deserialize pickle data
- Assume picklescan will flag malicious payloads
- Use tools or pipelines where pickle-based artifacts are exchanged across trust boundaries
In such contexts, the undetected malicious reduce methods can bypass scanning and still reach deserialization routines.
Exploit preconditions
- Attack surface: Systems or applications that consume pickle files and use picklescan for security screening.
- Required access: Ability to provide or influence pickle content that a victim system will later load (e.g., uploaded models, cached objects, shared artifacts).
- Trigger point: Victim deserializes the crafted pickle file using standard Python pickle APIs after it has passed picklescan checks.
- Why exploitation is possible: picklescan does not recognize malicious use of
idlelib.autocomplete.AutoComplete.fetch_completionsin reduce methods, allowing attacker-controlled code paths to remain undetected and execute during deserialization.
Why this happens
This issue stems from incomplete coverage of dangerous code paths in picklescan's analysis of pickle opcodes and their associated reduce methods.
Under CWE-502 (Unsafe Deserialization), the core problem is treating complex object reconstruction logic as benign without fully modeling or restricting how functions like AutoComplete.fetch_completions can be abused during unpickling.
Because the analyzer fails to classify this particular pattern as malicious or high risk, embedded attacker-controlled behavior is allowed through, resulting in undetected unsafe deserialization when the pickle is later loaded.
Potential impact
- Malicious pickle files may evade detection and be treated as safe.
- Attackers could execute arbitrary OS commands when victims load the crafted pickle.
- Compromise of local user environments, including access to files and credentials.
- Execution of arbitrary Python code within affected applications or tooling.
- Facilitation of lateral movement if the deserialization occurs in privileged or networked contexts.
General mitigation guidance
Effective mitigation focuses on reducing trust in pickle input and hardening deserialization workflows, rather than relying solely on any single scanner.
Common defensive patterns include:
- Avoiding pickle for data exchange across trust boundaries and preferring safer, non-executable serialization formats such as JSON or protocol buffers.
- Treating all pickle files as untrusted by default and isolating deserialization in low-privilege, sandboxed environments.
- Enforcing architectural rules that disallow dynamic object construction from untrusted sources.
- Using multiple, complementary security checks (linting, static analysis, and policy enforcement) around any deserialization code.
- Applying least-privilege principles to processes that must deserialize data, limiting the potential damage of successful code execution.
How teams detect issues like this
Detection strategies should focus both on the static characteristics of deserialization code and on how pickle files are processed in the broader system:
- Use static analysis rules to flag calls to generic Python pickle loaders (
pickle.load,pickle.loads,dill.load, etc.) when applied to data from untrusted or external sources. - During code review, look for reliance on security scanners as the only line of defense and identify complex reduce methods or object reconstruction patterns that may conceal executable behavior.
- Define and enforce organizational policies that restrict or prohibit use of pickle in interfaces exposed to external input, and require explicit threat modeling where pickle is essential.
- Consider automated review tools that can model serialization flows, highlight unsafe deserialization hotspots, and cross-reference them with known risky functions or modules used in reduce methods.

