Quick revision
The short answer
The core rule is that Java serialization never carries data across a trust boundary, meaning anywhere the bytes could come from someone we do not fully control. Inside a boundary it is tolerated but guarded: every JVM runs with a base-image jdk.serialFilter that rejects unexpected classes. Around those two rules we inventory the remaining uses in caches, sessions, RMI, JMX and brokers and migrate them to explicit formats, flag new ObjectInputStream and readObject code with static analysis, and keep dependency scanning for known gadget libraries.
What to remember
In this answer, we built an organisation-wide policy around trust boundaries: no Java serialization for data that crosses one, and a JVM-wide jdk.serialFilter in every base image for the uses that remain inside. We inventory caches, sessions, RMI, JMX and brokers and migrate them to explicit formats, flag new ObjectInputStream and readObject use with static analysis, scan for gadget libraries with patch deadlines, and keep the policy alive through time-limited exceptions and numbers reviewed every quarter.
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.
The core rule is that Java serialization never carries data across a trust boundary, meaning anywhere the bytes could come from someone we do not fully control. Inside a boundary it is tolerated but guarded: every JVM runs with a base-image jdk.serialFilter that rejects unexpected classes. Around those two rules we inventory the remaining uses in caches, sessions, RMI, JMX and brokers and migrate them to explicit formats, flag new ObjectInputStream and readObject code with static analysis, and keep dependency scanning for known gadget libraries.
Why this question is asked
A policy that simply says never use Java serialization sounds strong, but it fails on day one, because session replication, some caches and parts of the JDK's own management tooling still rely on it. A policy that people cannot follow gets ignored, and then it protects nothing. Interviewers ask this question to see whether we can write rules that are both safe and realistic, and how we make them stick. In this answer, we will define the trust boundary that the policy is built on, go through each rule and why it exists, describe how exceptions work, and show how tooling enforces the policy without relying on people's memory.
1The Idea the Policy Is Built On: Trust Boundaries
A trust boundary is any point where data enters our system from a source we do not fully control. A public API is obviously one, but so are internal endpoints reachable from the corporate network, message topics that several teams can write to, files uploaded by users, and a cache cluster that many services share. The danger of Java serialization is that the bytes choose which classes to instantiate and run their readObject methods, so whoever controls the bytes may control code execution. Inside a boundary, such as a session store written and read only by one application's own nodes on a private network, an attacker first has to break in somewhere else.
So the policy draws its main line there. It does not ban a technology outright; it bans it in the place where it is dangerous, and it requires protection everywhere else.
| Rule | Applies to | Enforced by |
|---|---|---|
| No Java serialization across a trust boundary | APIs, shared topics, uploads, shared caches | design review, CI rule |
JVM-wide jdk.serialFilter in every base image | every Java service | base image, startup check |
| Inventory and migrate remaining uses | caches, sessions, RMI, JMX, brokers | tracked programme |
Flag new ObjectInputStream and readObject | all new code | static analysis in CI |
| Scan for gadget libraries and upgrade | all dependencies | dependency scanner with deadlines |
2Rule 1: Ban Java Serialization Across Trust Boundaries
Any data that crosses a trust boundary must use an explicit, schema-based or well-defined format such as JSON mapped to fixed types, Protobuf or Avro. This covers HTTP and gRPC APIs, message payloads on topics other teams can write to, files, and any store several services share. The reason is simple: with these formats the data cannot choose which classes the reader builds, so the whole family of deserialization attacks does not apply.
The rule also covers the same risk in other forms. A JSON library with polymorphic default typing that reads class names from the data, or a YAML loader that can create arbitrary objects, is treated like Java serialization and needs the same allow-list approach.
3Rule 2: A JVM-Wide Filter in Every Base Image
For the uses that remain inside boundaries, every JVM starts with a deserialization filter set through the jdk.serialFilter property in the shared base image. It allows the JDK classes commonly needed, lets each service add its own packages through configuration, sets limits on depth and array size, and ends with a reject-all. Because it is in the base image, a new service is protected without anyone remembering to do anything.
Since Java 17, a filter factory can also combine this JVM-wide filter with any filter a library sets on its own streams, so a library can make the rules stricter but never looser. The platform team owns the base filter and its allow-list, and a startup check fails the deployment if the property is missing.
4Rule 3: Inventory the Remaining Uses and Migrate Them
Java serialization hides in places teams do not think of as serialization. Distributed caches often use it as their default codec; servlet session replication and session stores use it for attributes; RMI-based tools and remote JMX use it on the wire; JMS ObjectMessage puts serialized objects on a broker. The policy requires each team to list these uses in a shared inventory, with an owner and a target date, and to migrate them to explicit formats: a JSON or schema-based codec for caches, small JSON sessions, HTTP endpoints instead of RMI, metrics over HTTP instead of remote JMX, and text or schema-based message bodies.
We do not demand that all of this happens at once. Uses that sit inside a boundary and are already protected by the filter can migrate on a normal schedule, while anything exposed moves first.
5Rules 4 and 5: Static Analysis and Dependency Scanning
People forget policies; build pipelines do not. A shared static analysis rule, for example in Semgrep or Error Prone, flags new uses of ObjectInputStream, readObject and Java-serialization codecs in every repository. It does not have to block every case, since a reviewed exception list can allow known, protected uses, but a new use must be a conscious decision with a reviewer from the security group.
Finally, dependency scanning watches for libraries with known gadget chains and for deserialization vulnerabilities, with patch deadlines by severity, for example critical issues within seven days. Upgrading these libraries does not make Java serialization safe, but it removes the easiest chains while migrations are in progress.
6Exceptions and How the Policy Stays Alive
Some uses will need an exception, such as a third-party product that only speaks RMI. An exception is granted for a named use, with compensating controls such as network isolation and a strict filter, an owner, and an expiry date, after which it must be reviewed again. Exceptions are visible in the same inventory, so nobody is surprised by them later.
We measure the policy by numbers that should fall to zero or stay there: uses across trust boundaries, services without the base filter, open exceptions past their date, and gadget libraries past their patch deadline. Reviewing those numbers every quarter is what turns a document into a working policy.
7Follow-up questions
Is session replication allowed under this policy?
Yes, if it stays inside a trust boundary: the session store or replication channel is private to one application, the nodes run with the JVM-wide filter, and the session classes are on the allow-list. We still encourage moving sessions to small JSON payloads in an external store, because it also fixes the version problems that serialized sessions cause during rolling deployments.
Why not ban ObjectInputStream outright in CI?
Because some legitimate uses remain, inside the JDK, in frameworks and in protected internal paths, and a rule with no exceptions gets disabled. Flagging every new use and requiring a reviewed exception keeps the decision visible without stopping work.
Who owns the policy?
The security team owns the rules and reviews exceptions, and the platform team owns the tooling: base images, the filter, the CI rule and the scanner. Each product team owns its own inventory entries and migrations.
8Conclusion
In this answer, we built an organisation-wide policy around trust boundaries: no Java serialization for data that crosses one, and a JVM-wide jdk.serialFilter in every base image for the uses that remain inside. We inventory caches, sessions, RMI, JMX and brokers and migrate them to explicit formats, flag new ObjectInputStream and readObject use with static analysis, scan for gadget libraries with patch deadlines, and keep the policy alive through time-limited exceptions and numbers reviewed every quarter.
Open with
I would build the policy around trust boundaries rather than a blanket ban, because a ban that sessions, caches and the JDK itself cannot follow just gets ignored.
Then, if they want more
Rule one: Java serialization never carries data across a trust boundary, which means public and internal APIs, topics other teams can write to, uploaded files and shared stores. Those use JSON mapped to fixed types, Protobuf or Avro, and I treat polymorphic JSON typing or unsafe YAML loading the same way.
Rule two: every JVM starts with a jdk.serialFilter allow-list set in the shared base image, with limits and a final reject-all, so remaining internal uses are protected by default and new services get it for free.
Rule three: each team inventories its remaining uses, like cache codecs, session replication, RMI tools, remote JMX and JMS ObjectMessage, with an owner and a date, and migrates them to explicit formats, exposed uses first. Rule four: a shared static analysis rule in CI flags any new ObjectInputStream, readObject or serialization codec, and it needs a reviewed exception to merge.
Rule five: dependency scanning for known gadget libraries and deserialization CVEs with patch deadlines. Exceptions are allowed but time-limited, with compensating controls like network isolation. And I would track a few numbers every quarter, such as uses across boundaries and services without the filter, to show the policy is working.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 17
- 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
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "What organisation-wide policy would you set on Java serialization, given that some...": https://scrivio-interview-library.netlify.app/java/serialization/4b6cea8666/