SKY-D233 · Security in code
Unsafe deserialization
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
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
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
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
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
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
- In Rust this is a MEDIUM resource-use finding. Skylos checks when
serde_json::from_readerreads aVecfrom a TCP stream, or whenfrom_sliceorfrom_strparses a buffer immediately after an unlimitedread_to_endorread_to_string. A bounded reader such asstream.take(limit)stays quiet. - 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()anddill.Unpickler(...).load()are CRITICAL;shelve.open()is HIGH. - 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.
- Java and Kotlin:
new XMLDecoder(...)on anything but a string literal (CRITICAL when request or socket data is read), XStreamfromXMLwith missing or permissive type permissions, SnakeYAMLloadwithoutSafeConstructor, Jackson default typing or@JsonTypeInfo(use = Id.CLASS), and Kryo with registration turned off. - C#:
BinaryFormatter,SoapFormatter,NetDataContractSerializer,LosFormatterandObjectStateFormatterdeserialization, Json.NETTypeNameHandlingother thanNone, andJavaScriptSerializerwith aSimpleTypeResolver.pickleitself is reported as SKY-D204 and SKY-D205. - In TypeScript and JavaScript, reports
node-serializeunserialize,serialize-to-jsdeserializeandfuncsterdeepDeserializeof a non-literal value (HIGH, CRITICAL with request data), and js-yamlload/loadAllof request data whenpackage.jsondeclares 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.
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
shelvecache 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
# noqadoes not hide HIGH or CRITICAL security findings.Python cart = jsonpickle.decode(blob) # skylos: ignore[SKY-D233] blob is signedAccept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D233"]turns the rule off for the whole project.