Skip to content

fix: validate EOF for chunked h1 responses#5273

Merged
mcollina merged 1 commit into
mainfrom
fix-h1-truncated-chunked-eof
May 11, 2026
Merged

fix: validate EOF for chunked h1 responses#5273
mcollina merged 1 commit into
mainfrom
fix-h1-truncated-chunked-eof

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented May 9, 2026

Summary

  • validate HTTP/1.1 response completeness with llhttp_finish() on EOF-like socket termination
  • preserve the existing Content-Length mismatch error behavior
  • add regression coverage for truncated chunked responses in Client and fetch()

Details

Undici previously treated EOF on non-keepalive responses as an implicit successful message completion. That is correct for EOF-delimited responses, but not for chunked responses, which must receive the terminating 0\r\n\r\n chunk.

This change routes the EOF/close/ECONNRESET path through llhttp_finish() so llhttp can reject incomplete chunked responses with an invalid EOF state instead of completing the response body successfully.

Testing

  • node --test test/parser-issues.js test/content-length.js
  • npx eslint lib/dispatcher/client-h1.js test/parser-issues.js

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.44068% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.27%. Comparing base (0b06a16) to head (ab6aae5).

Files with missing lines Patch % Lines
lib/dispatcher/client-h1.js 86.44% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5273      +/-   ##
==========================================
- Coverage   93.28%   93.27%   -0.01%     
==========================================
  Files         110      110              
  Lines       36384    36427      +43     
==========================================
+ Hits        33939    33978      +39     
- Misses       2445     2449       +4     

☔ View full report in Codecov by Sentry.
📢 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.

@trivikr
Copy link
Copy Markdown
Member

trivikr commented May 10, 2026

Needs rebase to include node 26 FFI build from https://www,github.com/nodejs/undici/pull/5275

@mcollina
Copy link
Copy Markdown
Member Author

I think we can land without

@mcollina mcollina merged commit 13f6af6 into main May 11, 2026
84 of 87 checks passed
@mcollina mcollina deleted the fix-h1-truncated-chunked-eof branch May 11, 2026 07:24
@github-actions github-actions Bot mentioned this pull request May 14, 2026
mcollina added a commit that referenced this pull request May 18, 2026
(cherry picked from commit 13f6af6)

Signed-off-by: Matteo Collina <hello@matteocollina.com>
mcollina added a commit that referenced this pull request May 18, 2026
* fix: validate EOF for chunked h1 responses (#5273)

(cherry picked from commit 13f6af6)
Signed-off-by: Matteo Collina <hello@matteocollina.com>

* test: restore websocket test compatibility on Node 18

- replace t.assert usage with node:assert in websocket tests so they work on Node 18\n- reduce the disabled-limit payload size in permessage-deflate-limit to avoid CI timeouts\n- remove an extra blank line in lib/dispatcher/agent.js to satisfy standard

Signed-off-by: Matteo Collina <hello@matteocollina.com>

---------

Signed-off-by: Matteo Collina <hello@matteocollina.com>
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