Summary
A flaw in picklescan before version 0.0.34 fails to detect the use of _operator.attrgetter in pickle payloads, allowing malicious constructs to slip past its security checks.
Remote attackers can craft pickle files that abuse attrgetter within __reduce__ methods, leading to arbitrary code execution when applications call pickle.load() on untrusted data.
Affected context
This vulnerability appears in environments that rely on picklescan as a defensive layer when working with Python pickle data.
It is especially relevant where applications:
- Accept or process pickle payloads from external or semi-trusted sources
- Use picklescan to pre-screen payloads before calling
pickle.load() - Assume picklescan will reliably detect dangerous constructs and thereby treat screened payloads as safe
The risk arises when _operator.attrgetter is used within __reduce__ implementations to construct execution-capable objects that picklescan fails to flag.
Exploit preconditions
- Attack surface: Any interface that accepts pickle data and subsequently calls
pickle.load()or equivalent deserialization functions. - Required access: Ability to supply or influence serialized pickle payloads (e.g., file upload, API input, message queue, or shared storage).
- Trigger point: Deserialization of the crafted pickle object by an application using the Python
picklemodule, after the payload has been incorrectly deemed safe by picklescan. - Why exploitation is possible: picklescan before 0.0.34 does not recognize
_operator.attrgetter-based patterns within__reduce__that can be chained to execute code, so adversaries can construct payloads that bypass its checks while still leveraging unsafe deserialization semantics.
Why this happens
The underlying bug is an incomplete validation of deserialization constructs within pickle payloads, mapping directly to CWE-502: Unsafe Deserialization.
picklescan's analysis model fails to treat _operator.attrgetter as a potentially dangerous callable in __reduce__ methods, leaving a gap where code-capable object graphs can be constructed without detection.
In abstract terms, the system trusts a partial pattern-matching approach to classify payloads as safe, but the deserialization mechanism (pickle.load) can interpret more complex combinations of callables and state that picklescan does not fully model, enabling arbitrary behavior during object reconstruction.
Potential impact
- Attackers could achieve arbitrary code execution within the Python process that deserializes the malicious pickle.
- Malicious payloads can bypass picklescan-based security checks, undermining assumptions of safety and defense-in-depth.
- An attacker may escalate from data tampering to full compromise of the application environment or host, depending on process privileges.
- Successful exploitation could lead to data exfiltration, modification of application logic, or deployment of persistence mechanisms within the runtime.
General mitigation guidance
Effective mitigation focuses on both reducing trust in pickle-based data and hardening inspection mechanisms against unsafe deserialization patterns.
Common defensive patterns include:
- Avoiding
picklefor untrusted or cross-boundary data; prefer data-only serialization formats (e.g., JSON, protocol buffers) that do not support executable constructs. - Treating any deserialization mechanism as a potential execution vector and enforcing strict boundaries around what data can be deserialized and where it originates.
- Applying a deny-by-default policy in payload analysis tools: explicitly model and block callable objects and reduction patterns that can lead to code execution, rather than relying on incomplete allow-lists.
- Running deserialization logic in processes with minimal privileges, strong isolation, and limited filesystem or network access to reduce blast radius if unsafe payloads slip through.
- Incorporating schema validation or structural constraints for serialized data, ensuring application logic cannot load arbitrary objects without verification of type and content.
How teams detect issues like this
Organizations can approach detection by combining static and dynamic scrutiny of code and its deserialization practices:
- Static analysis rules to flag use of
pickle.load,pickle.loads, or similar APIs, especially on data originating from untrusted channels, and require review or justification. - Code review checklists that highlight assumptions around picklescan or similar tools, ensuring developers understand these are advisory filters rather than absolute safety guarantees.
- Policy-based controls in CI/CD pipelines that detect deserialization of attacker-controlled data, and that track the introduction of new callable patterns or helper functions used in
__reduce__implementations. - Runtime monitoring for suspicious deserialization behavior, such as unusual file access, process creation, or module imports occurring immediately after loading serialized objects.
- Optionally, use automated security scanners or linters configured with custom rules for pickle usage and unsafe deserialization constructs, including functions like
_operator.attrgetterand other callable helpers.

