Quick revision
The short answer
The main lesson is that any feature that lets input decide which types to create is dangerous, so it must be off by default and, when needed, limited to an explicit allow list. Beyond that, foundational libraries must be kept current, because old versions collect known issues; untrusted input needs allow lists and size limits; advisories should be tracked centrally so the whole fleet is patched quickly; and contracts between services should use simple, explicit data formats rather than clever serialization.
What to remember
In this answer, we saw how input-chosen types turned Jackson's polymorphic deserialization into a long series of advisories, why deny lists of gadget classes could never finish, and how allow lists ended that cycle. The lessons were to disallow input-chosen types by default, keep foundational libraries current, bound untrusted input with allow lists and size limits, track advisories centrally to patch the fleet quickly, and prefer simple, explicit formats for contracts between services.
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 main lesson is that any feature that lets input decide which types to create is dangerous, so it must be off by default and, when needed, limited to an explicit allow list. Beyond that, foundational libraries must be kept current, because old versions collect known issues; untrusted input needs allow lists and size limits; advisories should be tracked centrally so the whole fleet is patched quickly; and contracts between services should use simple, explicit data formats rather than clever serialization.
Why this question is asked
Jackson is in almost every Java service, so its security history is effectively the history of our own systems. From about 2017 onwards, a long series of advisories reported that Jackson could be tricked into creating dangerous classes, and later advisories covered denial of service through deeply nested input. Interviewers ask senior candidates what this teaches because the same patterns apply to every serialization library, from Java serialization to YAML parsers. In this answer, we will recap what went wrong, why the deny-list approach failed, and the lessons for libraries, input handling, patching and contract design.
1A Quick Recap of the Polymorphic Deserialization Problem
Polymorphic deserialization means the JSON contains information about which subclass to create. Jackson supports this through @JsonTypeInfo. With Id.CLASS, or with default typing enabled on the mapper, the payload carries a fully qualified Java class name, and Jackson creates an instance of that class and calls its setters or constructor with the values from the JSON.
The danger is that the classpath of a typical service contains thousands of classes, some of which do something powerful when a property is set, such as looking up a JNDI name, opening a connection or loading a class. Such a class is called a gadget. If the attacker can name it, Jackson calls the dangerous setter for them.
Notice that Jackson itself had no bug in the usual sense; it did exactly what it was configured to do. The flaw was the feature: input choosing types.
2Why Blocking Bad Classes One by One Failed
For several years the fix for each report was to add the newly found gadget class to a deny list inside jackson-databind and release a patch. Each patch was followed by a new report about another class in another library. The list grew to well over a hundred entries, and every service had to upgrade again each time.
The reason this cannot work is simple: the set of dangerous classes is open-ended. It depends on every library that might be on any classpath, including ones written next year. A deny list is always one discovery behind. Jackson 2.10 changed approach: activating default typing now requires a PolymorphicTypeValidator, which acts as an allow list of base types or packages we trust. That moved the responsibility to the place where the knowledge is, the application that knows which types it expects.
| Approach | What it assumes | Result over time |
|---|---|---|
| Deny list of gadget classes | We can know every dangerous class | Endless patches; always behind attackers |
| Allow list of expected types | We know the types we expect | Closed set; new gadgets do not matter |
| No input-chosen types at all | Types come from the contract | Nothing to exploit in this way |
3Lesson 1: Disallow Input-Chosen Types by Default
The deepest lesson is about library and API design. A feature that lets untrusted input choose code paths, classes, file paths or queries should be disabled by default, hard to enable, and limited to an explicit list when enabled. The same lesson appeared in Java's built-in serialization, in YAML libraries that could construct arbitrary objects, and in XML parsers resolving external entities. In each case, the dangerous behaviour was a convenience feature that was on, or easy to turn on.
For our own code, the rule is concrete: polymorphism uses logical names with a closed list of subtypes, never class names, and the build fails if anyone enables default typing.
4Lesson 2: Keep Foundational Libraries Current
Old versions accumulate known issues. A service pinned to a Jackson version from four years ago may be exposed to dozens of published advisories, each with a public description that tells attackers what to try. The cost of upgrading also grows with the gap: moving one minor version is routine, moving across many releases at once is a project. So we treat foundational libraries like Jackson, Netty, Spring and logging frameworks as something we upgrade continuously, ideally by moving with Spring Boot's managed versions, which already pick tested combinations.
Upgrades need safety nets to be routine. Golden-file tests of JSON output, good integration tests and a fast pipeline make a patch release a one-hour task instead of a risky week.
5Lesson 3: Allow Lists and Size Limits for Untrusted Input
Later Jackson advisories were about denial of service: deeply nested arrays that overflow the stack, or huge numbers that are expensive to convert. The response, StreamReadConstraints in 2.15, applies the same principle in another form: input should be bounded. For every boundary where untrusted data enters, we decide the maximum request size, the maximum nesting, the allowed types and the allowed values, and we enforce them as early as possible, at the proxy, in the parser, then in validation.
6Lesson 4: Track Advisories Centrally and Patch the Fleet
When a serious advisory appears, the question that matters is how many hours it takes until every service runs the fixed version. With 150 services owned by 30 teams, that only works if it is organised. We need an inventory of which version every deployed service uses, generated from builds rather than asked by email. We need automated dependency updates such as Dependabot or Renovate, a security team or platform team that triages advisories and says which ones need emergency action, and a target time to patch by severity, for example 48 hours for critical issues.
- Advisory publishedSecurity team triages severity
- Query the dependency inventoryWhich services use affected versions?
- Is the vulnerable feature in use?e.g. default typing enabledYesEmergency patch within 48 hoursNoNormal update cycle
- Automated update pull requestsGolden and integration tests run
- Deploy and confirm in inventoryTrack until every service is fixed
5 steps in order. Play them, or step through them one at a time.
Central tracking turns a fleet-wide patch into a routine process.
Finally, the lesson for contracts. Simple, explicit data formats between services, records with known fields and logical type names, described in a schema, are safer than formats that serialize object graphs. They are also easier to review, test and evolve, so security and maintainability point in the same direction here.
7Follow-up questions
Is it safe to use @JsonTypeInfo at all?
Yes, with Id.NAME and an explicit list of subtypes, ideally on a sealed interface. The risk comes from Id.CLASS, Id.MINIMAL_CLASS and default typing on broad base types such as Object, Serializable or a general interface, because then the payload can name classes we never intended to accept.
What if a legacy system needs class names in JSON, for example a cache?
Then the data must not come from untrusted sources, and I would still configure a PolymorphicTypeValidator that allows only the company's own model packages. Better still, I would change the cache to store explicit types, because a cache that an attacker can write to through another bug becomes an attack path.
How does this history apply to choosing a new serialization library?
I would check whether it can create arbitrary types from input and whether that is off by default, how quickly it publishes fixes, how many maintainers and users it has, and whether it offers limits on input size and depth. A library with a smaller feature set and a schema is often the safer choice for cross-service contracts.
8Conclusion
In this answer, we saw how input-chosen types turned Jackson's polymorphic deserialization into a long series of advisories, why deny lists of gadget classes could never finish, and how allow lists ended that cycle. The lessons were to disallow input-chosen types by default, keep foundational libraries current, bound untrusted input with allow lists and size limits, track advisories centrally to patch the fleet quickly, and prefer simple, explicit formats for contracts between services.
Open with
The big lesson for me is that features which let input choose types are inherently risky. Most Jackson advisories came from default typing or Id.CLASS, where the JSON names a class and Jackson instantiates it and calls its setters, so any gadget class on the classpath became an attack.
Then, if they want more
Jackson first answered with a deny list of gadgets, and that list kept growing because the set of dangerous classes is open-ended. Since 2.10 the approach is an allow list through a PolymorphicTypeValidator, which is the right model.
So in our own systems, polymorphism uses logical type names with a closed list of subtypes, and enabling default typing fails the build. The second lesson is to keep foundational libraries current, because old versions collect published issues and the upgrade gets harder the longer we wait; following Spring Boot's managed versions with golden tests makes that routine.
Third, untrusted input gets allow lists and size limits, which is what StreamReadConstraints added after the nesting advisories. Fourth, we need a central inventory of versions, automated update pull requests and a target time to patch, say 48 hours for critical issues. And for contracts between services I prefer simple, explicit, schema-described formats.
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
- Spring Framework reference, Spring Web MVC
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 "Jackson has had many security advisories over the years, mostly around polymorphic...": https://scrivio-interview-library.netlify.app/spring-boot/json-serialization/9e52524f50/