Summary
A flaw in picklescan prior to version 0.0.30 allows malicious pickle payloads using cProfile.run to evade detection.
When such crafted pickle files are deserialized, remote attackers can execute arbitrary code on the system that processes them, making any workflow that relies on picklescan for safety particularly risky.
Affected context
This vulnerability appears in environments that rely on picklescan (before 0.0.30) to vet untrusted or semi-trusted pickle data before deserialization.
It is most relevant where:
- Python pickle is used to load data from external or user-controlled sources
- Security controls assume picklescan will detect dangerous reducer methods
- Deserialization occurs automatically in batch jobs, APIs, or data pipelines without additional validation
Exploit preconditions
- Attack surface: Any interface, service, or pipeline that accepts pickle data and uses picklescan for screening.
- Required access: Ability to provide or influence serialized pickle content (e.g., upload, API parameter, message queue item).
- Trigger point: Deserialization of a malicious pickle object after it has passed picklescan checks.
- Why exploitation is possible: picklescan fails to recognize
cProfile.runcalls embedded in reduce methods as dangerous, allowing attacker-controlled code paths to be executed during unpickling.
Why this happens
The underlying issue is incomplete coverage in the unsafe deserialization detection logic of picklescan.
The tool's analysis of pickle reduce methods does not treat cProfile.run invocations as potentially executable attacker-controlled code, so these payloads are not flagged as suspicious.
This maps directly to CWE-502: Unsafe Deserialization, where applications trust serialized data and rely on insufficient safeguards, allowing logic or code execution during object reconstruction.
Potential impact
- Remote execution of arbitrary Python code during pickle deserialization
- Compromise of the application process handling the pickle data
- Unauthorized access to local files, environment variables, and secrets
- Pivoting to other internal systems reachable from the compromised host
- Tampering with data processed or produced by vulnerable pipelines
General mitigation guidance
Mitigation should focus on reducing trust in pickle-based data and hardening deserialization flows rather than relying solely on detection tools.
Common defensive patterns include:
- Avoiding pickle for untrusted or external data in favor of safer, schema-based formats.
- Isolating deserialization logic in tightly constrained, low-privilege execution environments.
- Applying explicit allowlists for callable targets and reducer methods during object reconstruction.
- Implementing layered validation and authorization checks before acting on deserialized content.
- Treating security scanning utilities like picklescan as one control among several, not a standalone gate.
How teams detect issues like this
Effective detection typically combines static and dynamic perspectives:
- Static analysis rules that flag use of
pickle,cPickle, or custom reducers handling external input. - Code review practices that scrutinize any deserialization of data originating outside the trust boundary.
- Policy-based checks in CI pipelines to discourage unsafe serialization formats for user-controlled data.
- Monitoring for unexpected
cProfile.runusage or unusual execution paths during deserialization in runtime telemetry.
Automated security review tools can help surface unsafe deserialization patterns but should be complemented by manual review and architectural controls.

