Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
3fb43b91
Commit
3fb43b91
authored
Jan 08, 2026
by
shaw
Browse files
fix(security): 强化 usage 端点信息暴露控制
parent
6e8188ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/usage_handler.go
View file @
3fb43b91
...
@@ -144,7 +144,7 @@ func (h *UsageHandler) List(c *gin.Context) {
...
@@ -144,7 +144,7 @@ func (h *UsageHandler) List(c *gin.Context) {
out
:=
make
([]
dto
.
UsageLog
,
0
,
len
(
records
))
out
:=
make
([]
dto
.
UsageLog
,
0
,
len
(
records
))
for
i
:=
range
records
{
for
i
:=
range
records
{
out
=
append
(
out
,
*
dto
.
UsageLogFromService
(
&
records
[
i
]))
out
=
append
(
out
,
*
dto
.
UsageLogFromService
Admin
(
&
records
[
i
]))
}
}
response
.
Paginated
(
c
,
out
,
result
.
Total
,
page
,
pageSize
)
response
.
Paginated
(
c
,
out
,
result
.
Total
,
page
,
pageSize
)
}
}
...
...
backend/internal/handler/dto/mappers.go
View file @
3fb43b91
...
@@ -234,7 +234,21 @@ func RedeemCodeFromService(rc *service.RedeemCode) *RedeemCode {
...
@@ -234,7 +234,21 @@ func RedeemCodeFromService(rc *service.RedeemCode) *RedeemCode {
}
}
}
}
func
UsageLogFromService
(
l
*
service
.
UsageLog
)
*
UsageLog
{
// AccountSummaryFromService returns a minimal AccountSummary for usage log display.
// Only includes ID and Name - no sensitive fields like Credentials, Proxy, etc.
func
AccountSummaryFromService
(
a
*
service
.
Account
)
*
AccountSummary
{
if
a
==
nil
{
return
nil
}
return
&
AccountSummary
{
ID
:
a
.
ID
,
Name
:
a
.
Name
,
}
}
// usageLogFromServiceBase is a helper that converts service UsageLog to DTO.
// The account parameter allows caller to control what Account info is included.
func
usageLogFromServiceBase
(
l
*
service
.
UsageLog
,
account
*
AccountSummary
)
*
UsageLog
{
if
l
==
nil
{
if
l
==
nil
{
return
nil
return
nil
}
}
...
@@ -269,12 +283,27 @@ func UsageLogFromService(l *service.UsageLog) *UsageLog {
...
@@ -269,12 +283,27 @@ func UsageLogFromService(l *service.UsageLog) *UsageLog {
CreatedAt
:
l
.
CreatedAt
,
CreatedAt
:
l
.
CreatedAt
,
User
:
UserFromServiceShallow
(
l
.
User
),
User
:
UserFromServiceShallow
(
l
.
User
),
APIKey
:
APIKeyFromService
(
l
.
APIKey
),
APIKey
:
APIKeyFromService
(
l
.
APIKey
),
Account
:
AccountFromService
(
l
.
A
ccount
)
,
Account
:
a
ccount
,
Group
:
GroupFromServiceShallow
(
l
.
Group
),
Group
:
GroupFromServiceShallow
(
l
.
Group
),
Subscription
:
UserSubscriptionFromService
(
l
.
Subscription
),
Subscription
:
UserSubscriptionFromService
(
l
.
Subscription
),
}
}
}
}
// UsageLogFromService converts a service UsageLog to DTO for regular users.
// It excludes Account details - users should not see account information.
func
UsageLogFromService
(
l
*
service
.
UsageLog
)
*
UsageLog
{
return
usageLogFromServiceBase
(
l
,
nil
)
}
// UsageLogFromServiceAdmin converts a service UsageLog to DTO for admin users.
// It includes minimal Account info (ID, Name only).
func
UsageLogFromServiceAdmin
(
l
*
service
.
UsageLog
)
*
UsageLog
{
if
l
==
nil
{
return
nil
}
return
usageLogFromServiceBase
(
l
,
AccountSummaryFromService
(
l
.
Account
))
}
func
SettingFromService
(
s
*
service
.
Setting
)
*
Setting
{
func
SettingFromService
(
s
*
service
.
Setting
)
*
Setting
{
if
s
==
nil
{
if
s
==
nil
{
return
nil
return
nil
...
...
backend/internal/handler/dto/types.go
View file @
3fb43b91
...
@@ -184,11 +184,18 @@ type UsageLog struct {
...
@@ -184,11 +184,18 @@ type UsageLog struct {
User
*
User
`json:"user,omitempty"`
User
*
User
`json:"user,omitempty"`
APIKey
*
APIKey
`json:"api_key,omitempty"`
APIKey
*
APIKey
`json:"api_key,omitempty"`
Account
*
Account
`json:"account,omitempty"`
Account
*
Account
Summary
`json:"account,omitempty"`
// Use minimal AccountSummary to prevent data leakage
Group
*
Group
`json:"group,omitempty"`
Group
*
Group
`json:"group,omitempty"`
Subscription
*
UserSubscription
`json:"subscription,omitempty"`
Subscription
*
UserSubscription
`json:"subscription,omitempty"`
}
}
// AccountSummary is a minimal account info for usage log display.
// It intentionally excludes sensitive fields like Credentials, Proxy, etc.
type
AccountSummary
struct
{
ID
int64
`json:"id"`
Name
string
`json:"name"`
}
type
Setting
struct
{
type
Setting
struct
{
ID
int64
`json:"id"`
ID
int64
`json:"id"`
Key
string
`json:"key"`
Key
string
`json:"key"`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment