/

CVE-2025-71321

Severity:

CRITICAL RISK

(9.8)

Unsafe Pickle Deserialization (CWE-502) in picklescan

CVE-2025-71321

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Arbitrary File Write leading to Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

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

picklescan contains an unsafe deserialization issue that allows malicious pickle data to bypass a dangerous blocklist and reach file-writing functionality.

By crafting specific pickle payloads, an attacker can overwrite arbitrary files on the system, which may lead to denial of service or remote code execution when targeted files are modified.

Affected context

This vulnerability occurs in environments where picklescan is used to inspect or process pickle data that may not be fully trusted.

The risk is elevated when:

  • Pickle payloads are accepted from external sources (e.g., user uploads, network inputs, shared artifacts)
  • The application relies on picklescan to detect or block dangerous pickle behaviors via a blocklist
  • The runtime user has write access to sensitive configuration, code, or service files whose modification changes application behavior

Exploit preconditions

  • Attack surface: Any interface where picklescan processes attacker-controlled or influenced pickle data
  • Required access: Ability to submit or cause processing of crafted pickle objects (remote or local, depending on deployment)
  • Trigger point: Deserialization or static analysis of a pickle that invokes distutils.file_util.write_file via pickle opcodes
  • Why exploitation is possible: The protection mechanism relies on a dangerous-object blocklist that can be bypassed; deserialization still permits invocation of file-write functionality, enabling arbitrary file overwrite under the privileges of the running process

Why this happens

The core issue is reliance on unsafe deserialization of pickle data combined with an incomplete or bypassable blocklist for dangerous behaviors.

Instead of enforcing a strict allowlist or using a non-executable serialization format, the code path permits construction of objects and invocation of helpers like distutils.file_util.write_file during pickle evaluation.

This aligns with CWE-502: Deserialization of Untrusted Data, where attackers craft serialized payloads to drive control flow and access powerful primitives—in this case, arbitrary file writes—despite nominal checks intended to prevent such operations.

Potential impact

  • Overwriting critical configuration files that may alter application logic
  • Corrupting system or application files, causing denial of service
  • Planting or modifying scripts and executables that can later be executed for remote code execution
  • Tampering with security controls (e.g., disabling logging or altering access rules) through targeted file overwrites
  • Facilitating privilege escalation when combined with weak file ownership or misconfigured service restart mechanisms

General mitigation guidance

Effective mitigation focuses on reducing trust in pickle input and eliminating arbitrary code execution paths during deserialization.

Recommended defensive patterns include:

  • Avoiding pickle for untrusted or semi-trusted data; prefer formats like JSON, Protobuf, or other non-executable encodings
  • Applying strict allowlists for permissible object types and modules if pickle use is unavoidable
  • Removing or isolating high-impact primitives (such as file-writing helpers) from code paths that handle serialized data
  • Running analysis or deserialization routines under least-privilege accounts with minimal filesystem write permissions
  • Separating components that interact with untrusted data from those that manage sensitive configuration or executable files

How teams detect issues like this

Detection typically combines code-centric and behavior-centric approaches:

  • Static analysis rules to flag uses of pickle and related modules when applied to non-validated or externally sourced data
  • Code review checklists that treat any deserialization—especially pickle—as a high-risk area requiring explicit justification and allowlisting
  • Policies that prohibit direct invocation of file-writing utilities during deserialization or analysis of serialized data
  • Runtime monitoring or sandboxing that alerts on unexpected file writes originating from pickle handling components
  • Integration of automated security scanning tools in CI pipelines to catch unsafe deserialization patterns before release

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-m273-6v24-x4m4
vulncheck.comvulncheck.com/advisories/picklescan-arbitrary-file-writing-via-distutils-module-bypass

Frequently asked

questions

It can be, if an application exposes an interface where remote users can supply or influence pickle data that is then processed by picklescan. In local-only workflows, exploitation is typically limited to users with local access.

An attacker must be able to provide crafted pickle payloads to the component using picklescan. They do not need shell access, but they do need control over input that reaches the vulnerable deserialization path.

The safest approach is to avoid processing untrusted data with pickle altogether and to remove reliance on blocklists for security. If pickle must be used, apply strict allowlists and ensure that powerful primitives like generic file-writing utilities are inaccessible during deserialization.

Use non-executable serialization formats for untrusted data, establish architectural rules that ban unsafe deserialization, enforce least privilege on services that handle serialized input, and add automated checks in code review and CI to flag any use of high-risk deserialization APIs.

Find out what's already
exploitable in your codebase.