Summary
A flaw in picklescan before version 0.0.30 fails to recognize malicious use of the doctest.debug_script function when analyzing Python pickle files.
Attackers can craft pickle payloads that invoke doctest.debug_script and evade picklescan's checks, leading to arbitrary command execution when the application calls pickle.load on untrusted data.
Affected context
This vulnerability appears in Python ecosystems where picklescan is relied on to pre-screen pickle files for unsafe constructs.
It becomes relevant whenever applications load pickle data from semi-trusted or untrusted sources and depend on picklescan's analysis as a safety net.
The issue specifically affects contexts that allow doctest.debug_script to be reachable at runtime and do not otherwise constrain or sandbox deserialization behavior.
Exploit preconditions
- Attack surface: Any component that invokes
pickle.loador similar APIs on data that has been "validated" by vulnerable versions of picklescan. - Required access: Ability for an attacker to supply or influence pickle content (e.g., file uploads, networked data streams, cached artifacts).
- Trigger point: Deserialization of a crafted pickle containing doctest.debug_script references, following a pass through picklescan that fails to flag it.
- Why exploitation is possible: picklescan's detection logic does not treat doctest.debug_script as a dangerous execution primitive, allowing unsafe opcodes to persist and execute during deserialization.
Why this happens
The underlying bug belongs to the unsafe deserialization class (CWE-502), where complex data formats like Python pickle are able to instantiate code-capable objects.
In this case, picklescan's security model assumes it can detect and block dangerous patterns but omits doctest.debug_script from its checks.
Because pickle supports invoking arbitrary callables and module functions on load, incomplete detection allows attacker-controlled byte streams to reach execution-capable objects, breaking the safety assumptions of users who trust picklescan's analysis.
Potential impact
- Attackers may execute arbitrary OS commands on the system deserializing the malicious pickle.
- Compromised hosts could be used for lateral movement within the environment.
- Sensitive data processed or stored by the affected application may be exfiltrated or altered.
- Application integrity can be undermined, enabling backdoors, logic tampering, or supply chain manipulation.
General mitigation guidance
Mitigation efforts should focus on reducing trust in pickle inputs and limiting code-capable behaviors during deserialization.
Common defensive patterns include:
- Avoiding pickle for untrusted or semi-trusted data, using safer serialization formats (e.g., JSON, MessagePack) that lack execution side effects.
- Treating any deserialization as a high-risk operation and enforcing strict separation of data and executable logic.
- Constraining runtime environments with least privilege, minimizing what code can do if deserialization is abused.
- Implementing additional validation layers beyond single-tool checks, such as schema validation or whitelisting expected object types.
How teams detect issues like this
Detection typically combines code-level and process-level review:
- Static analysis rules that flag uses of pickle with untrusted data sources or highlight calls to doctest.debug_script and similar execution primitives.
- Code review practices that challenge reliance on security scanners as sole protection for unsafe formats, and look for assumptions that "picklescan makes this safe."
- Security policies that treat use of pickle in externally facing interfaces as a design risk requiring sign-off or alternative patterns.
- Automated tooling that searches for deserialization hotspots and enforces serialization hardening guidelines in CI/CD pipelines.

