From 7ab7db9b76198c56a4d85a2463c391d5a1f3e644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=87=E5=B3=B0?= Date: Thu, 9 Apr 2026 17:10:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B880=E3=80=81443=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crawler/fetcher.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/crawler/fetcher.go b/crawler/fetcher.go index d72a204..ee6e57e 100644 --- a/crawler/fetcher.go +++ b/crawler/fetcher.go @@ -394,28 +394,19 @@ func mustParseCIDR(s string) *net.IPNet { return network } -// isSafeRedirect 检查重定向目标是否安全(非内网 IP、非非标端口)。 +// isSafeRedirect 检查重定向目标是否安全(非内网 IP)。 // 用于防止 SSRF 攻击:恶意服务器将爬虫重定向到内网服务。 func isSafeRedirect(u *url.URL) error { host := u.Hostname() - port := u.Port() // 解析 IP 地址 ip := net.ParseIP(host) if ip == nil { - // 域名(非 IP),允许(DNS 解析由系统处理) - // 但非标端口仍需检查 - if port != "" && port != "80" && port != "443" { - return fmt.Errorf("blocked: non-standard port %s", port) - } + // 域名(非 IP),允许(DNS 解析由系统处理,端口不限) return nil } // IP 直连:检查是否为私有地址 if isPrivateIP(ip) { return fmt.Errorf("blocked: private IP %s", ip) } - // 非标端口检查 - if port != "" && port != "80" && port != "443" { - return fmt.Errorf("blocked: non-standard port %s", port) - } return nil }