refactor: 移除安全校验和长度限制,简化输入处理逻辑

This commit is contained in:
wizardchen
2025-12-25 19:17:48 +08:00
committed by lyingbug
parent 0e5370c7c4
commit be1ec4de5d
3 changed files with 2 additions and 23 deletions
@@ -11,7 +11,6 @@ import (
"time"
"github.com/Tencent/WeKnora/internal/types"
secutils "github.com/Tencent/WeKnora/internal/utils"
)
// PluginIntoChatMessage handles the transformation of search results into chat messages
@@ -60,18 +59,9 @@ func (p *PluginIntoChatMessage) OnEvent(ctx context.Context,
weekdayName := []string{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
var userContent bytes.Buffer
// 验证用户查询的安全性
safeQuery, isValid := secutils.ValidateInput(chatManage.Query)
if !isValid {
pipelineWarn(ctx, "IntoChatMessage", "invalid_query", map[string]interface{}{
"session_id": chatManage.SessionID,
})
return ErrTemplateExecute.WithError(fmt.Errorf("用户查询包含非法内容"))
}
// Execute template with context data
err = tmpl.Execute(&userContent, map[string]interface{}{
"Query": safeQuery, // User's original query
"Query": chatManage.Query, // User's original query
"Contexts": passages, // Extracted passages from search results
"CurrentTime": time.Now().Format("2006-01-02 15:04:05"), // Formatted current time
"CurrentWeek": weekdayName[time.Now().Weekday()], // Current weekday in Chinese
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"github.com/Tencent/WeKnora/internal/utils"
"github.com/google/uuid"
"github.com/hibiken/asynq"
"gorm.io/gorm"
@@ -253,7 +252,7 @@ func (s *knowledgeTagService) enqueueIndexDeleteTask(ctx context.Context,
return
}
task := asynq.NewTask(types.TypeIndexDelete, payloadBytes, asynq.Queue(utils.GetAsynqQueueName("low")), asynq.MaxRetry(10))
task := asynq.NewTask(types.TypeIndexDelete, payloadBytes, asynq.Queue("low"), asynq.MaxRetry(10))
info, err := s.task.Enqueue(task)
if err != nil {
logger.Errorf(ctx, "Failed to enqueue index delete task: %v", err)
-10
View File
@@ -68,11 +68,6 @@ func ValidateInput(input string) (string, bool) {
return "", true
}
// 检查长度
if len(input) > 10000 {
return "", false
}
// 检查是否包含控制字符
for _, r := range input {
if r < 32 && r != 9 && r != 10 && r != 13 {
@@ -197,11 +192,6 @@ func SanitizeForLog(input string) string {
sanitized = builder.String()
// 限制长度,防止日志溢出
if len(sanitized) > 1000 {
sanitized = sanitized[:1000] + "...[truncated]"
}
return sanitized
}