feat: implement SSRF-safe HTTP client

Add SSRF protection by validating redirect targets and resolved IPs,
blocking internal hostnames, restricted suffixes, and private IP ranges
including Docker and Kubernetes internal endpoints.
This commit is contained in:
wizardchen
2026-01-26 11:28:51 +08:00
committed by lyingbug
parent 01d1aeab0e
commit 67f3423e9b
2 changed files with 123 additions and 4 deletions
+6 -4
View File
@@ -74,11 +74,13 @@ type WebFetchTool struct {
// NewWebFetchTool creates a new web_fetch tool instance
func NewWebFetchTool(chatModel chat.Chat) *WebFetchTool {
// Use SSRF-safe HTTP client to prevent redirect-based SSRF attacks
ssrfConfig := utils.DefaultSSRFSafeHTTPClientConfig()
ssrfConfig.Timeout = webFetchTimeout
return &WebFetchTool{
BaseTool: webFetchTool,
client: &http.Client{
Timeout: webFetchTimeout,
},
BaseTool: webFetchTool,
client: utils.NewSSRFSafeHTTPClient(ssrfConfig),
chatModel: chatModel,
}
}