feat: Add JWT_SECRET configuration to .env.example and enhance pagination validation in chunk handler

This commit is contained in:
wizardchen
2025-11-26 17:58:31 +08:00
parent b4ae609103
commit d41f8afe55
5 changed files with 37 additions and 8 deletions
+4
View File
@@ -59,6 +59,10 @@ TENANT_AES_KEY=weknorarag-api-key-secret-secret
# 是否开启知识图谱构建和检索(构建阶段需调用大模型,耗时较长) # 是否开启知识图谱构建和检索(构建阶段需调用大模型,耗时较长)
ENABLE_GRAPH_RAG=false ENABLE_GRAPH_RAG=false
# 配置 JWT_SECRET 用于前端登录刷新Token
JWT_SECRET=weknora-jwt-secret
# MinIO端口 # MinIO端口
# MINIO_PORT=9000 # MINIO_PORT=9000
+9
View File
@@ -98,6 +98,15 @@ func (h *ChunkHandler) ListKnowledgeChunks(c *gin.Context) {
c.Error(errors.NewBadRequestError(err.Error())) c.Error(errors.NewBadRequestError(err.Error()))
return return
} }
if pagination.Page < 1 {
pagination.Page = 1
}
if pagination.PageSize < 1 {
pagination.PageSize = 10
}
if pagination.PageSize > 100 {
pagination.PageSize = 100
}
chunkType := []types.ChunkType{types.ChunkTypeText} chunkType := []types.ChunkType{types.ChunkTypeText}
+4 -2
View File
@@ -149,12 +149,14 @@ func (h *FAQHandler) DeleteEntries(c *gin.Context) {
ctx := c.Request.Context() ctx := c.Request.Context()
var req faqDeleteRequest var req faqDeleteRequest
if err := c.ShouldBindJSON(&req); err != nil { if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to bind FAQ delete payload", err) logger.Errorf(ctx, "Failed to bind FAQ delete payload: %s", secutils.SanitizeForLog(err.Error()))
c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error())) c.Error(errors.NewBadRequestError("请求参数不合法").WithDetails(err.Error()))
return return
} }
if err := h.knowledgeService.DeleteFAQEntries(ctx, secutils.SanitizeForLog(c.Param("id")), req.IDs); err != nil { if err := h.knowledgeService.DeleteFAQEntries(ctx,
secutils.SanitizeForLog(c.Param("id")),
secutils.SanitizeForLogArray(req.IDs)); err != nil {
logger.ErrorWithFields(ctx, err, nil) logger.ErrorWithFields(ctx, err, nil)
c.Error(err) c.Error(err)
return return
+2 -1
View File
@@ -123,7 +123,8 @@ func (h *Handler) KnowledgeQA(c *gin.Context) {
// Use shared function to handle KnowledgeQA request // Use shared function to handle KnowledgeQA request
h.handleKnowledgeQARequest(ctx, c, session, secutils.SanitizeForLog(request.Query), h.handleKnowledgeQARequest(ctx, c, session, secutils.SanitizeForLog(request.Query),
knowledgeBaseIDs, assistantMessage, true, secutils.SanitizeForLog(request.SummaryModelID), request.WebSearchEnabled) secutils.SanitizeForLogArray(knowledgeBaseIDs),
assistantMessage, true, secutils.SanitizeForLog(request.SummaryModelID), request.WebSearchEnabled)
} }
// AgentQA handles agent-based question answering with conversation history and streaming // AgentQA handles agent-based question answering with conversation history and streaming
+13
View File
@@ -203,3 +203,16 @@ func SanitizeForLog(input string) string {
return sanitized return sanitized
} }
// SanitizeForLogArray 清理日志输入数组,防止日志注入攻击
func SanitizeForLogArray(input []string) []string {
if len(input) == 0 {
return []string{}
}
for _, item := range input {
input = append(input, SanitizeForLog(item))
}
return input
}