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:
2026-10-27 15:31:56 +01:00
parent d20f14fe67
commit 98fbeb6791
3 changed files with 48 additions and 3 deletions

View File

@@ -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) {