Mitigation Strategy: 1. Keep jackson-databind Updated
-
Description:
- Identify the current
jackson-databindversion (checkpom.xml,build.gradle, etc.). - Find the latest patch release for your minor version on GitHub or Maven Central.
- Update the dependency in your project's build file.
- Run a full build and test suite.
- Configure a dependency management tool (Dependabot, Snyk, etc.) for automatic updates (at least weekly).
- Identify the current
-
Threats Mitigated:
- Remote Code Execution (RCE) (Critical): Updates often patch RCE vulnerabilities.
- Denial of Service (DoS) (High): Some vulnerabilities can cause crashes or unresponsiveness.
- Information Disclosure (Medium): Less common, but some vulnerabilities might leak information.
-
Impact:
- RCE: Significantly reduces risk. Risk reduction: High.
- DoS: Reduces risk. Risk reduction: Medium.
- Information Disclosure: Reduces risk. Risk reduction: Low.
-
Currently Implemented:
- Check the project's build file for the current version.
- Check for a dependency management tool configuration.
- Example:
pom.xmlshows version 2.12.3. Dependabot is configured, but checks monthly.
-
Missing Implementation:
- Ensure all instances of
jackson-databindare updated (including subprojects). - Increase update frequency (e.g., to weekly).
- Example: A microservice uses an older version. Dependabot checks are missing for that microservice.
- Ensure all instances of
Mitigation Strategy: 2. Minimize Polymorphic Deserialization
-
Description:
- Review code for
@JsonTypeInfo,@JsonSubTypes, and related annotations. - Analyze if polymorphic deserialization is truly necessary. Could concrete types or composition be used?
- If possible, refactor to remove the annotations and use concrete types.
- If unavoidable, document why and proceed to other mitigations (especially PTV).
- Review code for
-
Threats Mitigated:
- RCE (Critical): Addresses the root cause of most
jackson-databindRCE vulnerabilities. - DoS (High): Reduces the attack surface for DoS.
- RCE (Critical): Addresses the root cause of most
-
Impact:
- RCE: The most significant impact. Risk reduction: Very High.
- DoS: Moderate impact. Risk reduction: Medium.
-
Currently Implemented:
- Check for the presence of the relevant annotations.
- Review design documents for justification of polymorphism.
- Example: Several data models use
@JsonTypeInfowithout clear justification.
-
Missing Implementation:
- Identify classes/modules where refactoring to remove polymorphism is feasible.
- Example: The
Eventclass hierarchy uses@JsonTypeInfobut could use a singleEventclass with aneventTypefield.
Mitigation Strategy: 3. Use a Safe Default Typing Strategy
-
Description:
- Locate where the
ObjectMapperis configured. - Check if
activateDefaultTyping(orenableDefaultTyping) is used. - Examine the
DefaultTypingenum value. If it'sOBJECT_AND_NON_CONCRETEorNON_FINAL, it's unsafe. - Change it to
NON_CONCRETE_AND_ARRAYSor, preferably, use a customTypeResolverBuilderwith aPolymorphicTypeValidator(see next point). - Thoroughly test the application.
- Locate where the
-
Threats Mitigated:
- RCE (Critical): Limits types that can be automatically deserialized.
- DoS (High): Indirectly helps by reducing complexity.
-
Impact:
- RCE: Moderate impact on its own, but essential with a
PolymorphicTypeValidator. Risk reduction: Medium (High with PTV). - DoS: Low impact. Risk reduction: Low.
- RCE: Moderate impact on its own, but essential with a
-
Currently Implemented:
- Check
ObjectMapperconfiguration foractivateDefaultTypingorenableDefaultTyping. - Example:
ObjectMapperis configured withDefaultTyping.NON_FINAL.
- Check
-
Missing Implementation:
- Change the
DefaultTypingsetting. - Implement a
PolymorphicTypeValidator(crucial). - Example: Change
DefaultTypingand implement a PTV.
- Change the
Mitigation Strategy: 4. Implement a PolymorphicTypeValidator (PTV)
-
Description:
- Create a
PolymorphicTypeValidatorinstance (BasicPolymorphicTypeValidatoris a good start). - Configure it to whitelist allowed base types and subtypes. Be restrictive. Use methods like:
allowIfSubType(String prefix)allowIfSubType(Class<?> clazz)allowIfBaseType(Class<?> clazz)allowIfSubType(Predicate<Class<?>> predicate)
- Pass the validator to
ObjectMapper'sactivateDefaultTyping. - Thoroughly test, adjusting the whitelist as needed.
- Create a
-
Threats Mitigated:
- RCE (Critical): The most effective mitigation when polymorphism is required. Prevents deserialization of unauthorized classes.
- DoS (High): Indirectly helps by limiting allowed types.
-
Impact:
- RCE: Very high impact. Risk reduction: Very High.
- DoS: Low impact. Risk reduction: Low.
-
Currently Implemented:
- Check
ObjectMapperconfiguration for anyPolymorphicTypeValidator. - Example: No
PolymorphicTypeValidatoris configured.
- Check
-
Missing Implementation:
- Critical missing piece. A PTV must be implemented if polymorphism is used.
- Create a
BasicPolymorphicTypeValidatorwith a strict whitelist. - Example: Create a PTV to allow only specific subtypes within
com.example.app.models.
Mitigation Strategy: 5. Disable Problematic Features
-
Description:
- Review the
ObjectMapperconfiguration. - Disable unnecessary features that could increase the attack surface. Consider:
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESMapperFeature.USE_GETTERS_AS_SETTERSMapperFeature.AUTO_DETECT_CREATORS,AUTO_DETECT_FIELDS,AUTO_DETECT_GETTERS,AUTO_DETECT_IS_GETTERS,AUTO_DETECT_SETTERS
- Thoroughly test after disabling features.
- Review the
-
Threats Mitigated:
- RCE (Critical): Reduces the attack surface.
- DoS (High): Can help prevent some DoS attacks.
- Information Disclosure (Medium): Can reduce information leaked through errors.
-
Impact:
- RCE: Low to moderate impact. Risk reduction: Low-Medium.
- DoS: Low impact. Risk reduction: Low.
- Information Disclosure: Low impact. Risk reduction: Low.
-
Currently Implemented:
- Check
ObjectMapperconfiguration for disabled features. - Example: No features are explicitly disabled.
- Check
-
Missing Implementation:
- Disable the listed features (or a subset) if not essential.
- Example: Disable
MapperFeature.AUTO_DETECT_CREATORS,AUTO_DETECT_FIELDS, etc.