diff --git a/backend/internal/service/api_key_service.go b/backend/internal/service/api_key_service.go index dc008b8a73..f749b35a24 100644 --- a/backend/internal/service/api_key_service.go +++ b/backend/internal/service/api_key_service.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "encoding/hex" "fmt" + "html" "strconv" "strings" "sync" @@ -401,7 +402,7 @@ func (s *APIKeyService) Create(ctx context.Context, userID int64, req CreateAPIK apiKey := &APIKey{ UserID: userID, Key: key, - Name: req.Name, + Name: html.EscapeString(req.Name), GroupID: req.GroupID, Status: StatusActive, IPWhitelist: req.IPWhitelist, @@ -540,7 +541,7 @@ func (s *APIKeyService) Update(ctx context.Context, id int64, userID int64, req // 更新字段 if req.Name != nil { - apiKey.Name = *req.Name + apiKey.Name = html.EscapeString(*req.Name) } if req.GroupID != nil {