undici vulnerable to Denial of Service via unhandled exception in stream() on request body errors
Description
Impact
When an application uses the stream() API with a Node.js Readable request body over HTTP/2, a server that starts a response and then destroys the HTTP/2 session while the upload is still pending can terminate the Node.js process. One request-body error event reaches StreamHandler.onResponseError twice. The second call clears the stored callback, and the response writable's error handler then calls runInAsyncScope(null, ...) (lib/api/api-stream.js). That throws an uncaught TypeError: Function.prototype.apply was called on null, which the application's callback and error handling never see, and the process exits.
The attacker controls only the HTTP/2 server's behavior. The application must use stream() with a streaming request body that has not been fully sent when the response starts. request(), Buffer and generator bodies, and HTTP/1.1 socket destruction are not affected by the remote trigger. The same crash occurs without an attacker when the application's own request body stream errors after the response has started, including over HTTP/1.1. The 7.x and 8.x release lines are affected. On 6.x, the HTTP/2 client reports the session error before the request body error, so the remote trigger does not reach this crash; undici 6.29.2 still includes the fix for the application-triggered case.
Patches
Upgrade to undici 7.30.4 or 8.14.1.
Workarounds
Use request() instead of stream() for streaming uploads to untrusted HTTP/2 servers, or send fully buffered request bodies.