fix(api): redact third-party credentials in ddns/notification list

GET /api/v1/ddns and /api/v1/notification returned full objects with
plaintext credentials (Cloudflare/TencentCloud secrets, webhook URLs
with embedded bot tokens, Authorization headers). Redact these fields
in the list responses.

Since the frontend edit form repopulates from the list endpoint, the
update handlers now treat an empty submitted credential as "no change"
and preserve the stored value, preventing accidental secret wipes.

Ref: GHSA-ww5p-j6cj-6mqq
This commit is contained in:
naiba
2026-06-20 01:54:50 +00:00
parent d556c3216f
commit 39d398066d
4 changed files with 210 additions and 5 deletions
+15 -2
View File
@@ -30,6 +30,13 @@ func listDDNS(c *gin.Context) ([]*model.DDNSProfile, error) {
return nil, err
}
// 列表端点不回显写入态凭据:ddnsProfiles 是 copier 复制出的副本,置零安全,
// 不影响 singleton 内原始数据。
for _, p := range ddnsProfiles {
p.AccessSecret = ""
p.WebhookHeaders = ""
}
return ddnsProfiles, nil
}
@@ -137,12 +144,18 @@ func updateDDNS(c *gin.Context) (any, error) {
p.Provider = df.Provider
p.Domains = df.Domains
p.AccessID = df.AccessID
p.AccessSecret = df.AccessSecret
p.WebhookURL = df.WebhookURL
p.WebhookMethod = df.WebhookMethod
p.WebhookRequestType = df.WebhookRequestType
p.WebhookRequestBody = df.WebhookRequestBody
p.WebhookHeaders = df.WebhookHeaders
// 凭据在列表接口已脱敏,前端无法回填;空值视为"不修改",保留旧值避免误清空。
if df.AccessSecret != "" {
p.AccessSecret = df.AccessSecret
}
if df.WebhookHeaders != "" {
p.WebhookHeaders = df.WebhookHeaders
}
for n, domain := range p.Domains {
// IDN to ASCII