Documentation
¶
Overview ¶
Package validator 提供了配置验证功能。 包括 URL 验证、路径验证等安全验证功能。
Package validator 提供了数据验证功能。 支持手机号和邮箱格式验证,支持多个国家/地区的手机号格式。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfigPath ¶
ValidateConfigPath 验证配置文件路径,防止路径遍历攻击
该函数对配置文件路径进行验证,包括: - 检查路径是否包含路径遍历字符(..) - 验证路径是否为绝对路径或相对路径 - 可选:限制配置文件只能从特定目录读取
参数:
- path: 要验证的文件路径
- allowedDirs: 允许的目录列表(可选,如果为空则不限制目录)
返回:
- string: 规范化后的绝对路径
- error: 如果路径无效或存在安全风险,返回错误;否则返回 nil
func ValidateRemoteURL ¶
ValidateRemoteURL 验证远程配置 URL,防止 SSRF 攻击
该函数对远程配置 URL 进行严格验证,包括: - 只允许 http:// 和 https:// 协议 - 禁止访问私有 IP 地址(10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8) - 禁止访问 localhost - 验证 URL 格式的有效性
参数:
- urlStr: 要验证的 URL 字符串
返回:
- error: 如果 URL 无效或存在安全风险,返回错误;否则返回 nil
Types ¶
type ValidationError ¶
ValidationError 验证错误
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Click to show internal directories.
Click to hide internal directories.