You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XAML server: bound Content-Length and header sizes in JsonRpcConnection #214
server/src/WinUiXaml.LanguageServer/Lsp/JsonRpcConnection.cs line 226 allocates new byte[contentLength] directly from the Content-Length header with no upper bound, and the header-reading loop has no cap on individual header-line length or total header size. A malformed or hostile Content-Length therefore turns into an unbounded allocation.
Additionally, when int.TryParse fails on the header value the code silently leaves contentLength at 0 rather than treating the frame as a protocol error, which makes malformed input hard to diagnose.
Severity is low in practice: the only client on this pipe is the extension host over stdio, so this is defense-in-depth rather than a reachable attack path.
Suggested work:
Cap Content-Length at a sane maximum (a few MB) and fail the frame beyond that.
Cap header-line and total-header size.
Treat a Content-Length parse failure as an explicit protocol error instead of falling through with 0.
Fixed in PR #50 (dada006, 5894e98), which closes this issue. All three suggested items are implemented.
Bounds.MaxContentLength 32 MB, MaxHeaderLineLength 8 KB, MaxHeaderBlockLength 64 KB, each failing the frame with its own log message rather than a shared generic one.
Parse failure is now a protocol error. Worth recording that this was slightly worse than the issue described. int.TryParse writes 0 on failure, which overwrote the -1 sentinel and so bypassed the contentLength < 0 missing-header guard entirely. The frame was completed with an empty body while the real body bytes stayed in the stream. Tracing what follows: the next read consumes those bytes as a header line, finds no Content-Length, and terminates the connection. So it failed closed rather than corrupting the session, but a malformed header killed the connection and reported the misleading message "missing Content-Length header".
A follow-on commit also switched the parse to NumberStyles.None with InvariantCulture. LSP specifies digits only, and a default int.TryParse is culture-sensitive and accepts a leading sign, so Content-Length: +39 previously parsed as 39 and dispatched the frame. Rejecting the sign also makes a negative value unparsable, removing the need for a separate < 0 guard.
On severity, the original assessment holds and I did not inflate it.Program.cs is the only construction site and it is stdio, so the extension host is the sole writer on this pipe. This is not attacker-reachable. The value is that a truncated or half-written frame from a crashing client fails fast with a diagnostic instead of an OutOfMemoryException or a read loop that never terminates.
Test honesty. Eight tests were added and each bound was verified by reverting it and confirming a specific failure. Two rounds of that were necessary: the first pass had six tests of which only two failed without the fix. One was vacuous, asserting a handler was not called for a body of {} that has no method and so never reached a handler either way, and another let a MemoryStream end naturally, which masked the missing cap. Both were rewritten to place a valid request frame behind the oversized header. Final state is five load-bearing tests plus three deliberate non-regression guards (a negative length the old < 0 check already caught, a culture guard that passes either way, and a positive control that headers within the limits still dispatch).
Server suite 1,008 passing. The end-to-end LSP smoke also passes, which mattered here because every message traverses this framing layer.
Activity
Address PR review findings for the XAML language service
Bound frame and header sizes in JsonRpcConnection
Parse Content-Length invariantly and reject signed values
chiaramooney commentedon Sep 8, 2026
Fixed in PR #50 (
dada006,5894e98), which closes this issue. All three suggested items are implemented.Bounds.
MaxContentLength32 MB,MaxHeaderLineLength8 KB,MaxHeaderBlockLength64 KB, each failing the frame with its own log message rather than a shared generic one.Parse failure is now a protocol error. Worth recording that this was slightly worse than the issue described.
int.TryParsewrites0on failure, which overwrote the-1sentinel and so bypassed thecontentLength < 0missing-header guard entirely. The frame was completed with an empty body while the real body bytes stayed in the stream. Tracing what follows: the next read consumes those bytes as a header line, finds noContent-Length, and terminates the connection. So it failed closed rather than corrupting the session, but a malformed header killed the connection and reported the misleading message "missing Content-Length header".A follow-on commit also switched the parse to
NumberStyles.NonewithInvariantCulture. LSP specifies digits only, and a defaultint.TryParseis culture-sensitive and accepts a leading sign, soContent-Length: +39previously parsed as 39 and dispatched the frame. Rejecting the sign also makes a negative value unparsable, removing the need for a separate< 0guard.On severity, the original assessment holds and I did not inflate it.
Program.csis the only construction site and it is stdio, so the extension host is the sole writer on this pipe. This is not attacker-reachable. The value is that a truncated or half-written frame from a crashing client fails fast with a diagnostic instead of anOutOfMemoryExceptionor a read loop that never terminates.Test honesty. Eight tests were added and each bound was verified by reverting it and confirming a specific failure. Two rounds of that were necessary: the first pass had six tests of which only two failed without the fix. One was vacuous, asserting a handler was not called for a body of
{}that has nomethodand so never reached a handler either way, and another let aMemoryStreamend naturally, which masked the missing cap. Both were rewritten to place a valid request frame behind the oversized header. Final state is five load-bearing tests plus three deliberate non-regression guards (a negative length the old< 0check already caught, a culture guard that passes either way, and a positive control that headers within the limits still dispatch).Server suite 1,008 passing. The end-to-end LSP smoke also passes, which mattered here because every message traverses this framing layer.