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/repror 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/reprdirectives that are capable of invokingeval-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
jsonmodule) or other serializers that do not support executable object representations when handling untrusted input. - Restrict or disable advanced features such as
py/reprand 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 whenpy/reprsupport 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.

