mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-21 13:52:09 +08:00
refactor: Sanitize log inputs in evaluation and session handlers to enhance security
This commit is contained in:
@@ -94,7 +94,7 @@ func (h *ChunkHandler) ListKnowledgeChunks(c *gin.Context) {
|
||||
// Parse pagination parameters
|
||||
var pagination types.Pagination
|
||||
if err := c.ShouldBindQuery(&pagination); err != nil {
|
||||
logger.Error(ctx, "Failed to parse pagination parameters", err)
|
||||
logger.Errorf(ctx, "Failed to parse pagination parameters: %s", secutils.SanitizeForLog(err.Error()))
|
||||
c.Error(errors.NewBadRequestError(err.Error()))
|
||||
return
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func (h *ChunkHandler) UpdateChunk(c *gin.Context) {
|
||||
}
|
||||
var req UpdateChunkRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(ctx, "Failed to parse request parameters", err)
|
||||
logger.Errorf(ctx, "Failed to parse request parameters: %s", secutils.SanitizeForLog(err.Error()))
|
||||
c.Error(errors.NewBadRequestError(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (e *EvaluationHandler) GetEvaluationResult(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := e.evaluationService.EvaluationResult(ctx, request.TaskID)
|
||||
result, err := e.evaluationService.EvaluationResult(ctx, secutils.SanitizeForLog(request.TaskID))
|
||||
if err != nil {
|
||||
logger.ErrorWithFields(ctx, err, nil)
|
||||
c.Error(errors.NewInternalServerError(err.Error()))
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -21,7 +22,7 @@ func (h *Handler) ContinueStream(c *gin.Context) {
|
||||
logger.Info(ctx, "Start continuing stream response processing")
|
||||
|
||||
// Get session ID from URL parameter
|
||||
sessionID := c.Param("session_id")
|
||||
sessionID := secutils.SanitizeForLog(c.Param("session_id"))
|
||||
if sessionID == "" {
|
||||
logger.Error(ctx, "Session ID is empty")
|
||||
c.Error(errors.NewBadRequestError(errors.ErrInvalidSessionID.Error()))
|
||||
@@ -29,7 +30,7 @@ func (h *Handler) ContinueStream(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Get message ID from query parameter
|
||||
messageID := c.Query("message_id")
|
||||
messageID := secutils.SanitizeForLog(c.Query("message_id"))
|
||||
if messageID == "" {
|
||||
logger.Error(ctx, "Message ID is empty")
|
||||
c.Error(errors.NewBadRequestError("Missing message ID"))
|
||||
@@ -165,7 +166,7 @@ func (h *Handler) ContinueStream(c *gin.Context) {
|
||||
// StopSession handles the stop generation request
|
||||
func (h *Handler) StopSession(c *gin.Context) {
|
||||
ctx := logger.CloneContext(c.Request.Context())
|
||||
sessionID := c.Param("session_id")
|
||||
sessionID := secutils.SanitizeForLog(c.Param("session_id"))
|
||||
|
||||
if sessionID == "" {
|
||||
c.JSON(400, gin.H{"error": "Session ID is required"})
|
||||
@@ -182,7 +183,7 @@ func (h *Handler) StopSession(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
assistantMessageID := req.MessageID
|
||||
assistantMessageID := secutils.SanitizeForLog(req.MessageID)
|
||||
logger.Infof(ctx, "Stop generation request for session: %s, message: %s", sessionID, assistantMessageID)
|
||||
|
||||
// Get tenant ID from context
|
||||
|
||||
Reference in New Issue
Block a user