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:
@@ -36,7 +36,7 @@ func newClient(cfg *Config) *client {
|
||||
return &client{
|
||||
baseURL: cfg.GetBaseURL(),
|
||||
token: cfg.APIToken,
|
||||
httpClient: &http.Client{Timeout: defaultTimeout},
|
||||
httpClient: datasource.NewConnectorHTTPClient(defaultTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,19 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost")
|
||||
secutils.ResetSSRFWhitelistForTest()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func makeDSConfig(f *fakeYuque, resourceIDs []string) *types.DataSourceConfig {
|
||||
return &types.DataSourceConfig{
|
||||
Type: types.ConnectorTypeYuque,
|
||||
|
||||
@@ -77,6 +77,9 @@ func parseYuqueConfig(config *types.DataSourceConfig) (*Config, error) {
|
||||
if strings.TrimSpace(cfg.APIToken) == "" {
|
||||
return nil, fmt.Errorf("%w: api_token is required", datasource.ErrInvalidCredentials)
|
||||
}
|
||||
if err := datasource.ValidateConnectorBaseURL(cfg.GetBaseURL()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user