/

CVE-2025-71368

Severity:

HIGH RISK

(8.1)

Pickle RCE via doctest.debug_script (CWE-502) bypass

CVE-2025-71368

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.load or 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.

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-fqq6-7vqf-w3fg
vulncheck.comvulncheck.com/advisories/picklescan-arbitrary-code-execution-via-undetected-doctest-debug-script

Frequently asked

questions

Yes, if an application accepts pickle data from remote sources and relies on vulnerable versions of picklescan to assert safety, the attacker can deliver malicious payloads that lead to remote code execution.

The attacker needs the ability to supply or influence pickle content that the application will deserialize, such as via uploads, API endpoints, or shared storage that the application consumes.

The safest pattern is to stop using pickle for data originating outside strict trust boundaries, replacing it with non-executable serialization formats. Where pickle must remain, treat all incoming data as untrusted, and add layered safeguards beyond single-tool detection.

Future prevention depends on designing systems so that data formats cannot trigger code execution, maintaining clear trust boundaries, and consistently reviewing deserialization usage. Combining safer serialization choices with policy, static analysis, and defense-in-depth controls helps avoid reliance on a single detection tool.

Find out what's already
exploitable in your codebase.