mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
logging: Clone array on log filters, prevent side-effects (#5786)
Fixes https://caddy.community/t/is-caddy-mutating-header-content-from-logging-settings/20947
This commit is contained in:
parent
ed8bb13c5d
commit
c46ec3b500
1 changed files with 10 additions and 3 deletions
|
@ -100,12 +100,15 @@ func (f *HashFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
// Filter filters the input field with the replacement value.
|
// Filter filters the input field with the replacement value.
|
||||||
func (f *HashFilter) Filter(in zapcore.Field) zapcore.Field {
|
func (f *HashFilter) Filter(in zapcore.Field) zapcore.Field {
|
||||||
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
||||||
|
newArray := make(caddyhttp.LoggableStringArray, len(array))
|
||||||
for i, s := range array {
|
for i, s := range array {
|
||||||
array[i] = hash(s)
|
newArray[i] = hash(s)
|
||||||
}
|
}
|
||||||
|
in.Interface = newArray
|
||||||
} else {
|
} else {
|
||||||
in.String = hash(in.String)
|
in.String = hash(in.String)
|
||||||
}
|
}
|
||||||
|
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,9 +222,11 @@ func (m *IPMaskFilter) Provision(ctx caddy.Context) error {
|
||||||
// Filter filters the input field.
|
// Filter filters the input field.
|
||||||
func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field {
|
func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field {
|
||||||
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
||||||
|
newArray := make(caddyhttp.LoggableStringArray, len(array))
|
||||||
for i, s := range array {
|
for i, s := range array {
|
||||||
array[i] = m.mask(s)
|
newArray[i] = m.mask(s)
|
||||||
}
|
}
|
||||||
|
in.Interface = newArray
|
||||||
} else {
|
} else {
|
||||||
in.String = m.mask(in.String)
|
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.
|
// Filter filters the input field with the replacement value if it matches the regexp.
|
||||||
func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field {
|
func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field {
|
||||||
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
if array, ok := in.Interface.(caddyhttp.LoggableStringArray); ok {
|
||||||
|
newArray := make(caddyhttp.LoggableStringArray, len(array))
|
||||||
for i, s := range 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 {
|
} else {
|
||||||
in.String = f.regexp.ReplaceAllString(in.String, f.Value)
|
in.String = f.regexp.ReplaceAllString(in.String, f.Value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue