Quick revision
The short answer
We run it as a programme with three tracks. First we rank every use by exposure, network-reachable endpoints that accept untrusted data first, and apply fast mitigations everywhere: a JVM-wide jdk.serialFilter allow-list delivered through the base images, and JMX and RMI ports restricted to trusted networks with authentication. Then we remove the root causes, switching the cache library to a JSON or binary codec and retiring the RMI tool, while tracking each of the 60 services to closure and adding a CI check that blocks new ObjectInputStream use.
What to remember
In this answer, we planned the remediation as a programme: an inventory ranked by exposure, fast central mitigations through a base-image jdk.serialFilter allow-list and restricted, authenticated JMX and RMI ports, then the root-cause fixes, a JSON or binary cache codec with versioned keys and a retired RMI tool. Each service is tracked to closure on a shared dashboard, and a CI check, dependency scanning and the default filter keep new uses from appearing.
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.
We run it as a programme with three tracks. First we rank every use by exposure, network-reachable endpoints that accept untrusted data first, and apply fast mitigations everywhere: a JVM-wide jdk.serialFilter allow-list delivered through the base images, and JMX and RMI ports restricted to trusted networks with authentication. Then we remove the root causes, switching the cache library to a JSON or binary codec and retiring the RMI tool, while tracking each of the 60 services to closure and adding a CI check that blocks new ObjectInputStream use.
Why this question is asked
A single vulnerable endpoint is a ticket; the same weakness across 60 services owned by many teams is an organisational problem. The technical fixes are known, but the hard part is ordering them, making them cheap for teams to adopt, and making sure every service actually finishes. Interviewers ask this at senior level to see whether we can turn a security finding into a plan with priorities, central leverage and measurable progress. In this answer, we will build the inventory and ranking, apply the fast mitigations centrally, fix each of the three sources, organise the work across teams, and make sure the problem stays fixed.
1Build the Inventory and Rank by Exposure
We cannot prioritise what we have not listed, so the first week is an inventory. For each of the 60 services we record which of the three uses it has, whether the port or endpoint is reachable from the network and from where, whether the data it deserializes can come from an untrusted source, and which gadget-prone libraries are on its class path. Most of this can be gathered automatically: dependency trees from the build, open ports from the deployment manifests, and code search for ObjectInputStream and the cache library's configuration.
Then we rank. The question for each use is how easily an attacker could send it bytes. A JMX or RMI port reachable from the general corporate network is near the top, because anyone with network access can connect. A cache that only reads entries this service wrote itself into a private cluster is lower, since an attacker would first need write access to the cache.
| Tier | Example | Target |
|---|---|---|
| 1: reachable, untrusted input | RMI admin tool or JMX open to the corporate network | contain within days |
| 2: reachable, authenticated | JMX with passwords but no network limits | contain within 2 weeks |
| 3: internal data path | cache entries written by the service itself | codec change within a quarter |
| 4: dormant | library present, feature unused | remove the dependency |
2Apply Fast Mitigations Centrally
Sixty teams changing code takes months, so we look for changes we can make once. The strongest lever is the base container image or the shared JVM launch configuration that every service uses. We add a JVM-wide filter there, starting from an allow-list of JDK classes the three uses really need plus each service's own packages, with limits on depth and array size.
Rolling out a global reject-all blindly would break caches in subtle ways, so we stage it. In a test environment, and then on one canary instance per service, we turn on logging for the java.io.serialization logger to see which classes each service actually deserializes, add them to that service's allow-list, and only then enable the filter everywhere. A service that breaks gets its list fixed, not the filter removed.
The second fast mitigation is the network. JMX and RMI ports should never be open to the general network: we bind them to localhost or a management network, enforce it with security groups or network policies, and turn on authentication and TLS for remote JMX. These are infrastructure changes the platform team can make for every service at once.
3Fix the Three Sources
With the risk contained, we remove the causes, one source at a time. The cache library is the biggest piece of work, because it touches data. Most caching libraries let us plug in a codec, so we configure a JSON codec or a binary codec with a schema instead of Java serialization. The catch is that existing cache entries are in the old format. We handle it by putting a version in the cache name or key prefix so the new code never reads old entries, and letting the old entries expire; for a cache that is cheap to rebuild, we simply flush it during the release.
JMX is usually kept, since operations teams use it for metrics and diagnostics, but restricted: local only, with metrics exported through an HTTP endpoint such as Micrometer with Prometheus instead of remote JMX wherever possible. The old RMI admin tool is retired. We find out what its users actually do with it, rebuild those few operations as authenticated HTTP endpoints with JSON, and switch off the RMI registry on a fixed date.
4Organise the Work Across Teams
Each team gets a short, specific ticket for each of its services, not a general instruction: which use was found, which tier it is in, the exact change to make with a link to a shared example, and a due date that matches the tier. The platform team provides the shared pieces, such as the base image filter, a ready-made JSON codec configuration for the cache library, and the replacement admin endpoints, so that most teams only change configuration.
We track the programme on one dashboard: each service, each use, its status and its owner. A short weekly review with the security team and engineering managers looks at the tier 1 and tier 2 items that are late and removes blockers. With 60 services, a realistic plan might close all tier 1 items in two weeks, tier 2 in a month, and the cache migrations within a quarter.
- Week 1: inventory and rankingautomated scan, owners confirmed
- Weeks 1-2: network containmentJMX and RMI off the general network
- Weeks 2-4: base-image filterlogging first, then enforce per service
- Month 2-3: cache codec migrationversioned keys, old entries expire
- Month 3: retire the RMI toolHTTP replacements, registry switched off
- Ongoing: CI check and scanningno new
ObjectInputStream; gadget libraries flagged
6 steps in order. Play them, or step through them one at a time.
5Keep It Fixed
A remediation that is not guarded will slowly come undone. We add a CI check, for example a Semgrep or ArchUnit rule shared by all builds, that fails when new code creates an ObjectInputStream or registers a Java serialization codec, with a short reviewed exception list. Dependency scanning flags known gadget libraries and deserialization vulnerabilities with patch deadlines. And the base-image filter means any new service starts protected by default.
We measure success by the numbers on the dashboard reaching zero: services with network-reachable JMX or RMI, services without the filter, and caches still using Java serialization. Once they are at zero, the CI check and the base image keep them there.
6Follow-up questions
Why not just remove Java serialization everywhere at once?
Because it would take months of work by every team before any risk was reduced, and it would change cached data and operational tooling all at the same time. Ranking by exposure and applying central mitigations first removes most of the risk in weeks, and the code changes can then happen in a safe order.
What if a team cannot change its cache codec this quarter?
The filter and network controls already reduce the risk, so we record a time-limited exception with an owner and a new date, and keep the item visible on the dashboard. Exceptions are fine; invisible exceptions are not.
How do we avoid the base-image filter breaking production?
We deploy it in logging mode first, collecting the classes each service really deserializes, build the allow-lists from that evidence, then enforce on a canary instance before all instances. A rejected class produces a clear InvalidClassException in the logs, so problems are quick to diagnose.
7Conclusion
In this answer, we planned the remediation as a programme: an inventory ranked by exposure, fast central mitigations through a base-image jdk.serialFilter allow-list and restricted, authenticated JMX and RMI ports, then the root-cause fixes, a JSON or binary cache codec with versioned keys and a retired RMI tool. Each service is tracked to closure on a shared dashboard, and a CI check, dependency scanning and the default filter keep new uses from appearing.
Open with
With 60 services I would run it as a programme rather than 60 separate tickets. First, an inventory, mostly automated from dependency trees, deployment manifests and code search, recording for each service which of the three uses it has, whether it is reachable over the network, and whether the input can be untrusted.
Then, if they want more
Then I rank by exposure: an RMI tool or JMX port open to the corporate network is tier one and gets contained within days, while a cache that only reads its own entries is lower. Second, central mitigations, because they reduce risk for all services at once.
The platform team adds a JVM-wide jdk.serialFilter allow-list through the base images, rolled out with logging first so we learn which classes each service really needs, then enforced on canaries, then everywhere. At the same time, JMX and RMI ports are bound to localhost or a management network and require authentication and TLS.
Third, the real fixes: switch the cache library to a JSON or binary codec, using a versioned key prefix so old entries just expire; export metrics over HTTP instead of remote JMX; and rebuild the few operations of the RMI admin tool as authenticated HTTP endpoints and switch it off.
Each team gets specific tickets with due dates by tier and a shared example, and a dashboard tracks every service to closure. Finally, a CI check blocks new ObjectInputStream use, and dependency scanning watches for gadget libraries.
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
- 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 "A security audit finds Java serialization in a cache library, in JMX remote access and...": https://scrivio-interview-library.netlify.app/java/serialization/307243b05d/