Quick revision
The short answer
Yes, I would run the programme, because every place that reads Java serialized data is a potential remote code execution path that we keep paying for with emergency patching. We start with an inventory of every use, including those hidden inside libraries and frameworks, prioritise the paths reachable by untrusted input, and replace them with explicit data formats such as JSON, Protobuf or Avro mapped to known types. Where removal takes time, ObjectInputFilter allowlists reduce the risk, and static analysis rules block new uses while we track the programme to zero.
What to remember
In this answer, we saw why removing Java native serialization deserves a funded programme: every remaining use is a potential code execution path and an operational burden. We inventory all uses through code search, runtime report-only filters and team knowledge, prioritise those reachable by untrusted input, replace them with JSON, Protobuf or Avro mapped to known types, protect what remains with ObjectInputFilter allowlists, and block new uses with static analysis while tracking the register to completion.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Yes, I would run the programme, because every place that reads Java serialized data is a potential remote code execution path that we keep paying for with emergency patching. We start with an inventory of every use, including those hidden inside libraries and frameworks, prioritise the paths reachable by untrusted input, and replace them with explicit data formats such as JSON, Protobuf or Avro mapped to known types. Where removal takes time, ObjectInputFilter allowlists reduce the risk, and static analysis rules block new uses while we track the programme to zero.
Why this question is asked
Java native serialization is easy to adopt and hard to leave. It sneaks in through a cache client's default serializer, an HTTP session store, an old RMI-style integration or a message converter, and years later nobody remembers it is there. Then a gadget chain is published for a library on the classpath and every one of those paths becomes urgent. Interviewers ask this leadership question to see whether we can justify a multi-quarter clean-up to the business and run it to completion rather than leaving it at 70 percent. In this answer, we will look at whether the programme is worth it, how to build the inventory, how to prioritise, what to replace serialization with, how to reduce risk in the meantime, and how to stop new uses and finish.
1Is It Worth a Programme?
A quick reminder of the risk: when ObjectInputStream reads bytes, it creates whatever classes the bytes name and runs their deserialization methods, so anyone who controls the bytes can chain library classes into code execution. Each new gadget chain or library CVE turns every place that reads serialized data into an emergency.
So the business case is the cost of those emergencies, plus the less visible costs: serialized objects tie caches and sessions to exact class versions, so a field change breaks rolling deploys, and the format cannot be read by services in other languages. Against that, the cost is engineering time to migrate. I would present it as a risk reduction with a clear end state: no Java native deserialization of data that crosses a trust boundary within, say, four quarters, and none at all within two years. Even the Java architects have called serialization a mistake and are working on alternatives, which helps the argument.
2Building the Inventory
We cannot remove what we have not found. The obvious places are code calling ObjectInputStream or ObjectOutputStream directly, but most uses hide in configuration: a Redis or Memcached client using a JDK serializer by default, Spring Session storing session attributes with JdkSerializationRedisSerializer, JMS ObjectMessage, Hazelcast or Ehcache entries, RMI or older remoting such as HTTP invoker, and libraries that use serialization for deep copies.
We combine three sources. Static search across all repositories for the classes and configuration names. Runtime evidence, because a JVM-wide filter in log-only style can report every class deserialized in production without blocking it; a filter that returns UNDECIDED and logs is a good way to collect that. And team knowledge, captured in a simple register with an owner per use.
After a week of this in production, the logs tell us which classes really flow through each service, which is exactly what we need to write allowlists later and to confirm that a migrated path has really stopped using serialization.
3Prioritising by Trust Boundary
Not all uses carry the same risk. The top priority is any path where bytes can come from outside our control: an HTTP endpoint or a message queue fed by partners, a session cookie or session store written from request data, or an RMI port reachable on the network. Next are shared infrastructure such as caches that many services write to, because one compromised writer can attack every reader. Last are purely internal uses inside one process, such as deep copies.
This ranking lets us show early progress where it matters most. Removing ten untrusted paths in the first quarter is worth more than removing a hundred internal deep copies.
| Use | Risk | Replacement |
|---|---|---|
| HTTP or RMI endpoint reading objects | Highest: untrusted bytes | REST or gRPC with JSON or Protobuf DTOs |
| Session store with JDK serializer | High: data from requests | JSON session serializer, small session data |
| Shared cache values | Medium: one writer attacks all readers | JSON or Protobuf cache serializers |
JMS ObjectMessage | Medium to high | TextMessage or bytes with a schema |
| Deep copy via serialization | Low: in-process | Copy constructors or mapping code |
4Replacing Serialization With Explicit Formats
The replacement is always the same idea: data formats that describe values, not classes, mapped onto types we choose. JSON with Jackson is the easiest step for most Spring services; Protobuf or Avro add a schema, which brings compact payloads and safe evolution rules for events and high-volume caches. The receiving code decides the target type, so an attacker can only send bad values, which validation catches.
Migration of stored data needs care. For a cache, we can switch the serializer and accept a cold cache, or write new entries under a new key prefix and let old ones expire. For session stores, we run both readers during the change so users are not logged out. Spring Data Redis makes the switch a configuration change in many cases.
Notice that we use a serializer bound to a specific class rather than one that writes class names into the JSON. A generic serializer with default typing would bring the same problem back in a different format; if one is needed, it must use a strict PolymorphicTypeValidator. Check your Spring Data Redis version for the exact serializer class names, which have changed across releases.
5Reducing Risk Until Removal Is Done
Some uses will take quarters to remove, such as an integration with a partner that will not change its protocol this year. For those we apply ObjectInputFilter allowlists, built from the classes we saw in the report-only logs, ending with !* so anything else is rejected, plus limits on depth and size. We also narrow network access, so an RMI port is reachable only from the one partner address that needs it.
6Blocking New Uses and Finishing
A clean-up without a barrier refills itself. We add static analysis rules that fail the build on new uses of ObjectInputStream, JDK serializers in cache and session configuration, and ObjectMessage, with a short exception process for the rare justified case. The platform starters default to JSON serializers so new services never start with the old default.
Then we track the register to zero: number of uses by risk tier, removed per month, and remaining with owners and dates. A programme that shows "untrusted paths: 14 -> 0, internal: 62 -> 9" on one page keeps leadership support, and the last 10 percent gets dedicated time instead of being left to good intentions.
7Follow-up questions
Would you turn on a JVM-wide filter that rejects everything?
Not as a first step, because some internal uses would break in production. I would first run a report-only filter to learn which classes flow through each service, then enforce allowlists service by service. A global reject-all filter is the end state once the register shows no remaining uses.
Is Protobuf always better than JSON for the replacement?
No. JSON is simpler to debug and good enough for most caches and APIs. Protobuf or Avro pay off when payloads are large or frequent, or when many teams consume the same events and need schema rules for evolution. The security benefit is the same: values mapped to known types.
8Conclusion
In this answer, we saw why removing Java native serialization deserves a funded programme: every remaining use is a potential code execution path and an operational burden. We inventory all uses through code search, runtime report-only filters and team knowledge, prioritise those reachable by untrusted input, replace them with JSON, Protobuf or Avro mapped to known types, protect what remains with ObjectInputFilter allowlists, and block new uses with static analysis while tracking the register to completion.
Open with
Yes, I would run it, and I would sell it as removing a whole class of emergencies. Every place that reads Java serialized data is a potential remote code execution path whenever a new gadget chain appears, and serialized objects also make rolling deploys fragile because they are tied to class versions.
Then, if they want more
The first step is an inventory. Code search finds ObjectInputStream, but most uses hide in configuration, like a JDK serializer in Redis, Spring Session or JMS ObjectMessage. So I also install a report-only ObjectInputFilter that logs every deserialized class in production and returns UNDECIDED, and I keep a register with an owner per use.
Then I prioritise by trust boundary: endpoints, sessions and queues that take outside input first, shared caches next, in-process deep copies last. The replacement is JSON with Jackson for most cases, or Protobuf or Avro with schemas for high-volume events, always mapped to a known type, never with class names in the data.
For caches we switch serializers with a new key prefix, and for sessions we read both formats during the change. Where removal takes longer, like a partner integration, I apply allowlist filters ending with reject-all and limit network access. To stop it coming back, static analysis fails the build on new uses, and platform starters default to JSON.
I report the register every month, untrusted paths down to zero first, and keep dedicated time for the last few.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- OWASP Top Ten
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Java native serialization has been the root of many critical vulnerabilities. Your...": https://scrivio-interview-library.netlify.app/spring-boot/web-security-threats/3dd7d0be9b/