Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A security scan reports that an internal admin service accepts Java serialized objects over HTTP. What steps do you take, in order?

We treat the finding as a possible remote code execution and first cut the endpoint's network exposure so only trusted callers can reach it, while checking logs for signs it was already abused. Next we add a strict allow-list deserialization filter as a short-term mitigation, then replace Java serialization on the endpoint with JSON or another schema-based format. Finally we look for the same pattern elsewhere, in remoting, JMX, RMI and caching libraries, and add a rule that blocks new ObjectInputStream use on untrusted input.

Why this question is asked

Security findings arrive with a severity label, but the order in which we respond decides how much damage is possible in the meantime. An endpoint that accepts Java serialized objects is a classic critical finding, because with the right library on the class path, one HTTP request can run commands on the server. Interviewers ask this scenario to see whether we can prioritise: contain first, mitigate quickly, fix properly, then make sure it cannot come back. In this answer, we will walk through each step in order, explain why it comes where it does, and show the code and configuration for the mitigation and the fix.

1Why This Finding Is Serious

When an endpoint reads its request body with ObjectInputStream, the bytes decide which classes are instantiated, and the readObject methods of those classes run before our code sees the result. If any library on the service's class path contains a gadget chain, an attacker who can reach the endpoint can run code with the service's permissions. Admin services usually have the most permissions of all, such as database credentials, access to other services, or the ability to change configuration. So the starting assumption is the worst case: this is a potential remote code execution until proven otherwise.

Being internal is not much comfort. Internal networks are reached through compromised laptops, through other vulnerable services, or through request forgery from a browser inside the network. We take the finding seriously even if the service has never been exposed to the internet.

Step throughResponding to the finding, in order
  1. Containrestrict network access; check logs for abuse
  2. Mitigatestrict allow-list deserialization filter
  3. Fixreplace Java serialization with JSON or Protobuf
  4. Searchremoting, JMX, RMI, caches in this and other services
  5. PreventCI rule against new ObjectInputStream on untrusted input

5 steps in order. Play them, or step through them one at a time.

Each step reduces risk while the slower steps are under way.

2Contain the Exposure and Look for Abuse

The first action takes minutes and needs no code change: limit who can reach the endpoint. We restrict it at the network layer with firewall rules, security groups or the ingress configuration so that only the specific admin hosts or a VPN range can connect, and if possible we require mutual TLS or strong authentication in front of it. If nobody actually uses the endpoint, we disable it.

In parallel we check whether it has been abused. We look at access logs for requests to the endpoint from unexpected sources, at the service's process list and outbound connections for unusual activity, and at the deployed dependencies for known gadget libraries. If there are signs of exploitation, this becomes an incident with its own process, including rotating the credentials the service holds.

3Add a Strict Allow-List Filter

The proper fix takes a release or two, so we add a deserialization filter now. We find exactly which classes the endpoint legitimately receives, often a handful of DTOs and a few JDK collections, and allow only those, with limits on graph size.

Java
private static final ObjectInputFilter ADMIN_FILTER = ObjectInputFilter.Config.createFilter(
"maxdepth=8;maxarray=5000;maxrefs=2000;maxbytes=262144;"
+ "com.acme.admin.api.*;java.util.ArrayList;java.util.HashMap;java.lang.*;!*");
@PostMapping(value = "/admin/jobs", consumes = "application/x-java-serialized-object")
public void submit(InputStream body) throws Exception {
try (var in = new ObjectInputStream(body)) {
in.setObjectInputFilter(ADMIN_FILTER); // rejects any class not listed, before it is built
JobRequest req = (JobRequest) in.readObject();
jobs.submit(req);
}
}

We can also set the same pattern JVM-wide with -Djdk.serialFilter, which covers streams created by libraries inside the service. Before deploying, we replay real traffic from logs or tests to confirm nothing legitimate is rejected. This turns an open door into a narrow one, but it is still Java serialization, so it is a mitigation and not the end state.

4Replace Java Serialization on the Endpoint

The real fix is to stop reading Java serialized objects at all. We define the request as JSON, or Protobuf if the callers prefer a binary format, and map it to a fixed type. A JSON body mapped onto a record cannot name arbitrary classes, so the whole class of attack disappears.

Java
public record JobRequest(String jobName, Map<String, String> parameters) {}
@PostMapping(value = "/admin/jobs", consumes = "application/json")
public void submit(@Valid @RequestBody JobRequest req) {
jobs.submit(req); // Jackson builds only JobRequest, String and Map: no class names in the data
}

Because callers must change too, we usually run both content types for a short period: the new JSON endpoint is added, callers migrate, and the serialized endpoint is removed on a fixed date. The filter from step 2 protects the old path until then.

5Look for the Same Pattern Elsewhere

One finding usually means more. The same service, and others built the same way, may use Java serialization indirectly. We check for remoting libraries; Spring's HttpInvoker and RMI exporters, for example, were built on Java serialization and were removed in Spring Framework 6, so a service still using them is on an old version. We check whether JMX is exposed remotely, because JMX over RMI deserializes objects. We check RMI registries left by old admin tools, caching and session libraries configured with a Java serialization codec, and message consumers that read ObjectMessage from a broker.

A quick search of the code and the dependency tree for ObjectInputStream, readObject, Serializable payload types and the libraries above finds most of them. Each finding gets the same treatment: contain, filter, replace.

6Prevent New Uses

Finally we make sure the problem does not come back. We add a static analysis rule in CI, for example a Semgrep, Error Prone or ArchUnit rule, that fails the build when new code creates an ObjectInputStream or calls readObject outside an approved list of classes. We add a JVM-wide filter to the base image so that every service has a baseline allow-list, and we record the decision in the team's security guidelines: no Java serialization on data that crosses a trust boundary. Dependency scanning that flags known gadget libraries completes the picture.

7Follow-up questions

Why not fix the code first, since that is the real solution?

Because a code change needs development, review, testing and a release, which takes days, while restricting network access takes minutes and removes most of the risk immediately. The filter comes next because it is a small, low-risk change. Doing the slow, correct fix first would leave the door open for the whole time it takes.

What if callers are third-party tools we cannot change?

Then we keep the endpoint behind strict network controls and authentication, keep the allow-list filter as tight as possible, and put a translating proxy or an adapter in front if feasible. We also record the exception with an owner and a review date, so it does not quietly become permanent.

How do we know which classes to allow?

We read the endpoint's code and the callers' code, and in a test environment we turn on logging of filter decisions through the java.io.serialization logger to see every class real requests contain. The resulting list is usually short.

8Conclusion

In this answer, we treated an endpoint that accepts Java serialized objects as a potential remote code execution and handled it in order: contain it by limiting network exposure and checking for abuse, mitigate it with a strict allow-list filter, fix it by replacing Java serialization with JSON or Protobuf, search for the same pattern in remoting, JMX, RMI and caching libraries, and prevent new uses with a CI rule and a base-image filter.

What to say in the interviewAbout 90 seconds aloud

Open with

I would treat it as a potential remote code execution, because ObjectInputStream builds whatever classes the bytes name, and if any gadget chain exists on the class path, one request can run code with the admin service's permissions.

Then, if they want more

So step one is containment, which needs no code: restrict the endpoint at the network level to the few admin hosts or a VPN, add strong authentication in front, or disable it if nobody uses it.

At the same time I would check access logs and the host for signs it was already exploited, and if there are any, run it as an incident and rotate the service's credentials.

Step two is a quick mitigation: a strict allow-list deserialization filter with only the DTO classes the endpoint really receives, a few JDK classes, limits on depth and size, and a trailing reject-all, set on the stream and ideally JVM-wide.

Step three is the real fix: change the endpoint to accept JSON mapped to a record, or Protobuf, migrate the callers, and remove the old content type on a fixed date. Step four is looking for the same pattern elsewhere: remote JMX, RMI registries, old Spring remoting, caches or session stores using Java serialization, and JMS ObjectMessage.

And step five is prevention: a CI rule that blocks new ObjectInputStream use on untrusted input and a baseline filter in our base images.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6
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.
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 scan reports that an internal admin service accepts Java serialized objects...": https://scrivio-interview-library.netlify.app/java/serialization/5600474114/