mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-04 15:27:17 -05:00
* ensure that all the jmap responses contain the SessionState * implement missing errors that were marked as TODO * moved common functions from pkg/jmap and pkg/services/groupware to pkg/log and pkg/structs to commonalize them across both source trees * implement error handling for SetError occurences * Email: replace anonymous map[string]bool for mailbox rights with a MailboxRights struct, as the keys are well-defined, which allows for properly documenting them * introduce ObjectType as an "enum" * fix JSON marshalling and unmarshalling of EmailBodyStructure * move the swagger documentation structs from groupware_api.go to groupware_docs.go * fix: change verb for /groupware/accounts/*/vacation from POST to PUT
44 lines
1023 B
Go
44 lines
1023 B
Go
package log
|
|
|
|
import "github.com/rs/zerolog"
|
|
|
|
const (
|
|
logMaxStrLength = 512
|
|
logMaxStrArrayLength = 16 // 8kb
|
|
)
|
|
|
|
// Safely caps a string to a given size to avoid log bombing.
|
|
// Use this function to wrap strings that are user input (HTTP headers, path parameters, URI parameters, HTTP body, ...).
|
|
func SafeString(text string) string {
|
|
runes := []rune(text)
|
|
|
|
if len(runes) <= logMaxStrLength {
|
|
return text
|
|
} else {
|
|
return string(runes[0:logMaxStrLength-1]) + `\u2026` // hellip
|
|
}
|
|
}
|
|
|
|
type SafeLogStringArrayMarshaller struct {
|
|
array []string
|
|
}
|
|
|
|
func (m SafeLogStringArrayMarshaller) MarshalZerologArray(a *zerolog.Array) {
|
|
for i, elem := range m.array {
|
|
if i >= logMaxStrArrayLength {
|
|
return
|
|
}
|
|
a.Str(SafeString(elem))
|
|
}
|
|
}
|
|
|
|
var _ zerolog.LogArrayMarshaler = SafeLogStringArrayMarshaller{}
|
|
|
|
func SafeStringArray(array []string) SafeLogStringArrayMarshaller {
|
|
return SafeLogStringArrayMarshaller{array: array}
|
|
}
|
|
|
|
func From(context zerolog.Context) *Logger {
|
|
return &Logger{Logger: context.Logger()}
|
|
}
|