fix(security): harden web_fetch and datasource connector SSRF paths
Use SSRF-safe HTTP clients in chat pipeline web_fetch and Feishu/Yuque/Notion connectors, validating tenant-supplied base_url values before outbound requests.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
)
|
||||
|
||||
// ValidateConnectorBaseURL checks a connector API base URL against the SSRF policy.
|
||||
// Empty rawURL is allowed; callers apply their own default before issuing requests.
|
||||
func ValidateConnectorBaseURL(rawURL string) error {
|
||||
url := strings.TrimSpace(rawURL)
|
||||
if url == "" {
|
||||
return nil
|
||||
}
|
||||
if !strings.Contains(url, "://") {
|
||||
url = "https://" + url
|
||||
}
|
||||
if err := utils.ValidateURLForSSRF(url); err != nil {
|
||||
return fmt.Errorf("base_url SSRF validation failed: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewConnectorHTTPClient returns an HTTP client with redirect and dial-time SSRF guards.
|
||||
func NewConnectorHTTPClient(timeout time.Duration) *http.Client {
|
||||
cfg := utils.DefaultSSRFSafeHTTPClientConfig()
|
||||
cfg.Timeout = timeout
|
||||
return utils.NewSSRFSafeHTTPClient(cfg)
|
||||
}
|
||||
Reference in New Issue
Block a user