Follow-ups from the PR #91 review: body-limit docs and route-ordering test coverage #93
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?
Tracking issue for the five non-blocking nits raised in the independent review of PR #91 (#90), so they do not become untracked. None of these blocked that merge; they are recorded here rather than round-tripping the PR.
Items
Stale doc comment.
internal/middleware/middleware_test.go(~line 435): the doc comment saysmaxBodySizeHandler, but the declaration it sits above istype maxBodySizeResult struct, and nomaxBodySizeHandleridentifier exists anywhere. The prose actually describesrunMaxBodySize, declared below it. Fix the comment to name the thing it documents.Inaccurate README sentence.
README.md(~line 875) says the body cap runs "before any other middleware or handler runs". That is wrong: it is registered per route group, so the eight global middlewares (Recoverer,RequestID,SecurityHeaders,Logging, optionalMetrics,CORS,Timeout, optional Sentry) all run first. The middleware's own doc comment ininternal/middleware/middleware.gois accurate — align the README to it. The claim that matters and is true is that the cap runs before CSRF and therefore before any form parsing.Ordering is test-guarded on only two of four groups. PR #91 added route-level ordering tests for
/pagesandPOST /passwordunder/user/{username}(exactly what the spec asked for)./sourcesand/source/{sourceID}have the correct order but nothing pins it, so a future reorder there would regress silently. Extend the table ininternal/server/routes_test.goto cover a POST route in each of the remaining two groups.Cap is POST/PUT/PATCH-only.
MaxBodySizeonly wraps those three methods, and after #91 removed the handler-local readers it is the single enforcement point. A GET or DELETE carrying a large body on a form route is therefore uncapped. Not exploitable today (no form handler reads a body on those methods) and not a regression, but the method restriction should be stated in the middleware doc comment so the limitation is deliberate rather than incidental.NewRouterForTesthand-builds the server.internal/server/export_test.go:27-32constructs&Server{...}field by field, so any field added toServerlater silently defaults to zero in these tests, and route tests could drift from the real wiring they exist to guard. Consider routing it through the real constructor, or add a comment explaining why the hand-built struct is sufficient.Definition of done
MaxBodySizedoc comment.make checkgreen via the repo's own entrypoints;.golangci.ymluntouched.