Summary
A flaw in Jackson Databind's polymorphic type validation allows attackers to sneak forbidden classes into generic type parameters when polymorphic typing is enabled.
If an attacker can control type identifiers in JSON input, they may bypass the PolymorphicTypeValidator allow-list and trigger deserialization of unsafe gadget classes, potentially leading to remote code execution or other severe impacts.
Affected context
This vulnerability arises in Java applications that use Jackson Databind with polymorphic typing enabled and rely on PolymorphicTypeValidator (PTV) to restrict deserialization targets.
It becomes relevant when incoming data can supply or influence type identifiers, especially canonical type strings that include generic parameters (such as java.util.List<com.evil.Gadget>).
The issue is most pronounced in API endpoints, message processors, or serialization frameworks that accept untrusted JSON and depend on PTV for enforcing deserialization safety.
Exploit preconditions
- Attack surface: Any JSON-based input path using Jackson Databind polymorphic deserialization (e.g., REST APIs, message queues, RPC payloads).
- Required access: Ability to send or control serialized data that includes type identifiers, typically through client-controlled request bodies or messages.
- Trigger point: Polymorphic deserialization of a type ID string containing generic parameters while PTV is configured to allow specific container types.
- Why exploitation is possible: DatabindContext._resolveAndValidateGeneric() validates only the raw container class name against PTV and never validates nested generic type arguments. As a result, an attacker can embed a denied or gadget class as a generic parameter of an approved container, causing Jackson to load, instantiate, and populate that class during deserialization.
Why this happens
The underlying bug is a validation gap in the polymorphic type resolution logic within Jackson Databind.
When a type identifier includes generic parameters, the code path validates only the outer container type (the substring before <) against PolymorphicTypeValidator and then constructs the full canonical type using TypeFactory without re-applying validation to inner type arguments.
This maps to CWE-184: Incomplete List of Disallowed Inputs, because the validation covers only part of the type structure, and to CWE-502: Unsafe Deserialization, since untrusted input is allowed to drive class loading and object instantiation.
Conceptually, the pattern is: trust is granted to an entire generic type graph based solely on the container, leaving nested types unchecked and enabling attackers to smuggle in unsafe gadget classes.
Potential impact
- Attackers may cause instantiation of explicitly disallowed gadget classes via generic type parameters.
- Deserialized objects could execute arbitrary code if gadget chains or dangerous class behaviors are present.
- Application-level data integrity and confidentiality can be compromised through malicious object graphs.
- Security controls relying on Jackson's PolymorphicTypeValidator allow-lists can be bypassed.
- Further exploitation may enable remote code execution, privilege escalation, or system compromise depending on gadget availability.
General mitigation guidance
Effective mitigation focuses on reducing trust in polymorphic type information and tightening deserialization boundaries.
Recommended patterns include:
- Avoiding or strictly limiting Jackson's polymorphic typing for data from untrusted or semi-trusted sources; prefer explicit, statically mapped types instead of attacker-controlled type IDs.
- Designing allow-lists that treat complex generic structures conservatively, and applying validation to complete type graphs rather than only container classes.
- Segmenting deserialization contexts so that sensitive or powerful types are never reachable from untrusted data, even if type validation fails.
- Applying least-privilege principles to deserialized objects by eliminating gadget classes and avoiding dangerous behaviors (such as code execution in constructors or setters).
- Encapsulating deserialization behind domain-specific DTOs that do not expose internal implementation classes or generic type parameters to external callers.
How teams detect issues like this
Detection typically involves reviewing both configuration and code paths that rely on polymorphic deserialization:
- Use static analysis or custom rules to flag uses of polymorphic typing (
@JsonTypeInfo, default typing, etc.) on input paths that may consume untrusted data. - During code review, look for places where PolymorphicTypeValidator is assumed to enforce strict safety, and verify how generic type identifiers are handled.
- Implement policy checks in CI/CD pipelines that disallow or require approval for polymorphic deserialization settings, especially those that allow broad type ranges.
- Monitor application logs and telemetry for unusual type identifiers or canonical type strings arriving from external inputs.
- Consider using automated security testing tools that generate hostile type ID payloads to exercise deserialization entry points and confirm validation behavior.

