Quick revision
The short answer
The policy has a few clear rules. No Java native serialization, or any format that lets data name classes, across trust boundaries; untrusted input uses schema-based formats. Polymorphic deserialization in JSON libraries is allowed only with allow-listed types. JVM-wide deserialization filters are set in base images. Dependency scanning covers gadget libraries and deserialization CVEs with patch deadlines, and CI static analysis plus periodic penetration tests of data endpoints catch what slips through. It stays effective through ownership, measurement, time-limited exceptions and a yearly review as libraries and attacks change.
What to remember
In this answer, we designed a deserialization policy that covers every language by describing the dangerous behaviour, data choosing types, rather than one API. Its rules are schema-based formats across trust boundaries, polymorphic JSON only with allow-listed types, JVM-wide filters in base images, dependency scanning with patch deadlines, and CI static analysis plus penetration tests of data endpoints. It stays effective through clear ownership, time-limited exceptions, quarterly numbers and a yearly review as libraries and attacks change.
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 policy has a few clear rules. No Java native serialization, or any format that lets data name classes, across trust boundaries; untrusted input uses schema-based formats. Polymorphic deserialization in JSON libraries is allowed only with allow-listed types. JVM-wide deserialization filters are set in base images. Dependency scanning covers gadget libraries and deserialization CVEs with patch deadlines, and CI static analysis plus periodic penetration tests of data endpoints catch what slips through. It stays effective through ownership, measurement, time-limited exceptions and a yearly review as libraries and attacks change.
Why this question is asked
In a company with hundreds of services, several languages and many third-party integrations, a deserialization policy is not a Java problem. Python's pickle, PHP's unserialize, .NET's type-name handling in JSON and YAML loaders that build objects all have the same weakness, and an integration partner can send us any of them. Interviewers ask this at principal level to see whether we can write rules that are general enough to cover all of this, concrete enough to check, and maintained over years. In this answer, we will define the problem the policy addresses, go through each rule, explain how it is enforced automatically, and then cover the governance that keeps it working.
1The Problem in One Sentence
Unsafe deserialization happens whenever the bytes we read are allowed to decide which types get created, and creating those types runs code. Java's ObjectInputStream is the best-known case, but the same shape appears in many places: Python's pickle runs arbitrary callables by design, PHP's unserialize calls magic methods, Jackson's default typing and .NET JSON settings that honour type names read class names from the JSON, and YAML loaders in several languages can build arbitrary objects unless a safe mode is used.
So the policy talks about behaviour, not about one API: any reader that lets data choose types is treated as dangerous, whatever the language.
2Rule 1: Schema-Based Formats Across Trust Boundaries
Data that crosses a trust boundary, from the internet, from partners, from other teams' services or from any shared store, is read with formats where the reader decides the types: JSON or XML mapped to fixed types, Protobuf, Avro, or similar. Language-native object serialization, Java serialization, pickle, PHP serialize, binary formatters, is not allowed there at all. This single rule removes most of the risk, because a reader that only fills in values of known types has no gadgets to call.
For third-party integrations this means we accept only documented formats at our edge. If a partner can only send something unsafe, an adapter in an isolated service converts it into our format, and only that adapter is exposed to the risk.
- Edge and integrationsonly schema-based formats accepted; adapters isolate legacy partners
- Service codepolymorphic JSON only with allow-listed types; CI static analysis
- RuntimeJVM-wide deserialization filters in base images; safe loader defaults
- Dependenciesscanning for gadget libraries and CVEs, patch deadlines
- Verificationpenetration tests of data endpoints; yearly policy review
5 layers, from the top down. Step through them one at a time.
Each layer catches what the one above it missed.
3Rule 2: Polymorphic JSON Only With Allow-Listed Types
Polymorphism is sometimes needed: an event field might hold one of several payload types. That is allowed, but the possible types must be a closed, allow-listed set, expressed as logical names that the reader maps to types. In Java with Jackson, that means @JsonTypeInfo with @JsonSubTypes and logical names, or a PolymorphicTypeValidator that allows only our own base packages, and never default typing with an allow-everything validator. Other languages get equivalent guidance, such as never turning on type-name handling for untrusted JSON in .NET and always using safe loaders for YAML.
4Rules 3 and 4: Runtime Filters and Dependency Scanning
Inside trust boundaries, some Java serialization remains in caches, session replication and management tools. Every Java service therefore runs with a JVM-wide jdk.serialFilter set in the shared base image, with limits and a reject-all at the end, and services extend the allow-list through configuration. The equivalent for other runtimes is safe defaults in shared libraries, for example a company YAML helper that only exposes safe loading.
Dependency scanning runs on every build for every language. It flags libraries with known gadget chains and any CVE classed as deserialization of untrusted data, with patch deadlines by severity, for example seven days for critical and thirty for high, tracked on a dashboard by team. Patching does not make unsafe formats safe, but it closes known chains while migrations happen.
5Rule 5: Static Analysis and Penetration Tests
Shared static analysis rules run in CI for each language: they flag ObjectInputStream and readObject in Java, pickle.loads and yaml.load without a safe loader in Python, unserialize in PHP, and type-name handling in .NET JSON settings. New findings block the merge unless the use is on a reviewed exception list. Rules are written once by the security team and distributed to every repository, so teams do not have to maintain them.
Tools miss things, so the policy also requires periodic penetration tests that target data endpoints specifically: APIs, message consumers, file uploads and integration adapters, using known deserialization payloads. A finding becomes a ticket with the same deadlines as a CVE.
6Keeping the Policy Effective Over Years
Policies decay in predictable ways: new languages and libraries arrive, attacks find new gadgets, exceptions become permanent and nobody remembers why a rule exists. We counter each one. The security team owns the policy and reviews it every year, adding new formats, libraries and attack techniques. The platform team owns the tooling that enforces it, so improvements reach every service through base images and shared CI rules. Exceptions have an owner, compensating controls and an expiry date.
We also measure it. A small set of numbers is reviewed every quarter: services accepting unsafe formats across a boundary, services without the base filter, open deserialization CVEs past their deadline, expired exceptions, and penetration test findings. Each rule has a short explanation of why it exists, so engineers joining in five years can follow the reasoning instead of just the rule.
- Collect evidenceincidents, pen test findings, new CVEs, exception list
- New formats or languages in use?Yesadd rules and CI checksNokeep current rules
- Expired or permanent exceptions?Yesrenew with controls or retire the useNocontinue
- Publish the updated policychangelog and reasons for each change
4 steps in order. Play them, or step through them one at a time.
7Follow-up questions
How do we handle a vendor product that only speaks Java RMI?
We isolate it: the product runs on its own network segment reachable only from a dedicated adapter, the JVMs involved run with strict filters, and the adapter exposes a schema-based API to the rest of the company. The exception is recorded with an owner and expiry, and the vendor is asked for a safer interface at each renewal.
Is a deny-list of known gadget classes enough?
No. Deny-lists only stop chains someone has already found, and new ones keep being published. Allow-lists, which accept only the types we expect, are the rule; deny-lists, such as the one Jackson maintains, are useful extra protection while we migrate.
How do we roll this out without stopping hundreds of teams?
Start with the central controls that need no team work, base-image filters, shared CI rules in warning mode and dependency scanning, then turn the CI rules into blocking checks once the existing findings are inventoried. Teams then migrate exposed uses first, with deadlines by risk.
8Conclusion
In this answer, we designed a deserialization policy that covers every language by describing the dangerous behaviour, data choosing types, rather than one API. Its rules are schema-based formats across trust boundaries, polymorphic JSON only with allow-listed types, JVM-wide filters in base images, dependency scanning with patch deadlines, and CI static analysis plus penetration tests of data endpoints. It stays effective through clear ownership, time-limited exceptions, quarterly numbers and a yearly review as libraries and attacks change.
Open with
I would write the policy around one idea: unsafe deserialization is any reader that lets the data choose which types to create, because creating types runs code. That covers Java serialization, Python pickle, PHP unserialize, .NET type-name handling, Jackson default typing and unsafe YAML loading, so the policy works across languages.
Then, if they want more
Rule one: anything crossing a trust boundary, from the internet, partners, other teams or shared stores, uses formats where the reader decides the types, JSON mapped to fixed types, Protobuf or Avro, and language-native serialization is not allowed there. Legacy partners go through an isolated adapter.
Rule two: polymorphic JSON is fine only with a closed list of logical type names or a strict type validator, never class names from the data. Rule three: every JVM runs with a jdk.serialFilter allow-list from the base image, and other runtimes get safe loaders through shared libraries.
Rule four: dependency scanning for gadget libraries and deserialization CVEs with patch deadlines, say seven days for critical. Rule five: shared static analysis rules per language in CI, plus periodic penetration tests aimed at data endpoints.
To keep it effective for years, security owns the policy and reviews it yearly, the platform team owns the tooling so improvements reach everyone, exceptions expire, and we track a few numbers quarterly, like unsafe formats at boundaries and overdue CVEs.
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 "What would a serialization and deserialization security policy look like for a company...": https://scrivio-interview-library.netlify.app/java/serialization/e490ef2819/