feat: 重建设备台账与凭据边界 (#65)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user