Copilot commented on code in PR #7973:
URL: https://github.com/apache/incubator-seata/pull/7973#discussion_r2887778697


##########
json-common/src/main/java/org/apache/seata/common/json/JsonAllowlistManager.java:
##########
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.common.json;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * JSON deserialization allowlist manager.
+ */
+public class JsonAllowlistManager {
+
+    private static final JsonAllowlistManager INSTANCE = new 
JsonAllowlistManager();
+
+    /**
+     * Built-in exact match allowlist
+     */
+    private final Set<String> builtinClasses = ConcurrentHashMap.newKeySet();
+
+    /**
+     * Built-in prefix match allowlist
+     */
+    private final Set<String> builtinPrefixes = ConcurrentHashMap.newKeySet();
+
+    /**
+     * User-defined exact match allowlist
+     */
+    private final Set<String> userClasses = ConcurrentHashMap.newKeySet();
+
+    /**
+     * User-defined prefix match allowlist
+     */
+    private final Set<String> userPrefixes = ConcurrentHashMap.newKeySet();
+
+    /**
+     * Check result cache (className -> allowed)
+     */
+    private final Map<String, Boolean> cache = new ConcurrentHashMap<>();
+
+    private JsonAllowlistManager() {
+        initBuiltinAllowlist();
+    }
+
+    public static JsonAllowlistManager getInstance() {
+        return INSTANCE;
+    }
+
+    /**
+     * Load user allowlist from configuration string
+     */
+    public void loadUserAllowlist(String config) {
+        if (config == null || config.isEmpty()) {
+            return;
+        }
+        cache.clear();
+        for (String item : config.split(",")) {
+            String trimmed = item.trim();
+            if (trimmed.isEmpty()) {
+                continue;
+            }
+            if (trimmed.endsWith(".")) {
+                userPrefixes.add(trimmed);
+            } else {
+                userClasses.add(trimmed);
+            }
+        }
+    }

Review Comment:
   `loadUserAllowlist` appends entries to `userClasses`/`userPrefixes` without 
clearing existing ones, so repeated loads (e.g., config refresh / multiple 
initializations in the same JVM) will keep old allowlist entries permanently. 
Consider clearing `userClasses` and `userPrefixes` (and cache) at the start of 
this method, and treating null/empty config as “reset to built-in only” rather 
than a no-op.



##########
seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonPropertiesTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.spring.boot.autoconfigure.properties;
+
+import org.apache.seata.common.json.JsonAllowlistManager;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SeataJsonPropertiesTest {
+
+    @AfterEach
+    public void cleanup() {
+        JsonAllowlistManager.getInstance().loadUserAllowlist("");

Review Comment:
   `cleanup()` calls `loadUserAllowlist("")`, but 
`JsonAllowlistManager.loadUserAllowlist` treats empty config as a no-op (does 
not clear `userClasses`/`userPrefixes`). This can leak allowlist state between 
tests and make the suite order-dependent. Use `clearUserAllowlist()` (or 
equivalent) here to reset state reliably.
   ```suggestion
           JsonAllowlistManager.getInstance().clearUserAllowlist();
   ```



##########
json-common/src/main/java/org/apache/seata/common/json/impl/JacksonJsonSerializer.java:
##########
@@ -147,13 +148,54 @@ 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);

Review Comment:
   The allowlist check was added to `parseObject(json, type, ignoreAutoType)`, 
but `parseObjectWithType(...)` still deserializes with 
`objectMapperWithAutoType` without any allowlist enforcement. This leaves a 
bypass path for polymorphic deserialization when callers use 
`parseObjectWithType`. Consider applying the same allowlist check there (when 
`useAutoType(text)` is true) before calling `readValue`.



-- 
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]

Reply via email to