Skip to content

Commit dc3ae26

Browse files
artembilangaryrussell
authored andcommitted
Code clean up for JacksonJsonUtils
* Mention `trustedPackages` in the `redis.adoc` **Cherry-pick to 5.3.x, 5.2.x, 5.1.x & 4.3.x**
1 parent 7b40488 commit dc3ae26

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -156,13 +156,13 @@ private static final class WhitelistTypeIdResolver implements TypeIdResolver {
156156
WhitelistTypeIdResolver(TypeIdResolver delegate, String... trustedPackages) {
157157
this.delegate = delegate;
158158
if (trustedPackages != null) {
159-
for (String whiteListClass : trustedPackages) {
160-
if ("*".equals(whiteListClass)) {
159+
for (String whiteListPackage : trustedPackages) {
160+
if ("*".equals(whiteListPackage)) {
161161
this.trustedPackages.clear();
162162
break;
163163
}
164164
else {
165-
this.trustedPackages.add(whiteListClass);
165+
this.trustedPackages.add(whiteListPackage);
166166
}
167167
}
168168
}
@@ -213,7 +213,10 @@ public JavaType typeFromId(DatabindContext context, String id) throws IOExceptio
213213
private boolean isTrustedPackage(String packageName) {
214214
if (!this.trustedPackages.isEmpty()) {
215215
for (String trustedPackage : this.trustedPackages) {
216-
if (packageName.equals(trustedPackage) || packageName.startsWith(trustedPackage + ".")) {
216+
if (packageName.equals(trustedPackage) ||
217+
(!packageName.equals("java.util.logging")
218+
&& packageName.startsWith(trustedPackage + "."))) {
219+
217220
return true;
218221
}
219222
}

src/reference/asciidoc/redis.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ However, if you want to use a different serialization technique (such as JSON),
367367

368368
Starting with version 4.3.10, the Framework provides Jackson serializer and deserializer implementations for `Message` instances and `MessageHeaders` instances -- `MessageJacksonDeserializer` and `MessageHeadersJacksonSerializer`, respectively.
369369
They have to be configured with the `SimpleModule` options for the `ObjectMapper`.
370-
In addition, you should set `enableDefaultTyping` on the `ObjectMapper` to add type information for each serialized complex object.
370+
In addition, you should set `enableDefaultTyping` on the `ObjectMapper` to add type information for each serialized complex object (if you trust the source).
371371
That type information is then used during deserialization.
372372
The framework provides a utility method called `JacksonJsonUtils.messagingAwareMapper()`, which is already supplied with all the previously mentioned properties and serializers.
373+
This utility method comes with the `trustedPackages` argument to limit Java packages for deserialization to avoid security vulnerabilities.
374+
The default trusted packages: `java.util`, `java.lang`, `org.springframework.messaging.support`, `org.springframework.integration.support`, `org.springframework.integration.message`, `org.springframework.integration.store`.
373375
To manage JSON serialization in the `RedisMessageStore`, you must configure it in a fashion similar to the following example:
374376

375377
====

0 commit comments

Comments
 (0)