Skip to content

fix(milo): apply idle socket validation and reject unsolicited responses - #6205

Open
mcollina wants to merge 1 commit into
mainfrom
fix/milo-idle-socket-validation
Open

mcollina wants to merge 1 commit into
mainfrom
fix/milo-idle-socket-validation

Conversation

@mcollina

Copy link
Copy Markdown
Member

The experimental Milo HTTP/1.1 parser (useMilo / UNDICI_USE_MILO) missed both parts of the GHSA-35p6-xmwp-9g52 fix that the llhttp parser has:

  1. Idle socket validation never ran. resumeH1 validates an idle socket before reusing it only if socket[kSocketUsed] is set. That symbol was private to client-h1.js, so parser-h1.js never set it, and with Milo an idle socket was reused without validation. This came up in fix(h1): do not reuse idle sockets whose keep-alive timeout expired #6171.
  2. Unsolicited responses were not rejected. The llhttp parser destroys the socket with SocketError('bad response') when a response starts while no request is running (onMessageBegin and onHeadersComplete). Milo had no such check. While a request is queued but not yet written, client[kQueue][client[kRunningIdx]] is that request, so buffered unsolicited response bytes were attributed to it.

Changes

  • Move kSocketUsed to lib/core/symbols.js, and set it when a Milo response completes, as the llhttp parser does.
  • In Milo, reject a response that starts, or completes its headers, while no request is running, with the same 'bad response' error as llhttp.

Both changes are needed. With only kSocketUsed set, the validation reads the unsolicited response before the next request is written, but Milo still attributes it to the queued request and fails an internal assertion (assert(this.timeoutType === TIMEOUT_HEADERS)). With the guard as well, the socket is destroyed and the request is sent on a new connection, as with llhttp.

Testing

  • test/response-queue-poisoning.js gains a test for both parsers. An unsolicited response reaches the client's receive buffer just before the next request is dispatched, and the test checks that the request does not receive it. On main, the llhttp case passes and the Milo case fails (the request gets the unsolicited response); with this change, both pass.
  • test/response-queue-poisoning.js, test/client-keep-alive.js, test/client-pipelining.js, test/issue-810.js and test/node-test/keep-alive-reuse.js pass with both parsers (43/43 each).
  • CI does not run the test suite with Milo enabled. A full local run of test/*.js with UNDICI_USE_MILO=1, and a benchmark of the Milo path, are in progress; their results will be added here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sfj4nEWQ4ovycNDjbvXcRs

The experimental Milo parser missed both parts of the
GHSA-35p6-xmwp-9g52 fix that the llhttp parser has:

- it never set kSocketUsed, which was private to client-h1.js, so the
  idle socket validation never ran before an idle socket was reused;
- it did not reject a response that starts while no request is running,
  so buffered unsolicited bytes were attributed to the request queued
  next.

Move kSocketUsed to core/symbols.js and set it when a Milo response
completes, as the llhttp parser does. Reject a response that starts, or
completes its headers, while no request is running, with the same
'bad response' SocketError.

Refs: GHSA-35p6-xmwp-9g52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sfj4nEWQ4ovycNDjbvXcRs
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina requested a review from ShogunPanda November 13, 2026 10:02
@codecov-commenter

codecov-commenter commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.76%. Comparing base (af82906) to head (c7e9976).

Files with missing lines Patch % Lines
lib/dispatcher/parser-h1.js 68.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6205      +/-   ##
==========================================
+ Coverage   91.67%   91.76%   +0.08%     
==========================================
  Files         113      113              
  Lines       44438    44457      +19     
==========================================
+ Hits        40740    40797      +57     
+ Misses       3698     3660      -38     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants