From 986753a7c6ec25bb676997a5a0ea2356406cb9aa Mon Sep 17 00:00:00 2001 From: Pichu Chen Date: Thu, 16 Jul 2026 00:38:58 +0800 Subject: [PATCH] logging: hash query parameter values in QueryFilter (#7884) --- modules/logging/filters.go | 2 +- modules/logging/filters_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/logging/filters.go b/modules/logging/filters.go index b863e72ea..309f473f6 100644 --- a/modules/logging/filters.go +++ b/modules/logging/filters.go @@ -421,7 +421,7 @@ func (m QueryFilter) processQueryString(s string) string { case hashAction: for i := range q[a.Parameter] { - q[a.Parameter][i] = hash(a.Value) + q[a.Parameter][i] = hash(q[a.Parameter][i]) } case deleteAction: diff --git a/modules/logging/filters_test.go b/modules/logging/filters_test.go index 8fbaed6f8..5852cae30 100644 --- a/modules/logging/filters_test.go +++ b/modules/logging/filters_test.go @@ -100,7 +100,7 @@ func TestQueryFilterSingleValue(t *testing.T) { } out := f.Filter(zapcore.Field{String: "/path?foo=a&foo=b&bar=c&bar=d&baz=e&hash=hashed"}) - if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED&hash=e3b0c442" { + if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED&hash=1a06df82" { t.Fatalf("query parameters have not been filtered: %s", out.String) } } @@ -121,16 +121,16 @@ func TestQueryFilterMultiValue(t *testing.T) { } out := f.Filter(zapcore.Field{Interface: internal.LoggableStringArray{ - "/path1?foo=a&foo=b&bar=c&bar=d&baz=e&hash=hashed", - "/path2?foo=c&foo=d&bar=e&bar=f&baz=g&hash=hashed", + "/path1?foo=a&foo=b&bar=c&bar=d&baz=e&hash=alpha", + "/path2?foo=c&foo=d&bar=e&bar=f&baz=g&hash=beta", }}) arr, ok := out.Interface.(internal.LoggableStringArray) if !ok { t.Fatalf("field is wrong type: %T", out.Interface) } - expected1 := "/path1?baz=e&foo=REDACTED&foo=REDACTED&hash=e3b0c442" - expected2 := "/path2?baz=g&foo=REDACTED&foo=REDACTED&hash=e3b0c442" + expected1 := "/path1?baz=e&foo=REDACTED&foo=REDACTED&hash=8ed3f6ad" + expected2 := "/path2?baz=g&foo=REDACTED&foo=REDACTED&hash=f44e64e7" if arr[0] != expected1 { t.Fatalf("query parameters in entry 0 have not been filtered correctly: got %s, expected %s", arr[0], expected1) }