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

mcollina merged 1 commit into
mainfrom
fix-h1-truncated-chunked-eof

Conversation

@mcollina

@mcollina mcollina commented May 9, 2026

Copy link
Copy Markdown
Member

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

trivikr commented May 10, 2026

Copy link
Copy Markdown
Member

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>
clevengermatt added a commit to openbindings/sdk that referenced this pull request Oct 24, 2026
* Require a Node whose fetch rejects a truncated chunked body

On Node 22.19, TypeScript discover reported a chunked 200 body cut short
as its connection closed as found or non-conformant, with the prefix
attached. Node's bundled undici completed any response not kept alive
when its socket ended, checking a fixed length but not chunked framing,
so the stream simply ended. undici fixed this in nodejs/undici#5273,
shipped as 6.26.0, 7.26.0 and 8.3.0. The first Node releases bundling a
fixed undici are 22.23.0 (6.27.0), 24.17.0 (7.28.0) and 26.2.0 (8.3.0);
22.22.2, 24.16.0 and 26.1.0 bundle 6.24.1, 7.25.0 and 8.2.0, Node 23
ended on 6.21, and Node 25's last release bundles 7.24.4.

Admit only fixed releases in engines (^22.23.0 || ^24.17.0 || >=26.2.0),
state the floor and its reason where the docs give the Node version,
pin CI to 22.23.0, and add a leg that runs the discovery tests, the ones
that use the host's fetch, at the 24 and 26 floors against the package
job's build.

* Test that a truncated discovery body is a body error

Serve each truncation shape from a raw local server: a chunked body
without its terminating chunk, cut inside a chunk, cut across chunks,
cut in the last chunk's size line, missing the final empty line, reset
after its chunks, and a short fixed-length body, each with and without
Connection: close, beside complete controls. Every truncated shape must
be a body error with no body attached, through the host's own fetch.

On the supported Node releases all 15 cases pass. On Node 22.19, whose
bundled undici predates nodejs/undici#5273, the six chunked shapes under
Connection: close fail.

* Judge the pattern differential by the edition the dialect names

JSON Schema 2020-12 core section 6.4 reads patterns in the dialect of
ECMA-262 section 21.2.1, and its normative reference is the 11th
edition (ES2020). The evaluator refuses syntax that edition lacks, but
the TypeScript differential treated the running V8 as the oracle, so on
Node 23 and 24, whose V8 accepts ES2025's modifiers such as (?i:a) and
duplicate named groups, 14 of its 1,505 rows differed and the test
failed.

Keep the checked-in fixture, recorded on V8 12.4, as the oracle: an
independent ES2020 pattern parser (regexpp, ecmaVersion 2020, unicode)
accepts exactly the patterns it accepts, so no entry changes. Compare
the live engine with it wherever a pattern uses only 11th edition
syntax, which is 1,458 rows, and for the 47 rows holding modifiers
(ES2025 section 22.2.1) or a repeated group name (section 22.2.1.1,
where the 11th edition's 21.2.1.1 refuses any repeat) require the
fixture's refusal instead. The evaluator still refuses all 47.

Name the edition where the documentation describes the dialect, and,
with the suite now passing on Node 24, run the whole TypeScript suite
in the CI leg at the 24 and 26 floors instead of only the discovery
tests.
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