Skip to content

Commit f90473f

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 65cc6ab commit f90473f

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.
@@ -168,13 +168,13 @@ private static final class WhitelistTypeIdResolver implements TypeIdResolver {
168168
WhitelistTypeIdResolver(TypeIdResolver delegate, String... trustedPackages) {
169169
this.delegate = delegate;
170170
if (trustedPackages != null) {
171-
for (String whiteListClass : trustedPackages) {
172-
if ("*".equals(whiteListClass)) {
171+
for (String whiteListPackage : trustedPackages) {
172+
if ("*".equals(whiteListPackage)) {
173173
this.trustedPackages.clear();
174174
break;
175175
}
176176
else {
177-
this.trustedPackages.add(whiteListClass);
177+
this.trustedPackages.add(whiteListPackage);
178178
}
179179
}
180180
}
@@ -225,7 +225,10 @@ public JavaType typeFromId(DatabindContext context, String id) throws IOExceptio
225225
private boolean isTrustedPackage(String packageName) {
226226
if (!this.trustedPackages.isEmpty()) {
227227
for (String trustedPackage : this.trustedPackages) {
228-
if (packageName.equals(trustedPackage) || packageName.startsWith(trustedPackage + ".")) {
228+
if (packageName.equals(trustedPackage) ||
229+
(!packageName.equals("java.util.logging")
230+
&& packageName.startsWith(trustedPackage + "."))) {
231+
229232
return true;
230233
}
231234
}

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)