Skip to content

Commit 986753a

Browse files
authored
logging: hash query parameter values in QueryFilter (#7884)
1 parent 873fac5 commit 986753a

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

modules/logging/filters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func (m QueryFilter) processQueryString(s string) string {
421421

422422
case hashAction:
423423
for i := range q[a.Parameter] {
424-
q[a.Parameter][i] = hash(a.Value)
424+
q[a.Parameter][i] = hash(q[a.Parameter][i])
425425
}
426426

427427
case deleteAction:

modules/logging/filters_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestQueryFilterSingleValue(t *testing.T) {
100100
}
101101

102102
out := f.Filter(zapcore.Field{String: "/path?foo=a&foo=b&bar=c&bar=d&baz=e&hash=hashed"})
103-
if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED&hash=e3b0c442" {
103+
if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED&hash=1a06df82" {
104104
t.Fatalf("query parameters have not been filtered: %s", out.String)
105105
}
106106
}
@@ -121,16 +121,16 @@ func TestQueryFilterMultiValue(t *testing.T) {
121121
}
122122

123123
out := f.Filter(zapcore.Field{Interface: internal.LoggableStringArray{
124-
"/path1?foo=a&foo=b&bar=c&bar=d&baz=e&hash=hashed",
125-
"/path2?foo=c&foo=d&bar=e&bar=f&baz=g&hash=hashed",
124+
"/path1?foo=a&foo=b&bar=c&bar=d&baz=e&hash=alpha",
125+
"/path2?foo=c&foo=d&bar=e&bar=f&baz=g&hash=beta",
126126
}})
127127
arr, ok := out.Interface.(internal.LoggableStringArray)
128128
if !ok {
129129
t.Fatalf("field is wrong type: %T", out.Interface)
130130
}
131131

132-
expected1 := "/path1?baz=e&foo=REDACTED&foo=REDACTED&hash=e3b0c442"
133-
expected2 := "/path2?baz=g&foo=REDACTED&foo=REDACTED&hash=e3b0c442"
132+
expected1 := "/path1?baz=e&foo=REDACTED&foo=REDACTED&hash=8ed3f6ad"
133+
expected2 := "/path2?baz=g&foo=REDACTED&foo=REDACTED&hash=f44e64e7"
134134
if arr[0] != expected1 {
135135
t.Fatalf("query parameters in entry 0 have not been filtered correctly: got %s, expected %s", arr[0], expected1)
136136
}

0 commit comments

Comments
 (0)