/

CVE-2025-71344

Severity:

HIGH RISK

(8.1)

Unsafe Deserialization (CWE-502) in picklescan Scanner

CVE-2025-71344

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 gap in picklescan's detection logic for malicious pickle payloads allows built-in function ensurepip._run_pip to be embedded in __reduce__ methods without being flagged.

When such a crafted pickle is later deserialized with pickle.load(), attackers may achieve arbitrary code execution despite prior scanning.

Affected context

This vulnerability affects environments that rely on vulnerable versions of picklescan (0.0.26 and earlier) as a safety gate before loading untrusted or semi-trusted Python pickle files.

It manifests when applications assume that a "clean" picklescan report implies a pickle is safe to deserialize, even though the underlying use of pickle.load() remains inherently dangerous.

The issue is specific to payloads that use ensurepip._run_pip in their __reduce__ implementations, which are not recognized as dangerous by affected picklescan versions.

Exploit preconditions

  • Attack surface: Any Python component that:
  • Uses picklescan (before 0.0.30) to vet pickle files, and
  • Subsequently deserializes them using pickle.load() or equivalent APIs.
  • Required access: Ability to supply or influence serialized pickle content (e.g., uploaded model files, cached objects, or data exchanged between services).
  • Trigger point: Deserialization of a malicious pickle containing an ensurepip._run_pip reference within its __reduce__ logic.
  • Why exploitation is possible: The scanner's detection rules do not treat ensurepip._run_pip as a dangerous callable, so the payload passes validation and is later executed by pickle's deserialization machinery.

Why this happens

The underlying bug belongs to the unsafe deserialization class (CWE-502) and is amplified by incomplete security scanning.

Python's pickle protocol allows objects to define __reduce__ methods that specify how they are reconstructed, including calling arbitrary functions during unpickling.

In this case, picklescan's detection logic fails to classify ensurepip._run_pip as a high-risk callable, leaving a deserialization gadget chain undetected.

The abstract insecure pattern is trusting a best-effort static check on a highly dynamic, code-executing serialization format and assuming that the absence of known bad patterns makes deserialization safe.

Potential impact

  • Attackers can execute arbitrary OS-level commands when the malicious pickle is loaded.
  • Compromise of the Python process running pickle.load(), including theft or manipulation of in-memory secrets and data.
  • Installation or modification of Python packages via pip, potentially leading to persistent supply-chain compromise.
  • Lateral movement within the hosting environment if the compromised process has network or filesystem access.
  • Service disruption or denial of service resulting from arbitrary code execution.

General mitigation guidance

Mitigation typically focuses on both reducing trust in pickle-based workflows and hardening scanning assumptions:

  • Treat all pickle deserialization as inherently unsafe when the data source is not fully trusted, regardless of prior scanning results.
  • Prefer safer serialization formats (e.g., JSON, MessagePack, or custom schemas) that do not support arbitrary code execution on load.
  • When pickle is unavoidable, strictly constrain which components are allowed to deserialize data and run them with least privilege and strong sandboxing.
  • Complement scanning tools with allowlists of expected types and modules, rejecting any pickle that references unexpected callables or modules.
  • Incorporate defense-in-depth controls such as process isolation, filesystem restrictions, and network egress limits around components that must unpickle data.

How teams detect issues like this

Detection efforts can focus on both code and runtime behavior:

  • Use static analysis or code search to identify all uses of pickle.load(), pickle.loads(), and equivalent deserialization APIs, especially where input originates from external or user-controlled sources.
  • Review build and deployment pipelines to ensure no one treats picklescan or similar tools as a definitive safety guarantee; policies should flag direct deserialization of externally sourced pickles.
  • Extend or configure scanning rules to treat calls to built-in or standard-library functions that can invoke pip, spawn processes, or manipulate the environment as high risk when referenced in __reduce__.
  • Monitor runtime logs and telemetry for anomalous package installation, subprocess invocation, or unexpected network traffic originating from components that handle pickle data.
  • Integrate automated security testing that feeds known-dangerous pickle payloads into deserialization endpoints to validate that compensating controls are effective.

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-xp4f-hrf8-rxw7
vulncheck.comvulncheck.com/advisories/picklescan-arbitrary-code-execution-via-undetected-ensurepip-run-pip-function

Frequently asked

questions

It can be, if an attacker can supply pickle data over a network boundary (for example through file uploads, API payloads, or shared storage) that is scanned with affected picklescan versions and then deserialized.

The attacker needs the ability to influence or provide pickle files that a vulnerable system will scan using picklescan and then load using pickle.load(); no direct shell or local account on the target host is required if the application accepts remote input.

The safest pattern is to avoid using pickle for untrusted data altogether, replacing it with non–code-executing formats and enforcing strict schemas, while treating scanners as advisory rather than authoritative for security.

Adopt design rules that ban deserialization of untrusted data with code-capable formats, enforce security reviews around any remaining serialization logic, use allowlists for expected object graphs, and establish defense-in-depth controls (sandboxing, least privilege) around any component that must perform deserialization.

Find out what's already
exploitable in your codebase.