Skip to content

Update ClientBasicParamUtil.java #13537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged

Conversation

rst-coding
Copy link
Contributor

@rst-coding rst-coding commented Jun 21, 2025

CWE-532 – Nacos 客户端 ACCESS_KEY 改为密文日志记录

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

XXXXX

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

CWE-532 – Nacos 客户端 ACCESS_KEY  改为密文日志记录
@CLAassistant
Copy link

CLAassistant commented Jun 21, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

lingma-agents bot commented Jun 21, 2025

修复CWE-532漏洞:对Nacos客户端ACCESS_KEY日志记录进行加密

变更概述

安全增强

  • 组件ClientBasicParamUtil.java
  • 功能描述:在参数日志记录时对ACCESS_KEY进行密文处理,防止敏感信息明文泄露
  • 实现细节:修改appendKeyParameters调用参数,将PropertyKeyConst.ACCESS_KEY的加密标志从false改为true
  • 修复依据:响应CWE-532(明文存储敏感数据)安全漏洞,确保认证凭证在日志系统中以密文形式存储
变更文件
文件路径 变更说明
client-basic/​src/​main/​java/​com/​alibaba/​nacos/​client/​utils/​ClientBasicParamUtil.​java 将ACCESS_KEY参数的日志记录加密标志从false改为true,实现敏感信息脱敏

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @lingma-agents 分析这个方法的性能瓶颈并提供优化建议。

  • @lingma-agents 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @lingma-agents 请总结上述讨论并提出解决方案。

  • @lingma-agents 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 代码评审报告

🎯 评审意见概览
严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 0 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 0 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 1 次要问题,酬情优化。例如:代码格式不规范或注释缺失。

总计: 1 个问题

📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
☕ client-basic/src/main/java/com/alibaba/nacos/client/utils/ClientBasicParamUtil.java (1 💬)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. 敏感参数加密策略不一致可能导致安全漏洞

appendKeyParameters方法中,第三个参数控制敏感数据的加密标记。当前修改将ACCESS_KEY的加密标记从false改为true,但需要检查其他敏感参数(如PASSWORD、SECRET_KEY)是否均遵循统一加密策略。若存在参数未正确设置加密标记,可能导致敏感信息明文传输。建议统一敏感参数的加密标记规则,并补充加密策略文档说明。

📌 关键代码

appendKeyParameters(result, properties, PropertyKeyConst.PASSWORD, true);
appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
appendKeyParameters(result, properties, PropertyKeyConst.SECRET_KEY, true);

⚠️ 潜在风险

未加密的敏感参数可能通过接口明文暴露,增加数据泄露风险

🔍2. 布尔参数语义不明确引发维护风险

方法appendKeyParameters的第三个布尔参数功能未在方法定义或文档中明确说明(尽管已有文件级注释建议),这可能导致后续开发者误用参数。建议将布尔参数改为枚举类型或补充详细方法注释,明确参数代表的加密/脱敏行为。

📌 关键代码

appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);

⚠️ 潜在风险

参数误用导致加密逻辑失效或数据处理错误

🔍3. 跨模块参数处理规范缺失

需要确认其他模块(如服务端参数处理模块)是否与客户端参数加密策略保持一致。若存在加密标记不一致的情况,可能导致前后端数据解析错误或安全漏洞。建议建立全局参数加密规范文档并同步到相关模块。

⚠️ 潜在风险

模块间参数处理不一致引发系统级数据解析错误

审查详情
📒 文件清单 (1 个文件)
📝 变更: 1 个文件

📝 变更文件:

  • client-basic/src/main/java/com/alibaba/nacos/client/utils/ClientBasicParamUtil.java

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @lingma-agents 分析这个方法的性能瓶颈并提供优化建议。

  • @lingma-agents 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @lingma-agents 请总结上述讨论并提出解决方案。

  • @lingma-agents 请根据讨论内容生成优化代码。

@@ -207,7 +207,7 @@ public static String getInputParameters(Properties properties) {
appendKeyParameters(result, properties, PropertyKeyConst.ENDPOINT_PORT, false);
appendKeyParameters(result, properties, PropertyKeyConst.USERNAME, false);
appendKeyParameters(result, properties, PropertyKeyConst.PASSWORD, true);
appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, false);
appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议为appendKeyParameters方法的第三个参数添加注释说明其用途

🟢 Minor | 🧹 Code Smells

📋 问题详情

当前代码中appendKeyParameters方法的第三个参数(布尔值)未明确其含义(如是否隐藏敏感信息)。添加注释可提高代码可读性,帮助开发者理解参数作用。

💡 解决方案

在参数列表上方添加注释说明第三个参数含义:

+    // 第三个参数表示是否隐藏敏感值(true表示脱敏)
    appendKeyParameters(result, properties, PropertyKeyConst.ENDPOINT_PORT, false);
    appendKeyParameters(result, properties, PropertyKeyConst.USERNAME, false);
    appendKeyParameters(result, properties, PropertyKeyConst.PASSWORD, true);
    appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
    appendKeyParameters(result, properties, PropertyKeyConst.SECRET_KEY, true);
    appendKeyParameters(result, properties, PropertyKeyConst.RAM_ROLE_NAME, false);
    appendKeyParameters(result, properties, PropertyKeyConst.SIGNATURE_REGION_ID, false);

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@rst-coding rst-coding closed this Jun 21, 2025
@rst-coding rst-coding reopened this Jun 21, 2025
Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 代码评审报告

🎯 评审意见概览
严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 0 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 0 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 1 次要问题,酬情优化。例如:代码格式不规范或注释缺失。

总计: 1 个问题

📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
☕ client-basic/src/main/java/com/alibaba/nacos/client/utils/ClientBasicParamUtil.java (1 💬)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. 敏感参数加密策略跨模块一致性风险

在ClientBasicParamUtil.java中新增的ACCESS_KEY参数加密标记为true,但需确认系统其他组件是否同步处理该参数的加密逻辑。例如,若存在其他模块直接读取未解密的ACCESS_KEY值,或在传输过程中未进行加密处理,可能导致安全漏洞。建议检查所有使用PropertyKeyConst.ACCESS_KEY的代码位置,确保加密/解密操作与参数标记保持一致。

📌 关键代码

+            appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);

⚠️ 潜在风险

若其他模块未同步处理加密逻辑,可能导致明文传输或存储敏感信息,增加被窃取风险

🔍2. 参数配置管理存在重复代码风险

ClientBasicParamUtil.java中连续调用appendKeyParameters处理多个参数,但未采用集中式配置管理。这种分散式硬编码方式可能导致参数维护困难,新增参数时容易遗漏加密标记。建议将参数与加密标记配置为Map或枚举集合,通过循环统一处理,减少重复代码并提升扩展性。

📌 关键代码

appendKeyParameters(result, properties, PropertyKeyConst.USERNAME, false);
appendKeyParameters(result, properties, PropertyKeyConst.PASSWORD, true);
+appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
appendKeyParameters(result, properties, PropertyKeyConst.SECRET_KEY, true);

⚠️ 潜在风险

新增参数时可能因重复代码导致配置错误,增加维护成本和潜在安全风险

🔍3. 缺乏参数加密的端到端测试覆盖

新增的ACCESS_KEY参数加密功能未在单元测试中体现。建议补充测试用例验证:1) 加密参数在输出中的正确掩码显示 2) 加密参数在系统内部处理时的正确解密恢复。当前测试仅关注参数收集,未验证加密逻辑的实际效果。

⚠️ 潜在风险

无法确保加密功能在复杂场景下正常工作,可能遗留未被发现的安全缺陷

审查详情
📒 文件清单 (1 个文件)
📝 变更: 1 个文件

📝 变更文件:

  • client-basic/src/main/java/com/alibaba/nacos/client/utils/ClientBasicParamUtil.java

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @lingma-agents 分析这个方法的性能瓶颈并提供优化建议。

  • @lingma-agents 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @lingma-agents 请总结上述讨论并提出解决方案。

  • @lingma-agents 请根据讨论内容生成优化代码。

@@ -207,7 +207,7 @@ public static String getInputParameters(Properties properties) {
appendKeyParameters(result, properties, PropertyKeyConst.ENDPOINT_PORT, false);
appendKeyParameters(result, properties, PropertyKeyConst.USERNAME, false);
appendKeyParameters(result, properties, PropertyKeyConst.PASSWORD, true);
appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, false);
appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为敏感参数添加注释说明加密需求

🟢 Minor | 🧹 Code Smells

📋 问题详情

新增的ACCESS_KEY参数调用appendKeyParameters时未添加注释,导致后续维护者难以理解true参数的具体含义(如是否需要加密存储)。敏感参数的处理逻辑需要明确标注,以提升代码可维护性和安全性。

💡 解决方案

在代码行末尾添加注释说明参数用途:

- appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true);
+ appendKeyParameters(result, properties, PropertyKeyConst.ACCESS_KEY, true); // 敏感参数,需加密存储

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@rst-coding
Copy link
Contributor Author

issues编号 #13494

@wuyfee
Copy link

wuyfee commented Jun 23, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

@KomachiSion KomachiSion modified the milestones: 2.5.2, 3.0.2 Jun 23, 2025
@KomachiSion KomachiSion added kind/enhancement Category issues or prs related to enhancement. area/Client Related to Nacos Client SDK labels Jun 23, 2025
@KomachiSion KomachiSion merged commit 5906b49 into alibaba:develop Jun 23, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Client Related to Nacos Client SDK kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants