refactor: 移除安全校验和长度限制,简化输入处理逻辑
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Tencent/WeKnora/internal/types"
|
"github.com/Tencent/WeKnora/internal/types"
|
||||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PluginIntoChatMessage handles the transformation of search results into chat messages
|
// PluginIntoChatMessage handles the transformation of search results into chat messages
|
||||||
@@ -60,18 +59,9 @@ func (p *PluginIntoChatMessage) OnEvent(ctx context.Context,
|
|||||||
weekdayName := []string{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
|
weekdayName := []string{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
|
||||||
var userContent bytes.Buffer
|
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
|
// Execute template with context data
|
||||||
err = tmpl.Execute(&userContent, map[string]interface{}{
|
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
|
"Contexts": passages, // Extracted passages from search results
|
||||||
"CurrentTime": time.Now().Format("2006-01-02 15:04:05"), // Formatted current time
|
"CurrentTime": time.Now().Format("2006-01-02 15:04:05"), // Formatted current time
|
||||||
"CurrentWeek": weekdayName[time.Now().Weekday()], // Current weekday in Chinese
|
"CurrentWeek": weekdayName[time.Now().Weekday()], // Current weekday in Chinese
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/Tencent/WeKnora/internal/logger"
|
"github.com/Tencent/WeKnora/internal/logger"
|
||||||
"github.com/Tencent/WeKnora/internal/types"
|
"github.com/Tencent/WeKnora/internal/types"
|
||||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||||
"github.com/Tencent/WeKnora/internal/utils"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -253,7 +252,7 @@ func (s *knowledgeTagService) enqueueIndexDeleteTask(ctx context.Context,
|
|||||||
return
|
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)
|
info, err := s.task.Enqueue(task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf(ctx, "Failed to enqueue index delete task: %v", err)
|
logger.Errorf(ctx, "Failed to enqueue index delete task: %v", err)
|
||||||
|
|||||||
@@ -68,11 +68,6 @@ func ValidateInput(input string) (string, bool) {
|
|||||||
return "", true
|
return "", true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查长度
|
|
||||||
if len(input) > 10000 {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否包含控制字符
|
// 检查是否包含控制字符
|
||||||
for _, r := range input {
|
for _, r := range input {
|
||||||
if r < 32 && r != 9 && r != 10 && r != 13 {
|
if r < 32 && r != 9 && r != 10 && r != 13 {
|
||||||
@@ -197,11 +192,6 @@ func SanitizeForLog(input string) string {
|
|||||||
|
|
||||||
sanitized = builder.String()
|
sanitized = builder.String()
|
||||||
|
|
||||||
// 限制长度,防止日志溢出
|
|
||||||
if len(sanitized) > 1000 {
|
|
||||||
sanitized = sanitized[:1000] + "...[truncated]"
|
|
||||||
}
|
|
||||||
|
|
||||||
return sanitized
|
return sanitized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user