Repository navigation
Conversation
The uWS request parser stored header string_views in a fixed Header[UWS_HTTP_MAX_HEADERS_COUNT=200] array inside HttpRequest, giving a hard ceiling of 198 request header fields (slot 0 is the request line, the last slot is the null-key terminator) that no option could raise. node:http's server.maxHeadersCount was accepted but never pushed to the native parser, so setting it above ~198 had no effect and the server answered 431 Request Header Fields Too Large. HttpRequest now holds a Header* that defaults to the inline[200] array and can be repointed at a per-connection std::vector<Header> owned by HttpParser. The vector is sized once (on the first parse after the server raised maxHeadersCount) and reused for every request on that connection, so connections on servers that never raise the option see no allocation and no layout change. getHeaders' loop bound is now the live capacity instead of the compile-time constant. node:http's applyServerCustomOptions forwards server.maxHeadersCount (when > 0) through setServerCustomOptions → Server__setMaxHeadersCount → uws_app_set_max_headers_count → HttpContextData::maxHeadersCount → consumePostPadded. The JS-side rawHeaders truncation for values below the compiled-in cap is unchanged (matches Node's truncate-not-431 behavior). Fixes #6982
|
Warning Review limit reached
Next review available in: 13 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (12)
Comment |
|
Updated 7:53 AM PT - Jul 26th, 2026
❌ @robobun, your commit 100e7f5 has 2 failures in
Add 🧪 To try this PR locally: bunx bun-pr 35907That installs a local version of the PR into your bun-35907 --bun |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
…ons in the test The overflow vector size is now min(maxHeadersCount + 2, maxFallbackSize/4 + 2), computed in size_t so a near-UINT32_MAX value can neither wrap the +2 nor allocate more than the byte-size head cap can ever admit (the minimum field line is 4 bytes). The rawRequest/listen helpers reject on socket 'error'.
|
CI on 100e7f5 is green for the diff; the red is unrelated:
The new |
There was a problem hiding this comment.
Both earlier findings are addressed in 100e7f5 and I didn't find anything new, but this reworks HttpRequest's header storage (inline array → repointable Header* backed by a per-connection std::vector) inside the uWS request parser hot path, which is worth a human look.
What was reviewed:
consumePostPaddedsizing:wantnow widened tosize_tand clamped bymaxFallbackSize/4 + 2, so the UINT32_MAX wrap and unbounded-resize cases are gone (test at0xFFFF_FFFEcovers it).- Lifetime of
req.headerswhen repointed atheaderOverflow.data(): the vector lives onHttpParser(connection-owned) and is only resized before parsing, so the pointer stays valid throughrequestHandlerand header iteration/capture inassignHeadersFromUWebSocketsForCall. getHeadersloop bound switched toheaderCapacity - 1; the null-key terminator write atheaders[...]still lands in-bounds for both the inline and overflow storage.- Test helpers now wire
sock.on('error', reject)/server.on('error', reject).
Extended reasoning...
Overview
The PR threads server.maxHeadersCount from node:http through setServerCustomOptions → jsHTTPSetCustomOptions (NodeHTTP.cpp) → Server__setMaxHeadersCount (server_body.rs, all four server variants) → uws_app_set_max_headers_count → HttpContextData::maxHeadersCount, and then into consumePostPadded on every onData. Inside the parser, HttpRequest gains a Header* + headerCapacity pair (defaulting to the existing inline Header[200]); when the configured count exceeds 198, consumePostPadded grows a per-connection std::vector<Header> on HttpParser and repoints req.headers at it before calling getHeaders, whose field-line loop now uses the passed-in capacity. Twelve files across C++/Rust/TS plus a new test file.
Security risks
The uWS HTTP parser handles untrusted network bytes and is the first line of defense against request smuggling / header-overflow attacks. My earlier pass found a user-controlled uint32_t + 2 overflow that produced a null/1-element buffer and a confirmed release-build segfault at 0x0; that is now fixed by widening to size_t and clamping against maxFallbackSize/4 + 2 (the byte-size cap already bounds achievable field count). I re-checked the clamp: on Bun's 64-bit targets (size_t)maxHeadersCount + 2 cannot wrap, and want only exceeds UINT_MAX if maxHeaderSize is set to ≥~17 GB, at which point resize would bad_alloc first — not a practical vector. No new untrusted-input parsing was added; the loop-bound change is a straight substitution of a constant for a parameter.
Level of scrutiny
High. This is a memory-layout change in the HTTP request parser hot path — every request on every node:http/Bun.serve connection runs this code — and it introduces a raw pointer that can reference storage outside the stack-local HttpRequest. The default (option-not-raised) path is layout-unchanged and allocation-free, which limits blast radius, but changes here have historically been the source of memory-safety and smuggling issues. That combination is beyond what I'm comfortable auto-approving.
Other factors
The plumbing layers (Rust shim, libuwsockets.cpp wrapper, App.h setter, TS type signature) mirror the existing maxHeaderSize path exactly and are mechanical. The new tests exercise 300/398/399/350 header counts, the near-UINT32_MAX clamp, and the default-cap 431, and fail-before/pass-after evidence is in the PR body (including the pre-fix release segfault). Both prior inline threads are resolved by the author with matching commits.
|
Re-checked against current main (165dc9f) now that #6982 is closed. Not covered: main still has the fixed #6982 was closed because the compiled-in limit had been raised, with the note that a configurable limit was not added, and this PR is that configurable limit, so whether it is still wanted is a product call. It currently conflicts with main and would need a rebase either way. Leaving it open for now. |
|
Note for review: #42532 replaces part of this PR. It adds the same plumbing with the same names ( |
|
Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-26, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main. |
What does this PR do?
The uWS request parser stores header string_views in a fixed
Header[UWS_HTTP_MAX_HEADERS_COUNT=200]array insideHttpRequest, giving a hard ceiling of 198 request header fields (slot 0 is the request line, the last slot is the null-key terminator) that no option could raise.server.maxHeadersCountwas accepted but never reached the native parser, so setting it above ~198 had no effect and the server answered431 Request Header Fields Too Large.HttpRequestnow holds aHeader*that defaults to the inline[200] array and can be repointed at a per-connectionstd::vector<Header>owned byHttpParser. The vector is sized once (on the first parse after the server raisedmaxHeadersCount) and reused for every request on that connection, so connections on a server that never raises the option see no allocation and no layout change.getHeaders' field-line loop bound is now the live capacity instead of the compile-time constant.node:http'sapplyServerCustomOptionsforwardsserver.maxHeadersCount(when> 0) throughsetServerCustomOptions→Server__setMaxHeadersCount→uws_app_set_max_headers_count→HttpContextData::maxHeadersCount→consumePostPadded. The JS-siderawHeaderstruncation for values below the compiled-in cap is unchanged (matches Node's truncate-not-431 behavior).Fixes #6982
How did you verify your code works?
test/js/node/http/node-http-maxHeadersCount.test.ts:server.maxHeadersCount = 400+ 300 custom header lines → 200 OK with all 302 pairs inrawHeaders; 400 total → 200 OK; 401 total → 431 (cap enforced at the configured value).maxHeadersCountset) still 431s at >198 fields.Fail-before: on the released bun the first two tests fail with
Expected: 200 / Received: 431.Notes
Bun.servehas no per-server option surface for this yet (same asmaxHeaderSize, which it reads from the process global); the plumbing added here (Server__setMaxHeadersCountover all four server variants) is ready for that follow-up.maxHeadersCount = 0("no limit" in Node) currently keeps the compiled-in cap; the byte-sizemaxHeaderSizealready bounds memory, so wiring 0 as "uncapped count" is a small follow-up if wanted.[review] gate passed · iteration 0 · 12 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 2 passed · 0 rejected · iteration 0
evidence per changed file