Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-LANG-SEC-042 --project .About This Rule
Understanding the vulnerability and how it is detected
jsonpickle is a Python library that extends JSON serialization to support arbitrary Python objects by encoding type information and object state in JSON format. During deserialization, jsonpickle.decode() uses the type information embedded in the JSON to reconstruct Python objects, which involves calling __new__() and __setstate__() or __reduce__() on the reconstructed types.
This means that jsonpickle.decode() can instantiate arbitrary Python classes and execute their initialization code, making it equivalent to pickle deserialization in terms of security risk. An attacker who can control the JSON input can craft a payload that calls os.system() or other dangerous functions during the decode() call.
For data interchange with untrusted parties, use standard json.loads() which only produces Python built-in types (dict, list, str, int, float, bool, None).
Security Implications
Potential attack scenarios if this vulnerability is exploited
Arbitrary Class Instantiation
jsonpickle encodes Python type information as {"py/object": "os.system"} or similar structures. During decode(), these types are imported and instantiated. An attacker crafts JSON that triggers instantiation of dangerous classes with malicious arguments.
JSON Format Disguise
jsonpickle data looks like valid JSON, which may bypass security controls that check content type or basic JSON validity. The malicious payload is hidden within the structural JSON that appears benign to casual inspection.
API Endpoint Exploitation
REST APIs that use jsonpickle to deserialize request bodies or parameters are directly exploitable. Any endpoint accepting application/json content that is decoded with jsonpickle is a remote code execution vector.
Cache and Storage Poisoning
Applications storing jsonpickle-serialized objects in Redis, databases, or message queues are vulnerable if an attacker can inject data into those stores, as the deserialization will execute the embedded code when the value is read.
How to Fix
Recommended remediation steps
- 1Replace jsonpickle.decode() with json.loads() for all data received from external sources, including API requests, file uploads, and message queue payloads.
- 2Use pydantic or marshmallow for typed deserialization with validation when structured Python objects are needed from external data.
- 3If jsonpickle is used for internal serialization between trusted components, ensure the serialized data never flows back from external sources.
- 4Audit all jsonpickle usage in API handlers, webhook processors, and data import functions.
- 5Consider migrating from jsonpickle to a schema-defined format (Protocol Buffers, Avro) for internal object serialization.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to jsonpickle.decode() and jsonpickle.loads() in Python source code. All call sites are flagged since jsonpickle deserialization is inherently dangerous with any input that could be attacker-influenced.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Pickle Deserialization of Untrusted Data
pickle.loads() and pickle.load() execute arbitrary Python code during deserialization. Never unpickle data from untrusted sources.
PyYAML Unsafe Load Function
yaml.load() and yaml.unsafe_load() can execute arbitrary Python objects during YAML parsing. Use yaml.safe_load() instead.
ruamel.yaml Unsafe Loader Configuration
ruamel.yaml configured with typ='unsafe' can instantiate arbitrary Python objects during YAML parsing. Use typ='safe' or the default round-trip loader.
Frequently Asked Questions
Common questions about jsonpickle Deserialization Detected
New feature
Get these findings posted directly on your GitHub pull requests
The jsonpickle Deserialization Detected rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.