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:
wizardchen
2026-07-02 12:21:39 +08:00
committed by lyingbug
parent 1d322c525a
commit 8325dac738
13 changed files with 179 additions and 66 deletions
@@ -12,6 +12,7 @@ import (
"sync"
"time"
"github.com/Tencent/WeKnora/internal/datasource"
"github.com/Tencent/WeKnora/internal/logger"
)
@@ -55,7 +56,7 @@ func NewClient(config *Config) *Client {
baseURL: config.GetBaseURL(),
appID: config.AppID,
appSecret: config.AppSecret,
httpClient: &http.Client{Timeout: 30 * time.Second},
httpClient: datasource.NewConnectorHTTPClient(30 * time.Second),
}
}
@@ -10,6 +10,7 @@ import (
"time"
"unicode/utf8"
"github.com/Tencent/WeKnora/internal/datasource"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/types"
)
@@ -499,6 +500,10 @@ func parseFeishuConfig(config *types.DataSourceConfig) (*Config, error) {
return nil, fmt.Errorf("feishu app_id and app_secret are required")
}
if err := datasource.ValidateConnectorBaseURL(feishuConfig.GetBaseURL()); err != nil {
return nil, err
}
return &feishuConfig, nil
}
@@ -6,14 +6,22 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"time"
"unicode/utf8"
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())
}
// ──────────────────────────────────────────────────────────────────────
// Fake Feishu API server
// ──────────────────────────────────────────────────────────────────────
@@ -374,13 +382,13 @@ func TestParseFeishuConfig(t *testing.T) {
Credentials: map[string]interface{}{
"app_id": "id1",
"app_secret": "sec1",
"base_url": "https://custom.example.com",
"base_url": "https://open.feishu.cn",
},
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg.AppID != "id1" || cfg.AppSecret != "sec1" || cfg.BaseURL != "https://custom.example.com" {
if cfg.AppID != "id1" || cfg.AppSecret != "sec1" || cfg.BaseURL != "https://open.feishu.cn" {
t.Errorf("unexpected config: %+v", cfg)
}
})