agentleFS
ShieldNet-360ShieldNet-360/secure-vibe/skills/deserialization-security/SKILL.md

deserialization-security

Skill22 starsChanged 5 months agoMITView on GitHub

Block unsafe deserialization and unsafe XML parsing in Java, Python, .NET, PHP, and Ruby: gadget chains, unrestricted type resolution, external entity expansion, and safer formats. Use when parsing or deserializing data from an untrusted source, wiring cookies, sessions, queues, or RPC payloads, or reviewing pickle, unserialize, Marshal, ObjectInputStream, BinaryFormatter, or XML parser configuration.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer data-only serialization formats — JSON, Protobuf, MessagePack with an explicit type map — over formats that reconstruct arbitrary …

    line 33
  2. Very specific:

    Treat an object-reconstructing deserializer crossing a trust boundary as high risk: pickle, ObjectInputStream, BinaryFormatter, …

    line 40
  3. Distinctive:

    Treat a type or object-graph filter as a process sandbox.

    line 65

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Deserialization Security

Rules (for AI agents)

ALWAYS

  • Prefer data-only serialization formats — JSON, Protobuf, MessagePack with an explicit type map — over formats that reconstruct arbitrary runtime objects. What makes a format safe here is not schema validation; it is whether the parser can instantiate a class the payload names.
  • Constrain polymorphic type resolution to an explicit set of expected application types. Never let payload data choose the runtime class — that is the mechanism behind every gadget chain, whichever serializer is involved.
  • Treat an object-reconstructing deserializer crossing a trust boundary as high risk: pickle, ObjectInputStream, BinaryFormatter, unserialize, Marshal.load and their framework equivalents. Adding one to a request-handling path needs explicit review — check the platform reference for the exact API and the version behaviour before accepting or remediating a use.
  • Disable external entity resolution and DTD processing on every XML parser that receives untrusted input. A parser that resolves entities is a file-read and server-side request primitive before it is a parser; ssrf-prevention owns where the outbound request lands.
  • Where serialized state carries a signature or MAC, verify it before invoking the deserializer — and treat that as defense in depth, not a licence to keep an unsafe format. crypto-misuse owns the signing key, its algorithm and its rotation.
  • Apply parser and object-graph limits — type filters, graph depth, array length, stream size — as defense in depth. Where legacy native deserialization is unavoidable and execution isolation is genuinely required, isolate at the OS, process or container boundary: a deserializer filter constrains what may be constructed, never what the constructed code may then do.

NEVER

  • Deserialize attacker-controlled or unauthenticated bytes with a native, object-reconstructing format.
  • Assume a MAC, a signature, TLS, or a trusted network makes an unsafe serializer safe. Some serializers cannot be made safe at any level of authentication, and their own vendors say so.
  • Allow unrestricted class-name or type resolution from serialized input.
  • Treat a type or object-graph filter as a process sandbox.
  • Re-enable a serializer the platform vendor classifies as unsafe for compatibility alone. That needs a recorded legacy risk acceptance, strict filtering, a least-privilege execution boundary, and a migration plan — not a false-positive waiver.
  • Copy a framework-specific deserialization example without checking it against the installed library version. Defaults in this area have moved repeatedly, and an example that was correct three releases ago may name an API that no longer exists.

KNOWN FALSE POSITIVES

  • Build-time or configuration-time deserialization of files that ship in the repository — test fixtures, vendored config — provided they are never loaded from a download.
  • A parser that is hardened by its library's current defaults is not a finding merely because an older release of the same library was unsafe. Check the installed version, not the library name.
  • A cryptographically authenticated session format where the MAC genuinely gates the deserializer and the framework's own current default serializer is in use.

Context (for humans)

Object-reconstructing deserialization is the most reliable RCE primitive in modern enterprise stacks. The economics are simple: when a serializer instantiates whatever class the payload names, the application has already loaded thousands of classes, many with side effects in readObject, __reduce__, __wakeup or Read* callbacks. A gadget chain strings those side effects into execution. Mature tooling — ysoserial, ysoserial.net, marshalsec, the pickle gadget catalogs — means "is this exploitable" is almost always "yes, with what is already on the classpath."

The fix is a format that cannot instantiate arbitrary classes, not a better filter. XML belongs in the same skill for the same reason: an entity-resolving parser does more than parse, and the exploit needs no gadget at all.

Two things date fast here and are deliberately kept out of these rules: exact API names and version-dependent defaults. Both have moved repeatedly — safe-by-default constructors, flipped loader defaults, vendor-obsoleted serializers — and a rule that hard-codes them ages into a false positive or, worse, into an API that never existed. The platform references carry them, with the version each statement applies to.

References

  • references/verifying-findings.md — confirm or refute a finding, then lock it
  • references/java.md — ObjectInputStream, Jackson polymorphic typing, SnakeYAML, XStream: current APIs, version gates, safe configuration
  • references/python.md — pickle family, PyYAML loaders, numpy, ML checkpoints
  • references/dotnet.md — BinaryFormatter and its relatives, vendor status
  • references/php-ruby.md — unserialize magic-method chains, Marshal, Psych
  • references/xml.md — per-platform flags to disable DTD and external entities
  • rules/unsafe_deserializers.json — build-time catalogue, not shipped to the agent
  • OWASP Deserialization Cheat Sheet.
  • OWASP XXE Prevention Cheat Sheet.
  • CWE-502 · CWE-611.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.