funky-eyes commented on code in PR #7973:
URL: https://github.com/apache/incubator-seata/pull/7973#discussion_r2937913394
##########
json-common/src/main/java/org/apache/seata/common/json/impl/JacksonJsonSerializer.java:
##########
@@ -147,13 +154,41 @@ public <T> T parseObject(String json, Class<T> type,
boolean ignoreAutoType) {
if ("[]".equals(json)) {
return (T) new ArrayList<>(0);
}
+
+ // Check allowlist when AutoType is enabled
+ if (!ignoreAutoType && useAutoType(json)) {
+ checkAutoTypeClasses(json);
+ }
+
if (ignoreAutoType) {
return defaultObjectMapper.readValue(json, type);
} else {
return objectMapperWithAutoType.readValue(json, type);
}
+ } catch (SecurityException e) {
+ throw e;
} catch (IOException e) {
throw new JsonParseException("Jackson deserialize error", e);
}
}
+
+ /**
+ * Parse JSON with defaultObjectMapper (AutoType disabled) and check all
real @type fields against allowlist
+ */
+ private void checkAutoTypeClasses(String json) throws IOException {
+ JsonNode root = defaultObjectMapper.readTree(json);
+ checkJsonNode(root);
+ }
+
+ private void checkJsonNode(JsonNode node) {
Review Comment:
Why not use JsonDeserializer and JsonSerializer to enforce a whitelist?
##########
script/client/spring/application.yml:
##########
@@ -199,6 +199,8 @@ seata:
name:
log:
exception-rate: 100
+ json:
+ allowlist: com.company.model.,com.company.dto.,com.company.SpecialBean
Review Comment:
```suggestion
allowlist:
```
##########
script/client/spring/application.properties:
##########
@@ -183,6 +183,8 @@ seata.registry.zk.password=
seata.registry.custom.name=
+seata.json.allowlist=com.company.model.,com.company.dto.,com.company.UserPo
Review Comment:
```suggestion
seata.json.allowlist=
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]