Copilot commented on code in PR #15699: URL: https://github.com/apache/dubbo/pull/15699#discussion_r2366161341
########## 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) + && (includes == null || includes.contains(key))) { Review Comment: [nitpick] The boolean logic condition is complex and could benefit from being extracted into a well-named helper method like `shouldIncludeParameter(key, showSensitive, includes)` for better readability. ########## 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: The comments indicate these should be constants (ACCESS_KEY, SECRET_KEY), but string literals are used instead. Consider defining these as constants in CommonConstants for consistency and maintainability. ```suggestion CommonConstants.ACCESS_KEY, // "accessKey" CommonConstants.SECRET_KEY // "secretKey" ``` ########## dubbo-common/src/main/java/org/apache/dubbo/config/RegistryConfig.java: ########## @@ -269,9 +310,27 @@ public void setAddress(String address) { updatePropertyIfAbsent(this::getProtocol, this::setProtocol, url.getProtocol()); updatePropertyIfAbsent(this::getPort, this::setPort, url.getPort()); + // Extract MSE Nacos specific parameters + updatePropertyIfAbsent(this::getNamespace, this::setNamespace, url.getParameter("namespace")); + updatePropertyIfAbsent(this::getAccessKey, this::setAccessKey, url.getParameter("accessKey")); + updatePropertyIfAbsent(this::getSecretKey, this::setSecretKey, url.getParameter("secretKey")); + + // Extract timeout parameter + String timeoutStr = url.getParameter("timeout"); + if (timeoutStr != null) { + try { + updatePropertyIfAbsent(this::getTimeout, this::setTimeout, Integer.valueOf(timeoutStr)); + } catch (NumberFormatException ignored) { + // Ignore invalid timeout values + } + } + Map<String, String> params = url.getParameters(); if (CollectionUtils.isNotEmptyMap(params)) { params.remove(BACKUP_KEY); + // Remove sensitive parameters from the parameters map to prevent exposure + params.remove("accessKey"); + params.remove("secretKey"); Review Comment: Hard-coded parameter names should be replaced with constants. Consider using the same parameter names that are defined in SensitiveParameterConfig or creating constants for these strings to ensure consistency. -- 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