feat(api): make request body-size limit declarative in the route registry - #415
Merged
Conversation
…stry stem's capability registry already made HTTP methods authoritative (methods + methodGate); the body-size cap was the one piece of route policy still living outside it — every handler relied on decodeJSONStrict passing maxRequestBodySize per call site, so a route that forgot to decode strictly had no body cap. This brings stem to seed parity (ADR-0002): the registry is the single authoritative source for body limits too. - Add maxBodyBytes to the route struct (0 => default maxRequestBodySize). - Add bodyLimited middleware, composed innermost in register() so r.Body is capped before the handler reads (order: rateLimit → auth → methodGate → bodyLimit → handler). - Expose maxBodyBytes in the /__capabilities manifest (routePolicyView). - Assert in TestRoutePolicyManifest that every route records a non-zero body limit, so no route can ship with an uncapped body. Safe to default-cap: stem has no multipart/upload routes — every body path already goes through decodeJSONStrict at maxRequestBodySize (1 MB), so the registry cap matches what was enforced inline. The existing inline decode caps remain as defense-in-depth.
krisarmstrong
enabled auto-merge (squash)
June 9, 2026 00:13
Contributor
License Compliance ReportAll dependencies pass license compliance checksGo Dependencies
npm DependenciesSee full report in workflow artifacts Allowed Licenses: MIT, Apache-2.0, BSD-*, ISC, CC0-1.0, MPL-2.0 |
This was referenced Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stem's capability registry already made HTTP methods authoritative
(methods + methodGate); the body-size cap was the one piece of route
policy still living outside it — every handler relied on decodeJSONStrict
passing maxRequestBodySize per call site, so a route that forgot to decode
strictly had no body cap. This brings stem to seed parity (ADR-0002): the
registry is the single authoritative source for body limits too.
is capped before the handler reads (order: rateLimit → auth → methodGate
→ bodyLimit → handler).
body limit, so no route can ship with an uncapped body.
Safe to default-cap: stem has no multipart/upload routes — every body
path already goes through decodeJSONStrict at maxRequestBodySize (1 MB),
so the registry cap matches what was enforced inline. The existing inline
decode caps remain as defense-in-depth.