feat(logger): 开放敏感内容列表定制并增加敏感检测开关
Verify / verify (push) Canceled after 0s

- 将凭据片段列表提升为全局默认列表,新增 DefaultSensitiveList、NewSensitiveList、Extend 与 SafeWith,支持整体替换或在默认列表之上扩展
- 新增 SetSensitiveDetection 与 SensitiveDetectionEnabled,缺省开启敏感检测,关闭后日志副本不再按名称隐藏凭据字段
- 显式敏感列表、访问日志固定凭据头与 RedactKeys、SQL config_value 与 Redis 认证命令等固定策略不受开关影响
- 同步接入使用指南的能力清单与使用说明
This commit is contained in:
zhangdeman authored and trae-solo-agent committed 2026-11-29 16:39:50 +08:00
1 parent 90d47c0152
commit c25bc4528a
6 files changed
+307 -17

No files matched your search

+32
View File
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"git.zhangdeman.cn/zhangdeman/ginframework/logger/storagevalue"
"github.com/gin-gonic/gin"
)
@@ -90,3 +92,33 @@ func TestDefaultPoliciesAndDisabledCollector(t *testing.T) {
engine.GET("/api", func(ctx *gin.Context) { ctx.Status(204) })
engine.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("GET", "/api", nil))
}
// TestDisabledSensitiveDetectionKeepsFixedPolicies 验证关闭敏感检测后正文保留原值,固定忽略的凭据头仍然隐藏。
func TestDisabledSensitiveDetectionKeepsFixedPolicies(t *testing.T) {
storagevalue.SetSensitiveDetection(false)
defer storagevalue.SetSensitiveDetection(true)
records := []Record{}
engine := gin.New()
engine.Use(New(Config{}, Options{
RequestBody: func(*gin.Context) any { return map[string]any{"password": "private-password"} },
Emit: func(_ *gin.Context, r Record) { records = append(records, r) },
}))
engine.POST("/api", func(ctx *gin.Context) { ctx.Status(204) })
req := httptest.NewRequest("POST", "/api", strings.NewReader("{}"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "private-header")
engine.ServeHTTP(httptest.NewRecorder(), req)
if len(records) != 1 {
t.Fatalf("records=%+v", records)
}
if records[0].Header.Get("Authorization") != "" {
t.Fatal("fixed credential header policy was disabled")
}
body, err := json.Marshal(records[0].Body)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(body), "private-password") {
t.Fatal("disabled detection still hid the body field")
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.