Summary
A deserialization bypass in picklescan allows malicious pickle files using cProfile.runctx to evade detection.
When such files are later loaded with pickle.load(), attackers can execute arbitrary code in the context of the loading application.
Affected context
This vulnerability affects Python applications that rely on picklescan as a safeguard against malicious pickle files.
It becomes relevant when applications both:
- Accept or process pickle data from semi-trusted or untrusted sources, and
- Depend on picklescan's scanning logic to block dangerous constructs before calling
pickle.load()or similar APIs.
In this context, pickle payloads that use cProfile.runctx in their reduce methods can pass through scanning and still perform dangerous actions when deserialized.
Exploit preconditions
- Attack surface: Any component that ingests external pickle data and uses picklescan for security filtering.
- Required access: Ability to supply or influence pickle files consumed by the target application (e.g., file upload, message queue, cached objects, or shared storage).
- Trigger point: Invocation of
pickle.load()(or equivalent) on a malicious pickle that has successfully passed picklescan scanning. - Why exploitation is possible: picklescan's detection logic does not recognize
cProfile.runctx-based execution paths within reduce methods, allowing attacker-controlled functions or code objects to be executed during deserialization.
Why this happens
The underlying issue is an incomplete detection strategy for unsafe deserialization patterns in pickle payloads.
While picklescan aims to detect dangerous global references and reduce-method constructs, its ruleset does not account for cProfile.runctx being leveraged as an execution primitive.
This aligns with CWE-502: Unsafe Deserialization, because untrusted serialized data can still trigger arbitrary code execution when deserialized, due to inadequate filtering of all known execution vectors within pickle protocols.
Potential impact
- Execution of arbitrary Python code in the application process.
- Compromise of application integrity, including modification or exfiltration of data.
- Installation of backdoors or persistence mechanisms via malicious payloads.
- Use of the compromised process as a pivot point for broader system or network attacks.
General mitigation guidance
Mitigation typically focuses on minimizing reliance on pickle for untrusted data and hardening deserialization paths.
Useful defensive patterns include:
- Treating all pickle input as untrusted and avoiding it for external or cross-trust-boundary data where possible.
- Introducing explicit allowlists of expected types and modules, and rejecting anything outside that set before deserialization.
- Running deserialization logic in a constrained environment (e.g., separate process, restricted permissions, sandbox) so that potential execution has limited impact.
- Applying defense-in-depth by combining scanning tools with protocol-level restrictions and strong authentication/authorization on data sources.
How teams detect issues like this
Detection generally combines code-level review and runtime monitoring.
Possible strategies include:
- Static analysis rules or linters flagging use of
pickle.load,pickle.loads, or similar APIs on data that can be influenced by external users. - Code review checklists that call out deserialization paths and verify they are not used across trust boundaries without strict validation.
- Policy-based controls (e.g., internal security guidelines) that require justification and approval for using pickle in production systems.
- Use of automated scanning tools to identify unsafe deserialization patterns and monitor for suspicious serialized payloads in logs or storage.

