Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves request abort handling, prevents stream leaks on unreadable request bodies, and adds support for handling 1xx informational responses (excluding 101 protocol switching) in fetchOverStream. It also includes comprehensive unit tests for these scenarios. The review feedback recommends limiting the maximum number of consecutive informational responses to prevent potential denial of service (DoS) or infinite loop attacks from malicious peers.
| while (head.status >= 100 && head.status < 200) { | ||
| if (head.status === 101) { | ||
| throw new HTTPParseError("protocol switching is not supported by mesh fetch"); | ||
| } | ||
| head = await readResponseHead(reader); | ||
| } |
There was a problem hiding this comment.
To prevent potential denial of service (DoS) or infinite loops from a misconfigured or malicious peer sending an endless sequence of 1xx informational responses, we should limit the maximum number of informational responses we are willing to parse before throwing an error.
let head = await readResponseHead(reader);
let infoResponsesCount = 0;
while (head.status >= 100 && head.status < 200) {
if (head.status === 101) {
throw new HTTPParseError("protocol switching is not supported by mesh fetch");
}
if (++infoResponsesCount > 10) {
throw new HTTPParseError("too many informational responses");
}
head = await readResponseHead(reader);
}There was a problem hiding this comment.
Agreed, taken in c7ab00a. Without a caller deadline, a peer that answers with 1xx heads and never a final response kept the fetch reading indefinitely. The loop now reads at most MAX_INFORMATIONAL_RESPONSES (10) of them, which leaves room for a 100 Continue, a 103 Early Hints and a few 102 Processing, and then aborts the stream with an HTTPParseError. The test pins the edge: ten informational heads followed by a 200 are read through, and eleven are refused with the stream aborted.
A peer that answered with 1xx heads and never a final response kept fetchOverStream reading for as long as the caller had no deadline. Read at most MAX_INFORMATIONAL_RESPONSES of them, then abort the stream with an HTTPParseError; the test covers ten heads accepted and eleven refused.
82d32f5 to
c7ab00a
Compare
Fix three independently reproduced failure modes in the JavaScript mesh HTTP client.
Each fix is a separate commit with a deterministic regression. The tests use local fakes and ordinary HTTP response sequences.
Linux and Node.js 22 passed all 157 SDK tests, the type check, the package and example builds, and the browser bundle.