Skip to content

fix: validate EOF for chunked h1 responses#5273

Open
mcollina wants to merge 1 commit intomainfrom
fix-h1-truncated-chunked-eof
Open

fix: validate EOF for chunked h1 responses#5273
mcollina wants to merge 1 commit intomainfrom
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.

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.

2 participants