mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-21 14:19:18 +08:00
fix: sanitize API key name with html.EscapeString to prevent stored XSS (CWE-79)
HTML-encode user-supplied key names in both Create and Update endpoints. Previously, names were stored verbatim — an attacker could inject script tags that would execute in admin panels or any view using innerHTML/v-html rendering. Fixes: CWE-79 (Stored Cross-Site Scripting)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"html"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -399,7 +400,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,
|
||||
@@ -538,7 +539,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 {
|
||||
|
||||
Reference in New Issue
Block a user