Summary
A flaw in picklescan before version 0.0.29 fails to recognize the dangerous use of the built-in trace.Trace.run function in pickle payloads, allowing malicious code to remain undetected during analysis.
Remote attackers can craft pickle files that leverage trace.Trace.run in the reduce method, leading to arbitrary code execution when pickle.load processes these files in environments that rely on picklescan for safety checks.
Affected context
This vulnerability affects systems that use picklescan as a security gate or auditing tool for Python pickle files but still deserialize those files with pickle.load.
It becomes relevant in workflows where:
- Untrusted or semi-trusted pickle data is accepted (e.g., uploaded artifacts, cached models, serialized jobs)
- picklescan is assumed to detect dangerous constructors and functions
- The decision to load a pickle is influenced by picklescan's analysis results
In such contexts, reliance on incomplete detection allows crafted payloads using trace.Trace.run to bypass scrutiny.
Exploit preconditions
- Attack surface: Any interface that accepts pickle files (APIs, file uploads, message queues, shared storage) and analyzes them with picklescan before deserialization.
- Required access: Ability for an attacker to supply or influence pickle content that will be scanned by picklescan and later loaded with
pickle.load. - Trigger point: Invocation of
pickle.load(or similar APIs) on a malicious pickle that was previously deemed safe by picklescan. - Why exploitation is possible: picklescan's detection logic does not treat
trace.Trace.runas a dangerous construct, allowing an attacker to embed it in the reduce method so that code is executed during deserialization without being flagged.
Why this happens
The underlying bug is an instance of CWE-502: Unsafe Deserialization, combined with incomplete threat modeling in a security scanning tool.
Python's pickle protocol allows arbitrary object construction and method invocation during deserialization, making it inherently dangerous for untrusted data.
picklescan attempts to statically inspect pickle opcodes to identify unsafe patterns but fails to classify the built-in trace.Trace.run function as a high-risk execution primitive.
This gap means that payloads using trace.Trace.run in the reduce chain can slip past detection, leaving the downstream pickle.load call to perform unsafe deserialization on what is incorrectly perceived as a benign object graph.
Potential impact
- Remote attackers may achieve arbitrary code execution on systems that deserialize attacker-supplied pickle files.
- Malicious payloads can run with the privileges of the application process performing
pickle.load. - Attackers could access or modify sensitive data processed by the application.
- Compromised hosts may be used as footholds for lateral movement within the network.
- Integrity of serialized artifacts (models, jobs, configurations) could be violated or poisoned.
General mitigation guidance
Effective mitigation focuses on reducing trust in pickle content and ensuring that security controls do not rely solely on scanners like picklescan:
- Avoid deserializing untrusted or semi-trusted data with
pickleand prefer data-only formats (JSON, MessagePack, protocol buffers) that do not allow arbitrary code execution. - Treat pickles as inherently privileged artifacts; limit who can produce them and where they can be loaded.
- Enforce process isolation and least privilege for components that must still consume pickle data, so that any code execution is contained.
- Complement scanning tools with strict policy: only accept pickles from controlled build pipelines or signed sources, rather than arbitrary external inputs.
- Maintain allowlists/denylists of callable objects and modules permitted in serialized payloads, rejecting anything that can invoke general-purpose execution primitives.
How teams detect issues like this
High-level detection approaches include:
- Static analysis of Python code to flag any use of
pickle.loador similar APIs on data that originates from untrusted channels. - Code review practices that treat deserialization boundaries as critical points, checking for assumptions about picklescan or other scanners as sufficient protection.
- Security policies that require non-executable serialization formats for external-facing inputs and document exceptions explicitly.
- Runtime monitoring to detect unusual or unauthorized execution paths triggered during deserialization flows.
- Using automated tools (SAST/DAST and specialized serialization analyzers) to surface unsafe deserialization patterns and missing validation in CI pipelines.

