Skip to main content

SKY-D233 · Security in code

Unsafe deserialization

CriticalCWE-502

Python marshal, jsonpickle and dill calls are CRITICAL and shelve.open() is HIGH. Java XMLDecoder and C# BinaryFormatter-style formatters are CRITICAL with request data and HIGH otherwise. Java XStream, SnakeYAML and Jackson settings, and Json.NET TypeNameHandling, range from MEDIUM to CRITICAL depending on the setting and whether request data is read. TypeScript/JavaScript node-serialize-style loaders are CRITICAL with request data and HIGH otherwise; js-yaml 3 load of request data is HIGH.

Deserialization turns stored bytes or text back into objects. Some formats can name any class or function to call while they load, so loading them runs code. SKY-D233 reports such loaders beyond pickle (which has its own rules): marshal, shelve, jsonpickle and dill in Python, and their equivalents in Java, Kotlin and C#. Rust also checks for unbounded JSON input decoded into a growable vector.

Languages
Python, Java, Kotlin, C#, TypeScript/JavaScript, Rust
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). HIGH and MEDIUM findings, such as shelve.open(), are only counted.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

If an attacker can change the data, for example a cookie, an upload or a cache entry, a crafted payload runs a command on the server the moment it is loaded. The Rust finding concerns memory exhaustion when an application accepts an unbounded sequence.

What Skylos flags

app/cart.py · PythonReported on line 10
import jsonpickle from flask import Flask, request app = Flask(__name__)  @app.get("/cart")def show_cart():    cart = jsonpickle.decode(request.cookies.get("cart", "[]"))    return {"items": len(cart)}

What Skylos leaves alone

app/cart.py · Python
import json from flask import Flask, request app = Flask(__name__)  @app.get("/cart")def show_cart():    cart = json.loads(request.cookies.get("cart", "[]"))    return {"items": len(cart)}

Why Skylos leaves it alone

json.loads() only builds dicts, lists, strings, numbers and booleans. It cannot create objects of other classes or call functions, so it is not a code-running loader.

More languages

Java

Flagged

src/main/java/com/example/SettingsController.java · JavaReported on line 14
package com.example; import java.beans.XMLDecoder;import java.io.IOException;import javax.servlet.http.HttpServletRequest;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class SettingsController {     @PostMapping("/settings/import")    public String importSettings(HttpServletRequest request) throws IOException {        XMLDecoder decoder = new XMLDecoder(request.getInputStream());        Object settings = decoder.readObject();        decoder.close();        return String.valueOf(settings);    }}

Not flagged

src/main/java/com/example/SettingsController.java · Java
package com.example; import com.fasterxml.jackson.databind.ObjectMapper;import java.io.IOException;import javax.servlet.http.HttpServletRequest;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class SettingsController {    private final ObjectMapper mapper = new ObjectMapper();     @PostMapping("/settings/import")    public String importSettings(HttpServletRequest request) throws IOException {        Settings settings = mapper.readValue(request.getInputStream(), Settings.class);        return settings.theme();    }     public record Settings(String theme, int pageSize) {}}

Why Skylos leaves it alone

Jackson reads the body into the one fixed Settings class. Without default typing or @JsonTypeInfo(use = Id.CLASS), the data cannot choose which class is created.

How Skylos decides

  1. In Rust this is a MEDIUM resource-use finding. Skylos checks when serde_json::from_reader reads a Vec from a TCP stream, or when from_slice or from_str parses a buffer immediately after an unlimited read_to_end or read_to_string. A bounded reader such as stream.take(limit) stays quiet.
  2. In Python, resolves each call's name through imports and aliases and matches it against a fixed table: marshal.load(), marshal.loads(), jsonpickle.decode(), dill.load(), dill.loads() and dill.Unpickler(...).load() are CRITICAL; shelve.open() is HIGH.
  3. Reports every matching call, whatever its argument. These formats can run code whenever the data is not your own, so the rule asks for a review of where the data comes from.
  4. Java and Kotlin: new XMLDecoder(...) on anything but a string literal (CRITICAL when request or socket data is read), XStream fromXML with missing or permissive type permissions, SnakeYAML load without SafeConstructor, Jackson default typing or @JsonTypeInfo(use = Id.CLASS), and Kryo with registration turned off.
  5. C#: BinaryFormatter, SoapFormatter, NetDataContractSerializer, LosFormatter and ObjectStateFormatter deserialization, Json.NET TypeNameHandling other than None, and JavaScriptSerializer with a SimpleTypeResolver. pickle itself is reported as SKY-D204 and SKY-D205.
  6. In TypeScript and JavaScript, reports node-serialize unserialize, serialize-to-js deserialize and funcster deepDeserialize of a non-literal value (HIGH, CRITICAL with request data), and js-yaml load/loadAll of request data when package.json declares js-yaml below 4, whose default schema runs !!js/function (HIGH).

How to fix it

Store and exchange data in a format that cannot create arbitrary objects, such as JSON, and check its shape after loading. When you must keep an object format, sign the data with a secret key and check the signature before loading it.

app/cart.py · Python · the fix, against the flagged file
Removed: import jsonpickleAdded: import json from flask import Flask, request app = Flask(__name__)  @app.get("/cart")def show_cart():Removed:     cart = jsonpickle.decode(request.cookies.get("cart", "[]"))Added:     cart = json.loads(request.cookies.get("cart", "[]"))Added:     if not isinstance(cart, list):Added:         cart = []    return {"items": len(cart)}

When it can be wrong

  • A Python call that only reads a file your own build wrote, such as a shelve cache in the app's data folder, is still reported. The rule does not follow where the data comes from.
  • marshal.loads() used on compiled code your own tool produced is reported the same way as one used on network data.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed call and say why the data is trusted. A bare # noqa does not hide HIGH or CRITICAL security findings.

    Python
    cart = jsonpickle.decode(blob)  # skylos: ignore[SKY-D233] blob is signed
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D233"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.