/

CVE-2025-71359

Severity:

HIGH RISK

(8.1)

Unsafe Pickle Deserialization (CWE-502) in picklescan

CVE-2025-71359

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution via bypassed pickle scanning

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 payloads can evade detection in affected versions of picklescan by abusing lib2to3.pgen2.grammar.Grammar.loads within the reduce method during deserialization.

If such crafted pickle files are processed with pickle.load(), attacker-controlled code may be executed, leading to remote code execution wherever untrusted pickle data is accepted.

Affected context

This vulnerability appears in environments that rely on picklescan (before 0.0.29) to vet pickle files for malicious content before using Python's pickle.load() or similar APIs.

It becomes relevant when applications accept or process pickle data from external, semi-trusted, or untrusted sources and assume that picklescan will reliably block hostile payloads.

Systems that treat the scanner as a primary control for safe deserialization, without additional validation or isolation, are more exposed to this class of bypass.

Exploit preconditions

  • Attack surface: Any application path that deserializes pickle data using Python's pickle module and relies on picklescan for security screening.
  • Required access: Ability to supply or influence pickle files consumed by the target application (e.g., uploaded files, network messages, stored objects).
  • Trigger point: A crafted pickle payload is scanned by a vulnerable version of picklescan, passes as benign, and is subsequently deserialized via pickle.load().
  • Why exploitation is possible: picklescan's detection logic does not account for payloads that call lib2to3.pgen2.grammar.Grammar.loads through the reduce mechanism, allowing attacker-controlled behavior to execute during deserialization.

Why this happens

The core issue stems from incomplete coverage in the unsafe deserialization detection logic, aligning with CWE-502: Unsafe Deserialization.

picklescan analyzes pickle opcodes and common execution primitives but fails to model or block reduce-based invocation paths that leverage lib2to3.pgen2.grammar.Grammar.loads.

As a result, certain object graphs and callable references are treated as safe, even though they can execute arbitrary code when unpickled, illustrating a broader pattern: relying on pattern-based scanners without fully constraining the deserialization runtime.

Potential impact

  • Remote code execution in the context of the application performing deserialization
  • Compromise of application data and configuration
  • Lateral movement within the host or container environment, depending on available privileges
  • Abuse of the affected system for further attacks, such as data exfiltration or persistence

General mitigation guidance

Effective mitigation focuses on both hardening deserialization and reducing trust in scanners as a sole control.

Common defensive patterns include:

  • Avoiding use of pickle for untrusted or semi-trusted data and favoring safer, declarative formats (e.g., JSON, protocol buffers) that do not support executable object graphs.
  • Treating all pickle input as untrusted and constraining deserialization to tightly controlled, minimal object types, ideally via whitelisting and object factories.
  • Running any required deserialization routines in isolated, least-privileged contexts (e.g., dedicated worker processes, containers, or sandboxes) to limit blast radius.
  • Complementing scanning tools like picklescan with broader secure design practices, such as strong input validation, strict separation of data and code, and cautious handling of legacy libraries used during deserialization.

How teams detect issues like this

Organizations can improve detection of unsafe deserialization and scanner bypasses through:

  • Static analysis rules and linters that flag direct or indirect usage of pickle, cPickle, or similar arbitrary object deserialization mechanisms, especially on untrusted inputs.
  • Code review checklists that highlight reliance on security scanners as the primary safeguard and encourage examination of object construction paths (e.g., __reduce__, __setstate__, and complex library callbacks).
  • Runtime monitoring for unusual behavior associated with deserialization routines, such as unexpected file access, network calls, or subprocess creation originating from pickle.load()-related code paths.
  • Security policies that restrict or require justification for use of powerful serialization formats, supplemented by automated tools that periodically scan repositories for deserialization patterns and high-risk libraries.

Sources

SourceLink
github.comgithub.com/mmaitre314/picklescan/security/advisories/GHSA-f54q-57x4-jg88
vulncheck.comvulncheck.com/advisories/picklescan-unsafe-deserialization-via-lib2to3-pgen2-grammar-grammar-loads

Frequently asked

questions

It can be, if the application consumes pickle data from remote sources. Attackers who can send or upload crafted pickle files that are scanned by picklescan and then deserialized may achieve remote code execution.

The attacker needs the ability to supply or modify pickle payloads that the application will process. No local shell access is required if the system accepts pickles over a network interface or via user uploads.

The safest approach is to avoid using pickle for any untrusted data and replace it with non-executable serialization formats. If pickle must be used, limit deserialization to a narrow set of safe object types and employ strict isolation of deserialization code.

Build a defensive serialization strategy that assumes deserialization is dangerous by default: prefer non-code-bearing formats, reduce trust in scanners as comprehensive protections, enforce least-privilege around any remaining deserialization, and adopt automated checks that flag high-risk deserialization constructs during development.

Find out what's already
exploitable in your codebase.