fix(backend): cut request log fields to the log bound (closes #60)
check / check (push) Successful in 1m4s
check / check (push) Successful in 1m4s
The request log wrote the URL, User-Agent, Referer and other request-supplied strings with no length limit, and the server accepts headers up to 1 MiB, so one request could put about 1 MiB per field into a log line. Every string the request log takes from the request, including the request ID chi copies from X-Request-Id, is now cut to the 128-byte bound the report handler already used. That bound and its helper moved from the handlers package to the logger package so both use the one copy. Model: opus-5-5
This commit is contained in:
@@ -11,6 +11,21 @@ import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// MaxLoggedFieldBytes bounds untrusted text (request fields,
|
||||
// header values, decode error text) before it is logged, so a
|
||||
// caller cannot inflate log volume with an oversized value.
|
||||
const MaxLoggedFieldBytes = 128
|
||||
|
||||
// BoundedForLog truncates an untrusted string to a fixed byte
|
||||
// bound so an attacker-controlled field cannot dominate the log.
|
||||
func BoundedForLog(s string) string {
|
||||
if len(s) > MaxLoggedFieldBytes {
|
||||
return s[:MaxLoggedFieldBytes]
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Params defines the dependencies for Logger.
|
||||
type Params struct {
|
||||
fx.In
|
||||
|
||||
Reference in New Issue
Block a user