/

CVE-2025-71350

Severity:

HIGH RISK

(8.1)

Unsafe Pickle Deserialization (CWE-502) in picklescan

CVE-2025-71350

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution via malicious pickle payloads

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 prior to version 0.0.28 fails to flag malicious pickle payloads that leverage the torch.utils.collect_env.run function inside custom reduce methods.

Under these conditions, attackers can embed undetected code into pickle files that executes remote commands when victims load the files in Python environments.

Affected context

This vulnerability appears in environments that rely on picklescan (before 0.0.28) to vet Python pickle files for malicious content.

It is most relevant in workflows where untrusted or semi-trusted pickle artifacts (models, datasets, cached states) are scanned prior to being loaded, particularly in machine learning pipelines using PyTorch.

The issue manifests when attackers craft pickle payloads that use the torch.utils.collect_env.run function in __reduce__ methods, bypassing picklescan's detection logic and remaining indistinguishable from benign files to the scanner.

Exploit preconditions

  • Attack surface: Python applications that load pickle files, especially ML workflows using PyTorch and relying on picklescan for safety checks.
  • Required access: Ability to supply or influence pickle files consumed by victims (e.g., model sharing platforms, artifact repositories, shared notebooks).
  • Trigger point: Deserialization of the malicious pickle using pickle.load or equivalent APIs in a Python process where the vulnerable detection logic was previously assumed to validate the file.
  • Why exploitation is possible: picklescan's analysis does not correctly interpret or flag the use of torch.utils.collect_env.run in custom reduce methods, allowing attacker-controlled code paths to execute during unpickling.

Why this happens

The underlying issue is a variant of CWE-502: Unsafe Deserialization, compounded by incomplete detection coverage in a security scanning tool.

Pickle is inherently capable of reconstructing arbitrary Python objects and can execute attacker-influenced behavior during reconstruction (e.g., via __reduce__).

picklescan's logic failed to treat the torch.utils.collect_env.run invocation inside reduce methods as a potential execution sink, leaving a gap where malicious payloads could be crafted to run remote commands during deserialization while evading the scanner's heuristics.

Potential impact

  • Remote command execution on systems that load attacker-crafted pickle files
  • Compromise of development or production ML environments
  • Theft or corruption of sensitive data, configuration, or model parameters
  • Establishment of backdoors or persistence mechanisms via poisoned artifacts
  • Lateral movement from compromised ML tooling into adjacent infrastructure

General mitigation guidance

Mitigation typically centers on reducing trust in pickle-based artifacts and constraining deserialization behavior.

Pattern-based strategies include:

  • Avoiding pickle for untrusted or externally sourced artifacts, favoring safer interchange formats (e.g., JSON, protocol buffers, or domain-specific export formats).
  • Enforcing strict separation between trusted and untrusted data sources, and treating all external pickle inputs as hostile unless independently verified.
  • Running deserialization routines within sandboxed, least-privilege environments that limit potential damage from code execution (e.g., containers with restricted permissions and network egress controls).
  • Applying whitelisting of allowed object types or controlled loaders where possible, rather than generic pickle deserialization.
  • Incorporating defense-in-depth checks that look for deserialization sinks and reduce-method invocations, rather than relying on a single scanning tool.

How teams detect issues like this

Effective detection generally combines static and dynamic review of deserialization logic:

  • Static analysis rules targeting use of pickle.load, pickle.loads, and custom __reduce__ / __setstate__ implementations, especially when combined with external command execution or environment inspection utilities such as torch.utils.collect_env.run.
  • Code review practices that flag any deserialization of untrusted data, with reviewers explicitly checking for hidden execution paths in object reconstruction methods.
  • Policy enforcement that prohibits generic pickle deserialization in high-risk contexts (e.g., CI pipelines, artifact ingestion services) or requires explicit justification and threat modeling.
  • Supplemental automated tools capable of scanning artifacts and source code for known unsafe deserialization patterns, used as an adjunct to human review rather than a sole line of defense.

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-f745-w6jp-hpxx
vulncheck.comvulncheck.com/advisories/picklescan-undetected-remote-code-execution-via-torch-utils-collect-env-run

Frequently asked

questions

It can be, if applications accept pickle files over network channels (e.g., APIs, file uploads, shared artifact repositories) and then deserialize them. The key risk is wherever untrusted pickle data is loaded.

An attacker must be able to provide or modify pickle files that a victim's Python environment will load. This could be through shared model repositories, data interchange platforms, or compromised storage where artifacts are exchanged.

The safest approach is to avoid using pickle for data received from outside trusted boundaries, replacing it with formats that do not embed executable behavior. Where pickle is unavoidable, restrict the set of allowed object types and isolate deserialization into tightly constrained environments.

Establish organization-wide policies that treat all deserialization operations as high-risk, mandate reviews for any use of pickle or equivalent mechanisms, integrate static analysis focused on unsafe deserialization sinks, and employ multiple layers of validation rather than relying solely on one scanning tool.

Find out what's already
exploitable in your codebase.