refactor: Sanitize log inputs in FAQ, Knowledge, and KnowledgeBase handlers to enhance security

This commit is contained in:
wizardchen
2025-11-26 19:52:07 +08:00
parent 85caee044a
commit 06a1c96cf2
4 changed files with 31 additions and 14 deletions
+7 -1
View File
@@ -32,7 +32,7 @@ func (h *FAQHandler) ListEntries(c *gin.Context) {
return
}
tagID := c.Query("tag_id")
tagID := secutils.SanitizeForLog(c.Query("tag_id"))
result, err := h.knowledgeService.ListFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), &page, tagID)
if err != nil {
@@ -177,6 +177,12 @@ func (h *FAQHandler) SearchFAQ(c *gin.Context) {
return
}
req.QueryText = secutils.SanitizeForLog(req.QueryText)
if req.MatchCount <= 0 {
req.MatchCount = 10
}
if req.MatchCount > 200 {
req.MatchCount = 200
}
entries, err := h.knowledgeService.SearchFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), &req)
if err != nil {
logger.ErrorWithFields(ctx, err, nil)