Copilot commented on code in PR #15682:
URL: https://github.com/apache/dubbo/pull/15682#discussion_r2358114782


##########
dubbo-common/src/main/java/org/apache/dubbo/common/config/SensitiveParameterConfig.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * 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.dubbo.common.config;
+
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.utils.StringUtils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Configuration for sensitive parameters that should be hidden in URL string 
representations
+ * to prevent credential leakage in logs and exceptions.
+ * <p>
+ * Supports both default sensitive parameters and custom configurations 
through:
+ * - System properties
+ * - Environment variables
+ * - Programmatic configuration
+ * </p>
+ */
+public class SensitiveParameterConfig {
+
+    /**
+     * System property key for configuring custom sensitive parameters
+     */
+    public static final String SENSITIVE_PARAMS_PROPERTY = 
"dubbo.url.sensitive.parameters";
+
+    /**
+     * Environment variable key for configuring custom sensitive parameters
+     */
+    public static final String SENSITIVE_PARAMS_ENV = 
"DUBBO_URL_SENSITIVE_PARAMETERS";
+
+    /**
+     * Default sensitive parameter names
+     */
+    private static final Set<String> DEFAULT_SENSITIVE_PARAMETERS =
+            Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+                    CommonConstants.USERNAME_KEY, // "username"
+                    CommonConstants.PASSWORD_KEY, // "password"
+                    "accessKey", // ACCESS_KEY
+                    "secretKey" // SECRET_KEY

Review Comment:
   Hard-coded string literals should use the constants from CommonConstants 
instead of inline strings with comments. Replace with 
`CommonConstants.ACCESS_KEY` and `CommonConstants.SECRET_KEY` to maintain 
consistency and avoid duplication.
   ```suggestion
                       CommonConstants.ACCESS_KEY, // "accessKey"
                       CommonConstants.SECRET_KEY // "secretKey"
   ```



##########
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java:
##########
@@ -1200,11 +1200,19 @@ public String toParameterString(String... parameters) {
     }
 
     protected void buildParameters(StringBuilder buf, boolean concat, String[] 
parameters) {
+        buildParameters(buf, concat, false, parameters);
+    }
+
+    protected void buildParameters(StringBuilder buf, boolean concat, boolean 
showSensitive, String[] parameters) {
         if (CollectionUtils.isNotEmptyMap(getParameters())) {
             List<String> includes = (ArrayUtils.isEmpty(parameters) ? null : 
Arrays.asList(parameters));
             boolean first = true;
             for (Map.Entry<String, String> entry : new 
TreeMap<>(getParameters()).entrySet()) {
-                if (StringUtils.isNotEmpty(entry.getKey()) && (includes == 
null || includes.contains(entry.getKey()))) {
+                String key = entry.getKey();
+                // Skip sensitive parameters in non-full string 
representations unless showSensitive is true
+                if (StringUtils.isNotEmpty(key)
+                        && (showSensitive || !isSensitiveParameter(key))
+                        && (includes == null || includes.contains(key))) {

Review Comment:
   The `isSensitiveParameter(key)` call is performed for every parameter even 
when `showSensitive` is true. Consider reordering the condition to 
`showSensitive || !isSensitiveParameter(key)` so the sensitive parameter check 
is skipped entirely when showing all parameters.



-- 
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: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to