Security · 3 min read · 796 words

Insecure Deserialization: When Bytes Become Code

By Chris Clark · AppSec practitioner & AWS Solutions Architect

Disclosure: Some links in this article are affiliate links. We may earn a commission at no extra cost to you if you purchase through them.

Insecure Deserialization in Plain English: When Bytes Become Code

Insecure deserialization is not a niche CVE flavor. It is what happens when your app rebuilds objects from bytes it should not trust.

Serialization turns a live object into a stream—file, cookie, HTTP body, queue message. Deserialization does the reverse: reads those bytes and constructs objects again. Native Java serialization (ObjectOutputStream out, ObjectInputStream.readObject() in) does more than restore field values. It can run constructor logic, custom readObject methods, and class-loading decisions while the stream is still being read. If an attacker controls the stream, that machinery becomes their interpreter.

OWASP maps this under A08:2025 Software or Data Integrity Failures. The integrity failure is simple: you treated attacker-shaped bytes as a trusted object graph. Impacts range from denial of service to privilege abuse to remote code execution, depending on what classes are on the classpath.

What "gadget" means without the jargon

You do not need a zero-day in ObjectInputStream for this to bite. Researchers chain ordinary classes already on your classpath—"gadgets"—whose readObject, readResolve, or related magic methods do something powerful with field values the attacker chose. The cast after readObject() does not help: by the time you write (AcmeObject) ois.readObject(), the dangerous work may already have run.

Java streams leave fingerprints if you know where to look. The OWASP Deserialization Cheat Sheet calls out hex magic AC ED 00 05, Base64 that starts with rO0, and Content-Type: application/x-java-serialized-object. Those are hunting signals for leftover remoting, session blobs, or "temporary" binary APIs—not proof by themselves, but enough to start a code search.

Filters help; they are not on by default

JDK 9+ shipped serialization filtering (JEP 290). You can set a JVM-wide pattern filter with jdk.serialFilter, or attach a stream-specific ObjectInputFilter before you read. Filters can allow or reject classes and packages, cap array length, graph depth, reference count, and stream size.

The trap: a serialization filter is not enabled by default. No property, no ObjectInputFilter on the stream means no filtering. An allowlist (only the classes you expect) is safer than a denylist of yesterday's gadgets.

Spring Boot and Angular: where this actually lives

This bug is almost always server-side Java. Your Angular SPA does not deserialize ObjectInputStream. What the SPA does change is which old server paths stay reachable.

In a Java 8 monolith being strangled toward Spring Boot APIs plus Angular, the risky leftovers look like:

Spring Framework's own Javadoc for HttpInvokerServiceExporter (deprecated as of 5.3) warns explicitly: manipulated input streams can lead to unwanted code execution during deserialization; do not expose HTTP invoker endpoints to untrusted clients; prefer JSON. That is the product truth for strangler work—replace the binary remoting edge with a JSON/REST contract when you cut a section over.

Jackson, XStream, SnakeYAML have their own footguns when type metadata lets the payload pick the class. JSON over the wire is still the right direction; turn off "deserialize any @type" features and keep DTOs boring.

What to do in a Java / Spring / Angular / GitLab CI shop

  • Prefer not to deserialize untrusted native Java streams. Replace section-by-section with Spring Boot controllers that accept JSON DTOs. Strangler replacement removes attack surface; an in-place JDK bump does not.
  • Inventory sinks before you "harden later." Search for ObjectInputStream, readObject, readUnshared, HTTP Invoker exporters, and queue consumers. Treat every hit as a ticket with an owner.
  • If a binary edge must stay, put an allowlist filter in front of it. Use ObjectInputFilter with an explicit allowlist of expected types plus size/depth limits. Do not ship "filter TBD."
  • Sign or HMAC any serialized blob that still crosses a trust boundary, and reject streams that fail the check before you deserialize.
  • Kill legacy remoting on the cutover checklist. When a monolith slice moves to Spring Boot 3, serialization-based HTTP Invoker is already gone from the framework; do not reintroduce equivalent ObjectInputStream endpoints by hand.
  • Wire detection into GitLab CI. Fail SAST jobs on new ObjectInputStream + untrusted InputStream patterns. Add a smoke test that rejects a truncated rO0 / AC ED probe on any endpoint that used to accept Java serialization.
  • The short version

    Insecure deserialization means your server rebuilt an object graph from bytes an attacker shaped—and Java's native serializer can run code while it does that. Fix it by not accepting untrusted Java-serialized streams: move strangler edges to JSON DTOs, allowlist-filter anything that must remain, drop HTTP Invoker, and keep Angular on boring REST contracts. Filters are seatbelts for the migration window—not a reason to keep binary object graphs on the public edge.

    Tags: insecure deserialization · Java security · code execution · OWASP A08 · application security