Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 22:00 UTC
logging: Clone array on log filters, prevent side-effects (#5786)
Fixes https://caddy.community/t/is-caddy-mutating-header-content-from-logging-settings/20947
Francis Lavoie committed
Aug 29, 2023 at 13:41 UTC
c46ec3b500774e554ef0612530acc941b8b92bd4
1 file changed
+10
-3
modules/logging/filters.go
+10
-3
@@ -100,12 +100,15 @@ func (f *HashFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
100
// Filter filters the input field with the replacement value.
101
func (f *HashFilter) Filter(in zapcore.Field) zapcore.Field {
102
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
103
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
104
for i, s := range array {
104
- array[i] = hash(s)
105
+ newArray[i] = hash(s)
106
}
107
+ in.Interface = newArray
108
} else {
109
in.String = hash(in.String)
110
}
111
+
112
return in
113
}
114
@@ -219,9 +222,11 @@ func (m *IPMaskFilter) Provision(ctx caddy.Context) error {
222
// Filter filters the input field.
223
func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field {
224
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
225
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
226
for i, s := range array {
223
- array[i] = m.mask(s)
227
+ newArray[i] = m.mask(s)
228
}
229
+ in.Interface = newArray
230
} else {
231
in.String = m.mask(in.String)
232
}
@@ -580,9 +585,11 @@ func (m *RegexpFilter) Provision(ctx caddy.Context) error {
585
// Filter filters the input field with the replacement value if it matches the regexp.
586
func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field {
587
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
588
+ newArray := make(caddyhttp.LoggableStringArray, len(array))
589
for i, s := range array {
584
- array[i] = f.regexp.ReplaceAllString(s, f.Value)
590
+ newArray[i] = f.regexp.ReplaceAllString(s, f.Value)
591
}
592
+ in.Interface = newArray
593
} else {
594
in.String = f.regexp.ReplaceAllString(in.String, f.Value)
595
}