fix: cap inbound message size — one oversized line could exhaust memory - #3
Merged
Conversation
readMessage accumulated a line without bound (bufio.ErrBufferFull → keep appending), so a client could OOM the server process with a single multi-gigabyte line — reachable in odek via `odek mcp` from any connected MCP client (2026-08 odek audit, open upstream finding). Server.MaxRequestBytes now caps one inbound message: default DefaultMaxRequestBytes (10 MiB, matching what a typical client accepts for a response), zero selects the default, negative disables (not recommended). An oversized line is answered in-band with -32600 (id null, "exceeds maximum size"), its remainder discarded in constant memory so the stream stays framed, and the dispatch loop keeps serving — per the project rule that bad input never kills the loop. Regression tests: TestRunWithIO_RequestSizeCap (oversized line rejected + next message still served), TestRunWithIO_UnderCapStillServed (default cap admits normal traffic).
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.
Summary
readMessageaccumulated a line without bound (bufio.ErrBufferFull→ keep appending), so any client could OOM the server process with a single multi-gigabyte line. In odek this is reachable throughodek mcpfrom any connected MCP client (open finding from odek's 2026-08 security audit).Fix:
Server.MaxRequestBytescaps one inbound message.DefaultMaxRequestBytes= 10 MiB (matches what a typical MCP client accepts for a response);0selects the default; negative disables (documented as not recommended).-32600(idnull, "exceeds maximum size") per the project rule that bad input never kills the loop.Testing
TestRunWithIO_RequestSizeCap— oversized line →-32600with null id, then the followinginitializestill succeeds (loop survives, framing intact).TestRunWithIO_UnderCapStillServed— default cap admits normal 4 KiB traffic.go test ./...green (incl. pipe-based integration + subprocess E2E),go vetclean, gofmt clean.