Summary
A detection bypass in picklescan before 0.0.29 allows malicious pickle data to use profile.Profile.run in reduce methods without being flagged.
When such crafted pickle files are deserialized, attackers can execute arbitrary code, making systems that rely solely on picklescan for safety vulnerable in remote data processing workflows.
Affected context
This vulnerability appears in environments that:
- Use Python's
picklemodule (or compatible serializers) for loading untrusted or semi-trusted data - Rely on picklescan (before 0.0.29) as a primary safety gate to detect dangerous pickle payloads
- Accept pickle data from remote sources such as APIs, message queues, file uploads, or data lakes
Under these conditions, crafted payloads that leverage profile.Profile.run within the pickle reduce mechanism may evade scanning and be deserialized without additional safeguards.
Exploit preconditions
- Attack surface: Any service or tool that deserializes pickle data after scanning with a vulnerable picklescan version
- Required access: Ability to supply or influence serialized pickle inputs (e.g., upload files, send messages, call APIs)
- Trigger point: Deserialization of the malicious pickle object, typically via
pickle.loadorpickle.loadsafter picklescan reports it as safe - Why exploitation is possible: picklescan's detection logic does not recognize the use of
profile.Profile.runin reduce methods as dangerous, allowing execution-capable constructs to pass validation and run during object reconstruction
Why this happens
The underlying bug stems from incomplete coverage of dangerous callable and method patterns in picklescan's analysis of pickle reduce operations.
In Python, pickle can recreate objects using callable references and arguments; when those callables can execute arbitrary code, reduce-based payloads become execution vectors.
Because profile.Profile.run was not classified or detected as a high-risk execution sink, malicious payloads using it avoided scrutiny, matching the CWE-502: Unsafe Deserialization pattern where untrusted serialized data drives code execution behavior.
Potential impact
- Remote attackers may execute arbitrary Python code on the deserializing host
- Attackers could gain control over application logic and internal workflows
- Data stored or processed by the affected service can be read, modified, or destroyed
- Compromise of surrounding infrastructure through lateral movement from the affected process
- Use of the vulnerable service as a pivot for broader supply-chain or pipeline attacks
General mitigation guidance
Effective mitigation focuses on reducing trust in serialized data and constraining what deserialization can do:
- Avoid deserializing untrusted or user-controlled pickle data whenever possible; prefer structured formats like JSON or protocol buffers
- Treat security scanners like picklescan as advisory checks rather than the sole enforcement mechanism, combining them with strict input validation and sandboxing
- Limit available execution sinks during deserialization by reducing the set of importable modules and callable references in the deserialization context
- Run deserialization routines with least-privilege identities, restricted file system access, and minimized network permissions
- Isolate risky deserialization workflows into separate, closely monitored processes or containers to contain potential compromise
How teams detect issues like this
Detection strategies typically combine code-level analysis with runtime monitoring:
- Use static analysis or grep-based rules to find uses of
pickle,cPickle, or similar libraries where inputs may be controlled by remote parties - Review code paths that rely on picklescan as a gatekeeper to ensure additional validation and authorization checks exist before deserialization
- In code review, look for custom reduce methods, callable references, and dynamic imports that might provide execution capabilities upon object reconstruction
- Employ security tooling that understands Python serialization semantics and can flag high-risk callables or methods used in reduce operations
- Monitor deserialization-heavy services for anomalous behavior, such as unexpected subprocess creation, file changes, or network calls shortly after loading serialized data

