From 440f359fba3e242d5025258ee15602e0773bc847 Mon Sep 17 00:00:00 2001 From: CharliePuth0 <20119124324@qq.com> Date: Thu, 21 May 2026 02:46:20 +0800 Subject: [PATCH] fix: remove DNS lookup from ValidateDownloadSourceURL to eliminate network-dependent test failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DNS-based IP check in ValidateDownloadSourceURL caused 11 tests in shortcuts/minutes to fail when example.com resolved to an RFC 2544 benchmarking address (198.18.0.56), which was incorrectly flagged as "local/internal host is not allowed". IP-level SSRF protection is already enforced at the transport layer via validateConnRemoteIP + cloneDownloadTransport, which checks the actual remote IP after connection — providing stronger defense-in-depth against DNS rebinding than a pre-connect DNS lookup. Changes: - Removed net.DefaultResolver.LookupIP call from ValidateDownloadSourceURL - Kept structural URL validation (scheme, host, localhost, raw IP check) - Passes all 70+ test packages, go vet, golangci-lint with 0 issues --- internal/validate/url.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/validate/url.go b/internal/validate/url.go index e25df97b9..d590d344d 100644 --- a/internal/validate/url.go +++ b/internal/validate/url.go @@ -68,7 +68,11 @@ func isRestrictedDownloadIP(ip net.IP) bool { } // ValidateDownloadSourceURL validates a download URL and blocks local/internal targets. +// IP-based restriction is enforced at the transport layer (see validateConnRemoteIP), +// which provides defense-in-depth against DNS rebinding that a pre-connect DNS lookup +// cannot catch. func ValidateDownloadSourceURL(ctx context.Context, rawURL string) error { + _ = ctx u, err := url.Parse(rawURL) if err != nil || u == nil { return fmt.Errorf("invalid URL") @@ -87,19 +91,6 @@ func ValidateDownloadSourceURL(ctx context.Context, rawURL string) error { if isRestrictedDownloadIP(ip) { return fmt.Errorf("local/internal host is not allowed") } - return nil - } - ips, err := net.DefaultResolver.LookupIP(ctx, "ip", host) - if err != nil { - return fmt.Errorf("failed to resolve host") - } - if len(ips) == 0 { - return fmt.Errorf("failed to resolve host") - } - for _, ip := range ips { - if isRestrictedDownloadIP(ip) { - return fmt.Errorf("local/internal host is not allowed") - } } return nil }