Skip to content

Commit d958e36

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 e370174 commit d958e36

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

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)