Merge pull request #2960 from CheriWen/fix/cwe-79-stored-xss-key-name

[Security] fix: sanitize API key name to prevent stored XSS
This commit is contained in:
Wesley Liddick
2026-06-06 11:09:08 +08:00
committed by GitHub
+3 -2
View File
@@ -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 {