fix: resolve and the 404 report refuse NUL and invalid UTF-8 addresses (WR-12)
A decoded path such as /%00 or /%FF reached Postgres as text and answered 500 with an error log line per request. parseTarget refuses a path or query that is not valid UTF-8 or holds NUL (422), NotFoundPath does the same for the logged address, and a referer is cleaned of both.
This commit is contained in:
@@ -76,7 +76,11 @@ func NotFoundPath(raw string) (string, error) {
|
||||
if p == "" {
|
||||
p = "/"
|
||||
}
|
||||
return joinQuery(p, u.RawQuery), nil
|
||||
out := joinQuery(p, u.RawQuery)
|
||||
if !safeText(out) {
|
||||
return "", ErrNotFoundURL
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// capWarned keeps when the row-cap warning was last logged.
|
||||
@@ -94,7 +98,7 @@ func (s *Service) ReportNotFound(ctx context.Context, rawURL, referer string) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
referer = strings.TrimSpace(referer)
|
||||
referer = strings.TrimSpace(strings.ToValidUTF8(strings.ReplaceAll(referer, "\x00", ""), ""))
|
||||
if len(referer) > MaxRefererBytes {
|
||||
referer = referer[:MaxRefererBytes]
|
||||
for len(referer) > 0 && !utf8ValidTail(referer) {
|
||||
|
||||
Reference in New Issue
Block a user