feat(web_fetch): enhance web fetch tool with DNS pinning and validation improvements

- Introduced a new validatedParams struct to hold validated input along with DNS-pinned host/IP for SSRF protection.
- Updated the validateParams function to validate and resolve the host to a single public IP, ensuring safe outbound fetches.
- Modified executeFetch and fetchHTMLContent methods to utilize the new validatedParams for improved security and clarity.
- Enhanced logging to reflect the display URL and provide better context during fetch operations.

This update strengthens the web fetch tool's security against SSRF attacks and improves the overall robustness of URL handling.
This commit is contained in:
wizardchen
2026-02-02 11:03:30 +08:00
committed by lyingbug
parent a5d1233b96
commit 2b3f76e418
2 changed files with 112 additions and 43 deletions
+11 -4
View File
@@ -244,6 +244,13 @@ func isRestrictedIP(ip net.IP) (bool, string) {
return false, ""
}
// IsPublicIP returns true if the IP is safe for outbound fetch (not private, loopback, link-local, etc.).
// Used for DNS pinning: after resolving a hostname we pick the first public IP and pin all requests to it.
func IsPublicIP(ip net.IP) bool {
restricted, _ := isRestrictedIP(ip)
return !restricted
}
// isZeros checks if a byte slice is all zeros
func isZeros(b []byte) bool {
for _, v := range b {
@@ -652,10 +659,10 @@ func ValidateStdioConfig(command string, args []string, envVars map[string]strin
// SSRFSafeHTTPClientConfig contains configuration for the SSRF-safe HTTP client
type SSRFSafeHTTPClientConfig struct {
Timeout time.Duration
MaxRedirects int
DisableKeepAlives bool
DisableCompression bool
Timeout time.Duration
MaxRedirects int
DisableKeepAlives bool
DisableCompression bool
}
// DefaultSSRFSafeHTTPClientConfig returns the default configuration