refactor: Sanitize log inputs in message and tag handlers to enhance security
This commit is contained in:
@@ -39,7 +39,7 @@ func (h *MessageHandler) LoadMessages(c *gin.Context) {
|
|||||||
logger.Info(ctx, "Start loading messages")
|
logger.Info(ctx, "Start loading messages")
|
||||||
|
|
||||||
// Get path parameters and query parameters
|
// Get path parameters and query parameters
|
||||||
sessionID := c.Param("session_id")
|
sessionID := secutils.SanitizeForLog(c.Param("session_id"))
|
||||||
limit := secutils.SanitizeForLog(c.DefaultQuery("limit", "20"))
|
limit := secutils.SanitizeForLog(c.DefaultQuery("limit", "20"))
|
||||||
beforeTimeStr := secutils.SanitizeForLog(c.DefaultQuery("before_time", ""))
|
beforeTimeStr := secutils.SanitizeForLog(c.DefaultQuery("before_time", ""))
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/Tencent/WeKnora/internal/errors"
|
"github.com/Tencent/WeKnora/internal/errors"
|
||||||
"github.com/Tencent/WeKnora/internal/logger"
|
"github.com/Tencent/WeKnora/internal/logger"
|
||||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||||
|
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TagHandler handles knowledge base tag operations.
|
// TagHandler handles knowledge base tag operations.
|
||||||
@@ -23,7 +24,7 @@ func NewTagHandler(tagService interfaces.KnowledgeTagService) *TagHandler {
|
|||||||
// ListTags returns all tags under a knowledge base with statistics.
|
// ListTags returns all tags under a knowledge base with statistics.
|
||||||
func (h *TagHandler) ListTags(c *gin.Context) {
|
func (h *TagHandler) ListTags(c *gin.Context) {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
kbID := c.Param("id")
|
kbID := secutils.SanitizeForLog(c.Param("id"))
|
||||||
|
|
||||||
tags, err := h.tagService.ListTags(ctx, kbID)
|
tags, err := h.tagService.ListTags(ctx, kbID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,7 +48,7 @@ type createTagRequest struct {
|
|||||||
// CreateTag creates a new tag.
|
// CreateTag creates a new tag.
|
||||||
func (h *TagHandler) CreateTag(c *gin.Context) {
|
func (h *TagHandler) CreateTag(c *gin.Context) {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
kbID := c.Param("id")
|
kbID := secutils.SanitizeForLog(c.Param("id"))
|
||||||
|
|
||||||
var req createTagRequest
|
var req createTagRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
@@ -56,7 +57,8 @@ func (h *TagHandler) CreateTag(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tag, err := h.tagService.CreateTag(ctx, kbID, req.Name, req.Color, req.SortOrder)
|
tag, err := h.tagService.CreateTag(ctx, kbID,
|
||||||
|
secutils.SanitizeForLog(req.Name), secutils.SanitizeForLog(req.Color), req.SortOrder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
logger.ErrorWithFields(ctx, err, map[string]interface{}{
|
||||||
"kb_id": kbID,
|
"kb_id": kbID,
|
||||||
@@ -81,7 +83,7 @@ type updateTagRequest struct {
|
|||||||
func (h *TagHandler) UpdateTag(c *gin.Context) {
|
func (h *TagHandler) UpdateTag(c *gin.Context) {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
|
|
||||||
tagID := c.Param("tag_id")
|
tagID := secutils.SanitizeForLog(c.Param("tag_id"))
|
||||||
var req updateTagRequest
|
var req updateTagRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
logger.Error(ctx, "Failed to bind update tag payload", err)
|
logger.Error(ctx, "Failed to bind update tag payload", err)
|
||||||
@@ -107,7 +109,7 @@ func (h *TagHandler) UpdateTag(c *gin.Context) {
|
|||||||
// DeleteTag deletes a tag. Use query param force=true to force delete even if referenced.
|
// DeleteTag deletes a tag. Use query param force=true to force delete even if referenced.
|
||||||
func (h *TagHandler) DeleteTag(c *gin.Context) {
|
func (h *TagHandler) DeleteTag(c *gin.Context) {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
tagID := c.Param("tag_id")
|
tagID := secutils.SanitizeForLog(c.Param("tag_id"))
|
||||||
|
|
||||||
force := c.Query("force") == "true"
|
force := c.Query("force") == "true"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user