Class DeserializationFilterHelper
java.lang.Object
org.apache.camel.support.DeserializationFilterHelper
Helper for resolving the JEP-290
ObjectInputFilter that components apply when deserializing Java objects from
potentially untrusted input (message payloads, persisted exchange state, and so on).
The resolution order is the same for every component:
- an explicitly configured filter pattern (typically a
deserializationFilterendpoint or component option); - the JVM-wide filter configured via the
jdk.serialFiltersystem property orObjectInputFilter.Config.setSerialFilter(ObjectInputFilter); - a conservative Camel default.
- Since:
- 4.22
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault deserialization filter pattern for checking the class of an object that a third-party library has already deserialized, for example the payload returned byjakarta.jms.ObjectMessage#getObject().static final StringDefault deserialization filter pattern applied while reading from anObjectInputStream(viaObjectInputStream.setObjectInputFilter(ObjectInputFilter)). -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectInputFilter.StatuscheckClass(ObjectInputFilter filter, Class<?> clazz) Checks the class of an already-deserialized object against the given filter.static ObjectInputFilterresolveDeserializationFilter(String configuredPattern) Resolves the deserialization filter to apply, falling back toDEFAULT_DESERIALIZATION_FILTER.static ObjectInputFilterresolveDeserializationFilter(String configuredPattern, String defaultPattern) Resolves the deserialization filter to apply: the configured pattern when present, otherwise the JVM-wide filter (jdk.serialFilter) when set, otherwise the given default pattern.
-
Field Details
-
DEFAULT_DESERIALIZATION_FILTER
Default deserialization filter pattern applied while reading from anObjectInputStream(viaObjectInputStream.setObjectInputFilter(ObjectInputFilter)). Deniesjava.net.**, allows other standard Java types and Apache Camel types, rejects everything else, and applies JEP-290 graph-shape limits (maxdepth,maxrefs,maxbytes) as defense-in-depth against resource-exhaustion payloads.- See Also:
-
DEFAULT_CLASS_DESERIALIZATION_FILTER
Default deserialization filter pattern for checking the class of an object that a third-party library has already deserialized, for example the payload returned byjakarta.jms.ObjectMessage#getObject(). Same allow-list asDEFAULT_DESERIALIZATION_FILTERbut deliberately without the JEP-290 graph-shape limits: stream metrics such as depth, reference count and byte count are not available once deserialization has already happened, so including the limits would only advertise protection that can never be enforced.- See Also:
-
-
Method Details
-
resolveDeserializationFilter
Resolves the deserialization filter to apply, falling back toDEFAULT_DESERIALIZATION_FILTER.- Parameters:
configuredPattern- the filter pattern configured on the component or endpoint, may be null or blank- Returns:
- the filter to apply, never null
-
resolveDeserializationFilter
public static ObjectInputFilter resolveDeserializationFilter(String configuredPattern, String defaultPattern) Resolves the deserialization filter to apply: the configured pattern when present, otherwise the JVM-wide filter (jdk.serialFilter) when set, otherwise the given default pattern.- Parameters:
configuredPattern- the filter pattern configured on the component or endpoint, may be null or blankdefaultPattern- the default pattern to fall back to, must not be null- Returns:
- the filter to apply, never null
-
checkClass
Checks the class of an already-deserialized object against the given filter. This is for components where a third-party library performs the actual deserialization and Camel can only vet the result after the fact. Only the class is checked; JEP-290 graph-shape limits (maxdepthand friends) in the filter pattern cannot be evaluated in this mode, so resolve the filter withDEFAULT_CLASS_DESERIALIZATION_FILTERas the default.- Parameters:
filter- the filter to check againstclazz- the class of the deserialized object- Returns:
- the filter decision; callers should treat
ObjectInputFilter.Status.REJECTEDas fatal
-