Skip to content

Fix the IP and port verification logic during service registration#846

Open
lengyue1084 wants to merge 5 commits intonacos-group:masterfrom
lengyue1084:fix-validation
Open

Fix the IP and port verification logic during service registration#846
lengyue1084 wants to merge 5 commits intonacos-group:masterfrom
lengyue1084:fix-validation

Conversation

@lengyue1084
Copy link

-Added legitimacy verification for IP addresses and domain names
-Added validity check for port numbers to ensure they are within the valid range

-Added ValidIPAddress function to validate the validity of IPv4 and IPv6 addresses
-The function returns nil to indicate validity, otherwise it returns an error message - introducing strings package to support string processing
-Implemented the VerifiDomain function to validate domain name format - check domain name length, label length, character composition, etc
-Added the isAllDigits auxiliary function to check if the string contains all digits
…vice registration

-Added legitimacy verification for IP addresses and domain names
-Added validity check for port numbers to ensure they are within the valid range
@CLAassistant
Copy link

CLAassistant commented Sep 12, 2025

CLA assistant check
All committers have signed the CLA.

@lingma-agents
Copy link

lingma-agents bot commented Sep 12, 2025

修复服务注册时的IP和端口验证逻辑

变更概述
  • 问题修复

    • 修复了服务注册过程中对IP地址和域名的合法性验证逻辑
    • 增加了对端口有效性的检查,确保端口号在有效范围内(1-65535)
    • 实现了更严格的域名格式验证,包括长度、标签格式、字符合法性等
    • 通过新增的验证函数 ValidateIPAddressValidateDomain 提高了输入参数的健壮性
  • 新功能

    • util 包中新增了两个验证函数:
      • ValidateIPAddress:用于验证IPv4或IPv6地址的有效性
      • ValidateDomain:用于验证域名格式是否符合RFC标准
    • 引入辅助函数 isAllDigits 来支持域名顶级域的数字检查
  • 实现细节

    • RegisterInstance 方法中添加了对 param.Ip 的双重验证(IP地址和域名)
    • 端口验证确保其值大于0且不超过 math.MaxUint16(即65535)
    • 域名验证涵盖了以下规则:
      • 总长度不超过253个字符
      • 不包含连续的点号
      • 每个标签不超过63个字符且不以连字符开头或结尾
      • 顶级域不能全为数字
      • 标签只能包含字母、数字和连字符
变更文件
文件路径 变更说明
clients/​naming_​client/​naming_​client.​go 在服务注册前增加了对IP地址和端口号的合法性验证,防止无效参数被注册。
util/common.go 新增了IP地址和域名验证函数,以及相关辅助函数,为服务注册提供基础校验能力。

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

…URLs

-Modify the ValidDomain function to support processing full URLs (with http://or https://prefix)
-Remove paths, query parameters, and fragments from the domain name
-Remove ports from the domain name
-Update the IP and domain name verification logic in the named client
@Sunrisea
Copy link
Member

The IP field allows users to enter a domain name. Is it appropriate to perform format validation here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants