Blocks 1.0: http.Server missing IdleTimeout and ReadHeaderTimeout (slowloris), no request body size limits #92
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the audit against the canonical
REPO_POLICIES.md. Independently verified againstmainat61f42e6.1. Missing server timeouts. The policy requires:
>
ReadTimeoutandReadHeaderTimeouton thehttp.Serverto defend against slowloris attacks. ...IdleTimeouton thehttp.Server.internal/server/http.go:16-24constructs the server withAddr,ReadTimeout(30 s),WriteTimeout(60 s),MaxHeaderBytes(8 KiB), andHandler— and nothing else. Grep forIdleTimeout|ReadHeaderTimeoutacrossinternal/andcmd/returns zero matches — verified.This is not covered by the existing settings.
ReadTimeoutbounds the whole request read but does not specifically bound the header phase, which is the slowloris dribble the policy names. With noIdleTimeout, a keep-alive connection is held open indefinitely — so a trivial number of idle connections can exhaust the accept path on a service explicitly targeting high concurrency.2. No application-enforced request body limit. The policy requires:
> Maximum request body size enforced on all endpoints (e.g. Go
http.MaxBytesReader). Choose a sane default per-route; never accept unbounded input.Grep for
MaxBytesReaderreturns zero matches.POST /andPOST /generateboth callr.ParseForm()(internal/handlers/auth.go:38,86) with no wrapper.Stated honestly: these routes are not literally unbounded — Go's
ParseFormapplies its own 10 MB cap to URL-encoded bodies. The divergence is that the limit is incidental rather than chosen, and it would silently evaporate if a handler ever switched toio.ReadAllor multipart. Lower severity than item 1, but it belongs in the same pass since both are HTTP-server hardening.Definition of done
HTTPIdleTimeoutandHTTPReadHeaderTimeoutconstants added alongside the existing ones (internal/server/http.go:10-14) and set on thehttp.Server. Choose values deliberately —ReadHeaderTimeoutshould be short (seconds),IdleTimeoutlonger than typical keep-alive reuse but bounded.http.MaxBytesReader(or middleware) applies an explicit per-route body limit onPOST /andPOST /generate; exceeding it returns 413, not a generic 400.WriteTimeoutof 60 s is right given large image responses over slow links — flag if it needs raising, but do not change it without saying why.make checkgreen.Priority
Blocks 1.0.0 for item 1 per the policy's pre-1.0 hardening section. Item 2 is cleanup.
internal/server/http.gois untouched by both open PRs.