feat: 重建设备台账与凭据边界 (#65)

This commit is contained in:
QiuSW
2026-08-14 14:59:34 +08:00
parent 1ef4a1fe0b
commit be091f093d
18 changed files with 1468 additions and 2 deletions
+2 -1
View File
@@ -136,7 +136,8 @@ func redactAuditValue(value interface{}) {
func isSensitiveAuditKey(key string) bool {
normalized := strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(key, "_", ""), "-", ""))
switch normalized {
case "password", "oldpassword", "newpassword", "token", "refreshtoken", "secret", "code", "uuid":
case "password", "oldpassword", "newpassword", "onvifusername", "onvifpassword", "rtspusername", "rtsppassword",
"token", "refreshtoken", "secret", "code", "uuid":
return true
default:
return false
@@ -18,6 +18,18 @@ func TestSanitizeAuditJSON(t *testing.T) {
}
}
func TestSanitizeAuditJSONHidesCameraCredentialFields(t *testing.T) {
value := sanitizeAuditJSON(`{"onvifUsername":"camera-user","onvifPassword":"camera-password","rtspUsername":"stream-user","rtspPassword":"stream-password","name":"东门摄像机"}`)
for _, forbidden := range []string{"camera-user", "camera-password", "stream-user", "stream-password"} {
if strings.Contains(value, forbidden) {
t.Fatalf("credential value leaked in audit JSON: %s", value)
}
}
if !strings.Contains(value, "东门摄像机") {
t.Fatalf("non-sensitive device field was unexpectedly removed: %s", value)
}
}
func TestSanitizeAuditJSONRejectsUnstructuredBodies(t *testing.T) {
if got := sanitizeAuditJSON("password=secret-value"); strings.Contains(got, "secret-value") {
t.Fatalf("unstructured body leaked: %s", got)