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 }