/

CVE-2021-47952

Severity:

CRITICAL RISK

(9.8)

Code Injection / Unsafe Deserialization in python-jsonpickle

CVE-2021-47952

Deferred

Vulnerability type

Category:

Code Injection / Unsafe Deserialization

CWE:

CWE-94, CWE-502

Impact:

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

python-jsonpickle 2.0.0 is vulnerable to code injection when deserializing attacker-controlled JSON payloads containing py/repr objects.

Crafted JSON can trigger eval during deserialization, allowing execution of arbitrary Python commands and system-level code where the library runs.

Affected context

This vulnerability affects applications that:

  • Use python-jsonpickle 2.0.0 to deserialize JSON data,
  • Accept JSON input that is fully or partially controlled by external users or integrated services, and
  • Allow py/repr or similar extended types to be processed during deserialization.

The risk is highest in APIs, web services, message consumers, and microservices that treat incoming JSON as trusted and pass it directly to jsonpickle.decode or equivalent functions.

Exploit preconditions

  • Attack surface: Any endpoint or component where untrusted JSON is decoded using python-jsonpickle (e.g., HTTP APIs, message queues, RPC interfaces, task queues).
  • Required access: Ability to supply or influence JSON data that will be deserialized (remote attacker in most networked applications).
  • Trigger point: Invocation of jsonpickle.decode() or compatible decoding function on the malicious JSON string.
  • Why exploitation is possible: The library honors py/repr directives that are capable of invoking eval-like behavior during object reconstruction, effectively treating serialized data as executable Python expressions.

Why this happens

The root cause is the combination of:

  • Treating serialized JSON as a transport for executable Python object representations (py/repr), and
  • Using evaluation semantics during deserialization without enforcing strict trust boundaries.

This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection'), where user-controllable data is used to construct or execute code.

Instead of confining deserialization to simple, inert data structures (strings, numbers, lists, dicts), the deserializer can interpret py/repr objects in ways that invoke code execution primitives. When these features are applied to untrusted input, an attacker can craft payloads that cause arbitrary Python or OS commands to run when the JSON is decoded.

Potential impact

  • Execution of arbitrary Python code within the vulnerable application process.
  • Execution of system commands with the privileges of the application runtime user.
  • Full compromise of the affected service, including data theft or destruction.
  • Pivoting to other internal systems reachable from the compromised host.
  • Deployment of malware, cryptominers, or backdoors in the application environment.
  • Tampering with business logic, logs, or security controls enforced by the application.

General mitigation guidance

Mitigation typically focuses on eliminating executable semantics from deserialization and narrowing trust boundaries around JSON handling:

  • Prefer plain JSON libraries (e.g., the standard json module) or other serializers that do not support executable object representations when handling untrusted input.
  • Restrict or disable advanced features such as py/repr and any mechanisms that allow reconstruction of arbitrary Python objects from JSON.
  • Introduce clear trust boundaries: treat all external JSON as untrusted and map it into simple, validated data-transfer objects rather than recreating arbitrary Python objects.
  • Apply strict schema validation to incoming JSON before any deserialization into complex object graphs (e.g., using JSON Schema or equivalent validation layers).
  • Run deserialization in processes or containers operating under least privilege, so that a potential compromise yields minimal access.
  • Apply defense-in-depth controls such as mandatory input validation layers and secure coding guidelines that prohibit code-evaluating patterns during deserialization.

How teams detect issues like this

Detection typically combines code-level inspection with runtime monitoring:

  • Static analysis: Configure SAST tools and linters to flag usage of jsonpickle.decode (or equivalent APIs) on data that may be controlled by external users, especially when py/repr support is enabled.
  • Code review: During manual reviews, look for:
  • Direct or indirect deserialization of request bodies, headers, cookies, or messages via jsonpickle,
  • Absence of type whitelisting, schema checks, or data sanitization before decoding,
  • Patterns that reconstruct arbitrary objects rather than mapping into well-defined DTOs.
  • Policy enforcement: Introduce coding standards that:
  • Disallow executable deserialization in user-facing components,
  • Require justification and additional safeguards when object reconstruction is truly necessary.
  • Runtime monitoring: Use application logging and security monitoring to track unexpected object types or error patterns during deserialization, and watch for anomalous subprocess creation or command execution around decode operations.
  • Automated review tools and CI checks can be configured to detect use of dangerous deserialization features and block merges that violate secure serialization policies.

Sources

SourceLink
github.comgithub.com/jsonpickle/jsonpickle
jsonpickle.github.iojsonpickle.github.io
exploit-db.comexploit-db.com/exploits/49585
vulncheck.comvulncheck.com/advisories/python-jsonpickle-remote-code-execution-via-py-repr
access.redhat.comaccess.redhat.com/security/cve/CVE-2021-47952
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2478170
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2021/cve-2021-47952.json

Frequently asked

questions

Yes. If an attacker can send JSON data that is deserialized by python-jsonpickle (for example, via a web API or message queue), they can often exploit this issue remotely without local access.

The attacker needs the ability to control or significantly influence the JSON payload that is passed to jsonpickle.decode or similar APIs. No prior authentication is required if the deserialization occurs before or outside of authentication checks.

The safest pattern is to stop using executable deserialization for untrusted data. Use standard JSON parsing into simple data structures, perform strict validation, and then map validated data into application objects. Avoid any deserialization modes that reconstruct arbitrary Python objects or interpret py/repr-style constructs.

Establish a policy that untrusted input must never drive code execution or object reconstruction with executable behavior. Prefer data-only serialization formats, enforce schema validation, prohibit use of eval-like mechanisms in deserialization code, and integrate static analysis plus code review checklists to flag risky serialization APIs before they reach production.

Find out what's already
exploitable in your codebase.