Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
refactor: Sanitize log inputs in mcp_service, duckduckgo, auth, faq, message, and model handlers to enhance security
wizardchen8e3c2d85474b
diff --git a/internal/application/service/mcp_service.go b/internal/application/service/mcp_service.goindex 5cbf9768f..9fb1c32ae 100644--- a/internal/application/service/mcp_service.go+++ b/internal/application/service/mcp_service.go@@ -9,6 +9,7 @@ import ("github.com/Tencent/WeKnora/internal/mcp""github.com/Tencent/WeKnora/internal/types""github.com/Tencent/WeKnora/internal/types/interfaces"+ secutils "github.com/Tencent/WeKnora/internal/utils")// mcpServiceService implements MCPServiceService interface@@ -175,24 +176,24 @@ func (s *mcpServiceService) UpdateMCPService(ctx context.Context, service *typesif service.AuthConfig != nil {configChanged = true}-+ name := secutils.SanitizeForLog(existing.Name)// Close existing client connection if:// 1. Service is now disabled (need to close connection)// 2. Critical configuration changed (need to reconnect with new config)if !existing.Enabled {s.mcpManager.CloseClient(service.ID)- logger.GetLogger(ctx).Infof("MCP service disabled, connection closed: %s (ID: %s)", existing.Name, service.ID)+ logger.GetLogger(ctx).Infof("MCP service disabled, connection closed: %s (ID: %s)", name, service.ID)} else if configChanged {s.mcpManager.CloseClient(service.ID)- logger.GetLogger(ctx).Infof("MCP service config changed, connection closed for reconnect: %s (ID: %s)", existing.Name, service.ID)+ logger.GetLogger(ctx).Infof("MCP service config changed, connection closed for reconnect: %s (ID: %s)", name, service.ID)} else if oldEnabled != existing.Enabled && existing.Enabled {// Service was just enabled (was disabled, now enabled)// Close any existing connection to ensure clean states.mcpManager.CloseClient(service.ID)- logger.GetLogger(ctx).Infof("MCP service enabled, existing connection closed for clean state: %s (ID: %s)", existing.Name, service.ID)+ logger.GetLogger(ctx).Infof("MCP service enabled, existing connection closed for clean state: %s (ID: %s)", name, service.ID)}- logger.GetLogger(ctx).Infof("MCP service updated: %s (ID: %s), enabled: %v", existing.Name, service.ID, existing.Enabled)+ logger.GetLogger(ctx).Infof("MCP service updated: %s (ID: %s), enabled: %v", name, service.ID, existing.Enabled)return nil}@@ -215,7 +216,7 @@ func (s *mcpServiceService) DeleteMCPService(ctx context.Context, tenantID uint6return fmt.Errorf("failed to delete MCP service: %w", err)}- logger.GetLogger(ctx).Infof("MCP service deleted: %s (ID: %s)", existing.Name, id)+ logger.GetLogger(ctx).Infof("MCP service deleted: %s (ID: %s)", secutils.SanitizeForLog(existing.Name), id)return nil}diff --git a/internal/application/service/web_search/duckduckgo.go b/internal/application/service/web_search/duckduckgo.goindex 0b68c1084..d85b837cb 100644--- a/internal/application/service/web_search/duckduckgo.go+++ b/internal/application/service/web_search/duckduckgo.go@@ -15,6 +15,7 @@ import ("github.com/Tencent/WeKnora/internal/logger""github.com/Tencent/WeKnora/internal/types""github.com/Tencent/WeKnora/internal/types/interfaces"+ secutils "github.com/Tencent/WeKnora/internal/utils")// DuckDuckGoProvider implements web search using DuckDuckGo (HTML first, API fallback)@@ -74,7 +75,7 @@ func (p *DuckDuckGoProvider) searchHTML(ctx context.Context, query string, maxRe// print curl of requestcurlCommand := fmt.Sprintf("curl -X GET '%s' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'", req.URL.String())- logger.Infof(ctx, "Curl of request: %s", curlCommand)+ logger.Infof(ctx, "Curl of request: %s", secutils.SanitizeForLog(curlCommand))resp, err := p.client.Do(req)if err != nil {diff --git a/internal/handler/auth.go b/internal/handler/auth.goindex 463bb102a..b3173d0e6 100644--- a/internal/handler/auth.go+++ b/internal/handler/auth.go@@ -10,6 +10,7 @@ import ("github.com/Tencent/WeKnora/internal/logger""github.com/Tencent/WeKnora/internal/types""github.com/Tencent/WeKnora/internal/types/interfaces"+ secutils "github.com/Tencent/WeKnora/internal/utils")// AuthHandler implements HTTP request handlers for user authentication@@ -58,7 +59,8 @@ func (h *AuthHandler) Register(c *gin.Context) {c.Error(appErr)return}-+ req.Username = secutils.SanitizeForLog(req.Username)+ req.Email = secutils.SanitizeForLog(req.Email)// Call service to register useruser, err := h.userService.Register(ctx, &req)if err != nil {diff --git a/internal/handler/faq.go b/internal/handler/faq.goindex ee2d7cf62..70de46f85 100644--- a/internal/handler/faq.go+++ b/internal/handler/faq.go@@ -174,7 +174,7 @@ func (h *FAQHandler) SearchFAQ(c *gin.Context) {c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))return}-+ req.QueryText = secutils.SanitizeForLog(req.QueryText)entries, err := h.knowledgeService.SearchFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), &req)if err != nil {logger.ErrorWithFields(ctx, err, nil)diff --git a/internal/handler/message.go b/internal/handler/message.goindex f84a18c4d..76122fdab 100644--- a/internal/handler/message.go+++ b/internal/handler/message.go@@ -10,6 +10,7 @@ import ("github.com/Tencent/WeKnora/internal/errors""github.com/Tencent/WeKnora/internal/logger""github.com/Tencent/WeKnora/internal/types/interfaces"+ secutils "github.com/Tencent/WeKnora/internal/utils")// MessageHandler handles HTTP requests related to messages within chat sessions@@ -39,8 +40,8 @@ func (h *MessageHandler) LoadMessages(c *gin.Context) {// Get path parameters and query parameterssessionID := c.Param("session_id")- limit := c.DefaultQuery("limit", "20")- beforeTimeStr := c.DefaultQuery("before_time", "")+ limit := secutils.SanitizeForLog(c.DefaultQuery("limit", "20"))+ beforeTimeStr := secutils.SanitizeForLog(c.DefaultQuery("before_time", ""))logger.Infof(ctx, "Loading messages params, session ID: %s, limit: %s, before time: %s",sessionID, limit, beforeTimeStr)@@ -115,8 +116,8 @@ func (h *MessageHandler) DeleteMessage(c *gin.Context) {logger.Info(ctx, "Start deleting message")// Get path parameters for session and message identification- sessionID := c.Param("session_id")- messageID := c.Param("id")+ sessionID := secutils.SanitizeForLog(c.Param("session_id"))+ messageID := secutils.SanitizeForLog(c.Param("id"))logger.Infof(ctx, "Deleting message, session ID: %s, message ID: %s", sessionID, messageID)diff --git a/internal/handler/model.go b/internal/handler/model.goindex 929808754..16e3d9ebf 100644--- a/internal/handler/model.go+++ b/internal/handler/model.go@@ -84,7 +84,7 @@ func (h *ModelHandler) CreateModel(c *gin.Context) {c.Error(errors.NewBadRequestError(err.Error()))return}-+ req.Name = secutils.SanitizeForLog(req.Name)tenantID := c.GetUint64(types.TenantIDContextKey.String())if tenantID == 0 {logger.Error(ctx, "Tenant ID is empty")