From 475e35385079e6cd938d1864888c7f8593d81f60 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Mon, 13 Jul 2026 16:26:17 +0800 Subject: [PATCH] =?UTF-8?q?httpclient:=20=E6=B8=85=E7=90=86=20ssrf.go=20S1?= =?UTF-8?q?017=20lint=20=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit matchAllowedHost 里两处 if strings.HasPrefix(...) pattern = pattern[N:] 替成无条件 strings.TrimPrefix, 行为完全等价 (前缀不匹配时 TrimPrefix 是 no-op). 触发 S1017 (Should replace this if statement with an unconditional strings.TrimPrefix). 净 -4 行, 函数语义不变, matchAllowedHost 现有测试 (ssrf_test.go) 覆盖的精确/后缀/wildcard 三种 host 匹配路径都不变. Co-Authored-By: Claude --- internal/httpclient/ssrf.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/httpclient/ssrf.go b/internal/httpclient/ssrf.go index 201cab3..311e380 100644 --- a/internal/httpclient/ssrf.go +++ b/internal/httpclient/ssrf.go @@ -116,12 +116,8 @@ func matchAllowedHost(host, pattern string) bool { return true } - if strings.HasPrefix(pattern, "*.") { - pattern = pattern[2:] - } - if strings.HasPrefix(pattern, ".") { - pattern = pattern[1:] - } + pattern = strings.TrimPrefix(pattern, "*.") + pattern = strings.TrimPrefix(pattern, ".") return host == pattern || strings.HasSuffix(host, "."+pattern) }