Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions internal/validate/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down
Loading