oxsean commented on code in PR #15699: URL: https://github.com/apache/dubbo/pull/15699#discussion_r2366241957
########## 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 { Review Comment: I think this has been made unnecessarily complicated. There’s no need to introduce such a complex SensitiveParameterConfig class just for a single configuration item. We should keep the code as simple as possible and only implement what’s truly necessary. The more code we add, the higher the complexity and the lower the maintainability — less is more. My suggestion: 1. Simply add SensitiveParameterNames and isSensitiveParameterNames in `org.apache.dubbo.common.config.ConfigurationUtils` like this: ``` org/apache/dubbo/common/constants/CommonConstants.java: String SENSITIVE_PARAMETER_NAMES = "dubbo.url.sensitive-parameter-names"; org/apache/dubbo/common/config/ConfigurationUtils.java private static volatile Set<String> SensitiveParameterNames; public static boolean isSensitiveParameter(URL url, String name) { if (SensitiveParameterNames == null) { synchronized (ConfigurationUtils.class) { if (SensitiveParameterNames == null) { String value = getProperty(url.getOrDefaultApplicationModel(), SENSITIVE_PARAMETER_NAMES); String[] names; if (value == null) { names = new String[] {CommonConstants.PASSWORD_KEY, "secretKey"}; } else { names = StringUtils.tokenize(value); } SensitiveParameterNames = new HashSet<>(Arrays.asList(names)); } } } return SensitiveParameterNames.contains(name); } ``` ########## 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" Review Comment: I suggest keeping name and id, or simply not adding a default value at all. Otherwise, users who rely on username for certain analyses will lose that information. ########## 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) + && (!isSensitiveParameter(key) || showSensitive) Review Comment: (!isSensitiveParameter(key) || showSensitive) to (showSensitive && !isSensitiveParameter(key)) ########## dubbo-common/src/main/java/org/apache/dubbo/config/RegistryConfig.java: ########## @@ -205,6 +205,21 @@ public class RegistryConfig extends AbstractConfig { */ private String secure; + /** + * Namespace for MSE Nacos registry. + */ + private String namespace; Review Comment: Why add this? It's a common configuration class. ########## 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) { Review Comment: showSensitive -> withSensitive -- 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]
