feat: Add JWT_SECRET configuration to .env.example and enhance pagination validation in chunk handler
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -181,10 +181,10 @@ func SanitizeForLog(input string) string {
|
|||||||
// 替换换行符(LF, CR, CRLF)为空格,防止日志注入
|
// 替换换行符(LF, CR, CRLF)为空格,防止日志注入
|
||||||
sanitized := strings.ReplaceAll(input, "\n", " ")
|
sanitized := strings.ReplaceAll(input, "\n", " ")
|
||||||
sanitized = strings.ReplaceAll(sanitized, "\r", " ")
|
sanitized = strings.ReplaceAll(sanitized, "\r", " ")
|
||||||
|
|
||||||
// 替换制表符为空格
|
// 替换制表符为空格
|
||||||
sanitized = strings.ReplaceAll(sanitized, "\t", " ")
|
sanitized = strings.ReplaceAll(sanitized, "\t", " ")
|
||||||
|
|
||||||
// 移除其他控制字符(ASCII 0-31,除了空格已处理的)
|
// 移除其他控制字符(ASCII 0-31,除了空格已处理的)
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
for _, r := range sanitized {
|
for _, r := range sanitized {
|
||||||
@@ -193,13 +193,26 @@ func SanitizeForLog(input string) string {
|
|||||||
builder.WriteRune(r)
|
builder.WriteRune(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sanitized = builder.String()
|
sanitized = builder.String()
|
||||||
|
|
||||||
// 限制长度,防止日志溢出
|
// 限制长度,防止日志溢出
|
||||||
if len(sanitized) > 1000 {
|
if len(sanitized) > 1000 {
|
||||||
sanitized = sanitized[:1000] + "...[truncated]"
|
sanitized = sanitized[:1000] + "...[truncated]"
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user