hardening(dap): bound DapFrameDecoder frames and make accumulation linear - #413
Merged
Conversation
…near The decoder accepted any finite positive Content-Length (a hostile or buggy peer could OOM the proxy worker / mirror connection), buffered header-less garbage without bound, and Buffer.concat'ed per chunk — O(N^2) for large frames arriving in small pieces (issue #402). - maxContentLength option, default 64 MB (DAP_MAX_FRAME_BYTES override); over-cap advertisements report a new 'overflow' error context and discard the buffer, same recovery contract as 'header' - header-search accumulation bounded at 16 KB - body bytes accumulate as a chunk list concatenated once per frame - MinimalDapClient warns and continues on overflow; DapMirrorServer closes the mirror connection (as it does for corrupt headers) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Fixes #402
DapFrameDecoderaccepted any finite positiveContent-Length— a peer advertising a huge frame made the buffer grow until OOM (a buggy/compromised adapter can OOM the proxy worker;expose_sessionmirror clients are loopback + token-gated but defense-in-depth says the decoder itself must cap). Growth was unbounded even before any header: a garbage stream with no\r\n\r\nbuffered forever. Andpush()didBuffer.concatper chunk — O(N²) when a large frame arrives in small chunks.Change
maxContentLengthoption (default 64 MB, matching the repo'smaxBufferprecedent; env-overridable viaDAP_MAX_FRAME_BYTES). Over-cap advertisements → new error context'overflow'+ buffer discard, same recovery contract as'header'.'overflow'+ discard (headers are a handful of short lines).MinimalDapClienttreats'overflow'like'header'(warn + continue, decoder already discarded);DapMirrorServercloses the mirror connection on'overflow'as it does on'header'— a client advertising an over-cap frame is equally untrustworthy.Tests (property suite extended; new cases watched fail first)
'overflow'reported, payload discarded, decoder recovers on the next push.'overflow'+ recovery (previously buffered forever).rawDatanow assert the renamed internals.npm testgreen,npm run lintclean.DAP_MAX_FRAME_BYTESdocumented in the setup guide.🤖 Generated with Claude Code