diff options
author | Francis Lavoie <lavofr@gmail.com> | 2023-08-29 13:41:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 11:41:39 -0600 |
commit | c46ec3b500774e554ef0612530acc941b8b92bd4 (patch) | |
tree | a059ac5163186acef85ab8e6fff903c02c9a6142 /modules/logging | |
parent | ed8bb13c5df7656647ca7fc1fd09237631a6767c (diff) |
logging: Clone array on log filters, prevent side-effects (#5786)
Fixes https://caddy.community/t/is-caddy-mutating-header-content-from-logging-settings/20947
Diffstat (limited to 'modules/logging')
-rw-r--r-- | modules/logging/filters.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/logging/filters.go b/modules/logging/filters.go index ed4c7af..69ba9d1 100644 --- a/modules/logging/filters.go +++ b/modules/logging/filters.go @@ -100,12 +100,15 @@ func (f *HashFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { // Filter filters the input field with the replacement value. func (f *HashFilter) Filter(in zapcore.Field) zapcore.Field { if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok { + newArray := make(caddyhttp.LoggableStringArray, len(array)) for i, s := range array { - array[i] = hash(s) + newArray[i] = hash(s) } + in.Interface = newArray } else { in.String = hash(in.String) } + return in } @@ -219,9 +222,11 @@ func (m *IPMaskFilter) Provision(ctx caddy.Context) error { // Filter filters the input field. func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field { if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok { + newArray := make(caddyhttp.LoggableStringArray, len(array)) for i, s := range array { - array[i] = m.mask(s) + newArray[i] = m.mask(s) } + in.Interface = newArray } else { in.String = m.mask(in.String) } @@ -580,9 +585,11 @@ func (m *RegexpFilter) Provision(ctx caddy.Context) error { // Filter filters the input field with the replacement value if it matches the regexp. func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field { if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok { + newArray := make(caddyhttp.LoggableStringArray, len(array)) for i, s := range array { - array[i] = f.regexp.ReplaceAllString(s, f.Value) + newArray[i] = f.regexp.ReplaceAllString(s, f.Value) } + in.Interface = newArray } else { in.String = f.regexp.ReplaceAllString(in.String, f.Value) } |