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

+34
View File
@@ -8,6 +8,7 @@ import (
"testing"
"git.zhangdeman.cn/zhangdeman/ginframework/internal/testutil/redisserver"
"git.zhangdeman.cn/zhangdeman/ginframework/logger/storagevalue"
"github.com/redis/go-redis/v9"
"go.uber.org/zap"
@@ -75,3 +76,36 @@ func TestHookObservesReturnedError(t *testing.T) {
t.Fatalf("hook altered command or observed wrong result: %v", logs.All())
}
}
// TestDisabledSensitiveDetectionKeepsFixedHiddenCommands 验证关闭敏感检测后普通命令保留原始参数,认证管理命令仍然整组隐藏。
func TestDisabledSensitiveDetectionKeepsFixedHiddenCommands(t *testing.T) {
storagevalue.SetSensitiveDetection(false)
defer storagevalue.SetSensitiveDetection(true)
var (
core, logs = observer.New(zap.InfoLevel)
hook = New(zap.New(core), "cache")
process = hook.ProcessHook(func(context.Context, redis.Cmder) error { return nil })
)
if err := process(context.Background(), redis.NewStringCmd(context.Background(), "set", "user:token", "private-value")); err != nil {
t.Fatal(err)
}
if err := process(context.Background(), redis.NewStringCmd(context.Background(), "auth", "private-password")); err != nil {
t.Fatal(err)
}
var (
entries = logs.All()
)
if len(entries) != 2 {
t.Fatalf("entries=%d, want 2", len(entries))
}
body, err := json.Marshal(entries[0].ContextMap())
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(body), "private-value") {
t.Fatal("disabled detection still hid ordinary command arguments")
}
if entries[1].ContextMap()["args"] != "[REDACTED]" || entries[1].ContextMap()["value"] != "[REDACTED]" {
t.Fatal("fixed hidden command policy was disabled")
}
}
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.