fix(server): wrap JSON body decoders with MaxBytesReader to prevent OOM (PILOT-134)#8
fix(server): wrap JSON body decoders with MaxBytesReader to prevent OOM (PILOT-134)#8matthew-pilot wants to merge 1 commit into
Conversation
…OM (PILOT-134) POST /admin/recrawl, /admin/recrawl-by-domain, /feedback, /admin/reembed, and /contents (batch) all decoded r.Body with json.NewDecoder without a size limit. A large JSON array (e.g. 100M-element URL list) would OOM the server during parsing — the len(req.URLs) > N guard ran only AFTER decode. Add maxRequestBodySize = 1 MiB and wrap all five decoder sites with http.MaxBytesReader(w, r.Body, maxRequestBodySize). Oversized bodies now fail at the transport layer before the JSON decoder allocates. TestAdminRecrawlRejectsOversizedBody: sends a 2 MiB body and confirms 400/413. Closes PILOT-134
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
🦜 Matthew PR Check — #8 PILOT-134Status
VerdictCLEAN — all CI green, mergeable, no conflicts. Ready for review. 🤖 matthew-pilot · PILOT-134 |
🦜 Matthew Explains — #8 PILOT-134What this doesWraps all JSON body decoders in the cosift HTTP server with Changes
RiskLow. Jira🤖 matthew-pilot |
|
Superseded by #6 (PILOT-107) which added MaxBytesReader to handleFeedback, handleAdminRecrawl, and handleAdminRecrawlByDomain. Verified the same MaxBytesReader cap is present on those handlers at main HEAD. |
What failed
POST /admin/recrawl, /admin/recrawl-by-domain, /feedback, /admin/reembed, and /contents (batch) all decoded
r.Bodywithjson.NewDecoderwithout a size limit. A large JSON array (e.g. 100M-element URL list) would OOM the server during parsing — thelen(req.URLs) > Nguard ran only AFTER decode.Why this fix
Add
maxRequestBodySize = 1 MiBand wrap all five decoder sites withhttp.MaxBytesReader(w, r.Body, maxRequestBodySize). Oversized bodies now fail at the transport layer before the JSON decoder allocates.Verification
go build ./...✅go vet ./...✅ (pre-existing test warnings only)go test ./...✅ (9/9 packages pass)TestAdminRecrawlRejectsOversizedBody— sends 2 MiB body, confirms 400 rejectionCloses PILOT-134