feat(middleware): enhance logger to sanitize new and old password fields

Updated the logger to include regex patterns for sanitizing "new_password" and "old_password" fields in JSON logs. Added a corresponding test case to verify the sanitization functionality.
This commit is contained in:
wizardchen
2026-07-13 20:09:43 +08:00
committed by lyingbug
parent 8ec65941a5
commit a6c85dad28
2 changed files with 8 additions and 3 deletions
+5
View File
@@ -38,6 +38,11 @@ func TestSanitizeBody(t *testing.T) {
in: `{"password":"p","token":"t"}`,
want: `{"password":"***","token":"***"}`,
},
{
name: "snake_case new_password and old_password",
in: `{"email":"alice@example.com","new_password":"FreshPass9","old_password":"OldPass9"}`,
want: `{"email":"alice@example.com","new_password":"***","old_password":"***"}`,
},
{
name: "extra whitespace around colon",
in: `{"apiKey" : "leak"}`,