/

CVE-2025-71342

Severity:

HIGH RISK

(8.1)

Unsafe Pickle Deserialization (CWE-502) in picklescan

CVE-2025-71342

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

Malicious pickle files can bypass detection in vulnerable versions of picklescan, allowing embedded code to execute when pickle.load is called.

When untrusted or third-party model artifacts are scanned with an affected picklescan version, attackers may achieve remote code execution and perform supply chain attacks.

Affected context

This vulnerability appears in environments that rely on picklescan (before 0.0.30) to detect malicious Python pickle payloads, particularly around machine learning model loading.

It is most relevant where:

  • PyTorch or other frameworks load pickled models or artifacts
  • Artifacts are obtained from external or semi-trusted sources
  • Security checks depend on picklescan's analysis to flag dangerous reduce methods

In these contexts, malicious code hidden inside pickle files may pass validation and execute at load time.

Exploit preconditions

  • Attack surface: Deserialization of attacker-controlled pickle files (e.g., ML models, datasets, cached objects).
  • Required access: Ability to supply or modify pickle files that a target application will scan with picklescan and then load using pickle.load.
  • Trigger point: Invocation of pickle.load or equivalent deserialization routines on a crafted pickle that uses idlelib.run.Executive.runcode in its reduce method.
  • Why exploitation is possible: The vulnerable picklescan versions do not recognize this reduce-based execution path as malicious, allowing dangerous code to remain undetected and execute during normal deserialization.

Why this happens

The core issue is an incomplete detection strategy for unsafe deserialization patterns in Python pickle files.

picklescan before 0.0.30 fails to account for the use of idlelib.run.Executive.runcode inside reduce methods, a pattern that can execute arbitrary Python code at unpickle time.

This maps to CWE-502: Unsafe Deserialization, where serialized data is treated as benign input, while embedded logic can run during object reconstruction without being flagged or constrained by security checks.

Potential impact

  • Attackers may execute arbitrary Python code on systems loading crafted pickle files.
  • PyTorch models and other ML artifacts can be weaponized to perform supply chain attacks.
  • Compromise of the application process running the deserialization, leading to data theft or tampering.
  • Installation of backdoors or persistence mechanisms through malicious model loading pipelines.

General mitigation guidance

Defenses should focus on reducing trust in serialized artifacts and constraining deserialization behavior rather than relying solely on detection tools.

Common mitigation patterns include:

  • Avoiding generic pickle-based deserialization for data or models from untrusted or third-party sources.
  • Using serialization formats that lack executable behavior (e.g., JSON, protocol buffers, or framework-specific safe formats) for interchange.
  • Enforcing strict separation between code and model data, ensuring that model loading does not implicitly execute arbitrary logic.
  • Applying least-privilege principles to processes that must deserialize pickle files, limiting OS-level capabilities in case execution occurs.
  • Incorporating layered validation and sandboxing around ML artifact loading pipelines to reduce the blast radius of a compromised artifact.

How teams detect issues like this

Detection typically involves analyzing deserialization flows and serialized artifacts for execution-capable constructs.

Effective strategies can include:

  • Static analysis rules that identify unsafe use of pickle.load, especially on data sourced from external or semi-trusted locations.
  • Code review practices that flag reliance on pickle for cross-boundary data exchange or model distribution.
  • Artifact scanning policies that look for suspicious reduce methods or references to execution helpers such as idlelib.run.Executive.runcode.
  • CI/CD checks that prevent introducing new pickle-based interfaces for remote or user-supplied data without explicit security review.
  • Use of automated review tools configured to highlight CWE-502 patterns and deserialization hotspots in ML pipelines.

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-m869-42cg-3xwr
vulncheck.comvulncheck.com/advisories/picklescan-undetected-remote-code-execution-via-idlelib-run-executive-runcode

Frequently asked

questions

Yes, if an attacker can deliver malicious pickle files that a remote system will scan with picklescan and then deserialize using pickle.load, they can potentially execute code on that system.

The attacker must be able to introduce or modify pickle files consumed by the application—such as uploading a model, pushing artifacts into a repository, or influencing cached objects used in ML workflows.

The safest approach is to minimize or eliminate the use of pickle for untrusted data, favor non-executable serialization formats, and ensure any necessary deserialization occurs inside strongly constrained and monitored environments.

Establish policies that treat deserialization as a high-risk operation, require explicit review of any pickle usage, adopt safer serialization standards for shared artifacts, and integrate automated checks for CWE-502 patterns into development and deployment pipelines.

Find out what's already
exploitable in your codebase.