Repository navigation
Reject fetch() with a TypeError for a response head that doesn't parse - #8535
Conversation
There was a problem hiding this comment.
Superseded by the review of
acdebe17.
This review, of 28020849
✅ Approved — No issues found: the error mapping is consistent across kj and kj-hyper, and the Rust unit test and the WPT expectations cover it.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
I checked the changed code against its callers. The parse-error mapping in client_error is consistent at every call site, and the description string is the same in client.rs and http.c++. The new fetch() branch follows the neighbouring branches, and the WPT expectations match in both configurations.
📝 Documentation: ✅ LGTM
The comments describe the code as it is now and point to their counterpart in the other layer.
Reviewed commit: 28020849
2802084 to
acdebe1
Compare
There was a problem hiding this comment.
Superseded by the review of
f84304c1.
This review, of acdebe17
💬 Approved with comments — No defects found. One question asks which change makes security/1xx-response.any.js pass, since a 1xx-then-close response does not obviously go through the new parse-error mapping.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The client.rs mapping is correct. One question about the 1xx WPT expectation.
Recommendation: 💬 Optional Nits
- [QUESTION] Which change makes
security/1xx-response.any.jsreject with a TypeError? The pull request description doesn't mention this expectation change. (src/wpt/fetch/misc-test.ts:506)
View full review
client_error checks for an io::Error first, so real I/O failures keep their mapping. It then returns FAILED with INVALID_RESPONSE for a hyper::Error where is_parse() is true. That string matches the third entry of isInvalidResponseError in src/workerd/api/http.c++, and the comments on each side point to the other. The new test a_response_head_that_does_not_parse_fails_as_kj_does covers this branch.
The pull request also removes the expected failures for security/1xx-response.any.js in src/wpt/fetch/misc-test.ts. The description doesn't mention this, and it isn't clear which change fixes it (see the question).
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only maps response-head parse failures to a FAILED error and a TypeError. It adds no new input path, and the error text contains no secrets.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
⚡ Performance: ✅ LGTM
The new work runs only when a request fails: a source-chain walk in client_error and a substring check over three short strings in http.c++.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour and point to their counterpart in the other layer.
Reviewed commit: acdebe17
acdebe1 to
f84304c
Compare
There was a problem hiding this comment.
Superseded by the review of
d579844e.
This review, of f84304c1
💬 Approved with comments — No defects found. One question asks which change makes security/1xx-response.any.js pass, since a 1xx-then-close response does not obviously go through the new parse-error mapping.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The client.rs mapping is correct. One question about the 1xx WPT expectation.
Recommendation: 💬 Optional Nits
- [QUESTION] Which change makes
security/1xx-response.any.jsreject with a TypeError? The pull request description doesn't mention this expectation change. (src/wpt/fetch/misc-test.ts:506)
View full review
client_error checks for an io::Error first, so real I/O failures keep their mapping. It then returns FAILED with INVALID_RESPONSE for a hyper::Error where is_parse() is true. That string matches the third entry of isInvalidResponseError in src/workerd/api/http.c++, and the comments on each side point to the other. The new test a_response_head_that_does_not_parse_fails_as_kj_does covers this branch.
The pull request also removes the expected failures for security/1xx-response.any.js in src/wpt/fetch/misc-test.ts. The description doesn't mention this, and it isn't clear which change fixes it (see the question).
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only maps response-head parse failures to a FAILED error and a TypeError. It adds no new input path, and the error text contains no secrets.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
⚡ Performance: ✅ LGTM
The new work runs only when a request fails: a source-chain walk in client_error and a substring check over three short strings in http.c++.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour and point to their counterpart in the other layer.
Reviewed commit: f84304c1 — same changes as acdebe17, so this is that commit's review (no new review was run; line numbers are as of acdebe17)
f84304c to
d579844
Compare
There was a problem hiding this comment.
Superseded by the review of
1b9fb557.
This review, of d579844e
💬 Approved with comments — No defects found. One question asks which change makes security/1xx-response.any.js pass, since a 1xx-then-close response does not obviously go through the new parse-error mapping.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The Rust and C++ mapping is consistent and tested. One question remains about the removed security/1xx-response.any.js expected failures.
Recommendation: 💬 Optional Nits
- [QUESTION] Which change makes
security/1xx-response.any.jsreject with a TypeError? The pull request description doesn't mention this expectation change. (src/wpt/fetch/misc-test.ts:506)
View full review
client_error checks for an io::Error first, so real I/O failures keep their mapping. A hyper::Error where is_parse() is true fails as FAILED with kj's "The headers sent by the server are not valid." description. The new isInvalidResponseError in src/workerd/api/http.c++ matches that string and kj's own two response-parse descriptions, and maps all three to a TypeError. The new kj-hyper test covers this branch.
The pull request also removes the expected failures for security/1xx-response.any.js. The description doesn't mention this, and it isn't clear which path now produces the TypeError (see the question).
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only maps response-head parse failures to a FAILED error and a TypeError. It adds no new input path, and the error text contains no secrets.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
⚡ Performance: ✅ LGTM
The new work runs only when a request fails: a source-chain walk in client_error and a substring check over three short strings in http.c++.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour and point to their counterpart in the other layer.
Reviewed commit: d579844e
There was a problem hiding this comment.
Superseded by the review of
d2ee7397.
This review, of 1b9fb557
💬 Approved with comments — No defects found. One question asks which change makes security/1xx-response.any.js pass, since a 1xx-then-close response does not obviously go through the new parse-error mapping.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The Rust and C++ mapping is consistent and tested. One question remains about the removed security/1xx-response.any.js expected failures.
Recommendation: 💬 Optional Nits
- [QUESTION] Which change makes
security/1xx-response.any.jsreject with a TypeError? The pull request description doesn't mention this expectation change. (src/wpt/fetch/misc-test.ts:506)
View full review
client_error checks for an io::Error first, so real I/O failures keep their mapping. A hyper::Error where is_parse() is true fails as FAILED with kj's "The headers sent by the server are not valid." description. The new isInvalidResponseError in src/workerd/api/http.c++ matches that string and kj's own two response-parse descriptions, and maps all three to a TypeError. The new kj-hyper test covers this branch.
The pull request also removes the expected failures for security/1xx-response.any.js. The description doesn't mention this, and it isn't clear which path now produces the TypeError (see the question).
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only maps response-head parse failures to a FAILED error and a TypeError. It adds no new input path, and the error text contains no secrets.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
⚡ Performance: ✅ LGTM
The new work runs only when a request fails: a source-chain walk in client_error and a substring check over three short strings in http.c++.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour and point to their counterpart in the other layer.
Reviewed commit: 1b9fb557 — same changes as d579844e, so this is that commit's review (no new review was run; line numbers are as of d579844e)
There was a problem hiding this comment.
Superseded by the review of
47c3414f.
This review, of d2ee7397
✅ Approved — No defects found. The earlier question about the 1xx-response WPT cases is answered by the updated description, and it matches the code path.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only alters how a response head that fails to parse is reported. It adds no new input path, and the error text exposes nothing sensitive.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
📋 Code Quality: ✅ LGTM
Real I/O failures still take their existing mapping, because client_error checks for an io::Error first in the source chain. A hyper parse failure now fails as FAILED with kj's description, and the new kj-hyper test covers that path. isInvalidResponseError matches that description and kj's own response-parse descriptions. The 1xx-response expectation change follows from the same mapping, as the updated description explains.
⚡ Performance: ✅ LGTM
The new work runs only on the error path: a walk of the error's source chain and a few short substring checks.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour, and each points to its counterpart in the other layer.
Reviewed commit: d2ee7397
There was a problem hiding this comment.
Superseded by the review of
316c7617.
This review, of 47c3414f
✅ Approved — No defects found. The earlier question about the 1xx-response WPT cases is answered by the updated description, and it matches the code path.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only alters how a response head that fails to parse is reported. It adds no new input path, and the error text exposes nothing sensitive.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
📋 Code Quality: ✅ LGTM
Real I/O failures still take their existing mapping, because client_error checks for an io::Error first in the source chain. A hyper parse failure now fails as FAILED with kj's description, and the new kj-hyper test covers that path. isInvalidResponseError matches that description and kj's own response-parse descriptions. The 1xx-response expectation change follows from the same mapping, as the updated description explains.
⚡ Performance: ✅ LGTM
The new work runs only on the error path: a walk of the error's source chain and a few short substring checks.
📝 Documentation: ✅ LGTM
The comments describe the current behaviour, and each points to its counterpart in the other layer.
Reviewed commit: 47c3414f — same changes as d2ee7397, so this is that commit's review (no new review was run; line numbers are as of d2ee7397)
47c3414 to
316c761
Compare
There was a problem hiding this comment.
Superseded by the review of
430a437e.
This review, of 316c7617
💬 Approved with comments — No defects found. The only notes are an untested flag-off path and a pull request description that predates the new compatibility flag.
Findings: 2 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
The code is correct. The flag-off path has no test, and the description no longer matches the code.
Recommendation: 💬 Optional Nits
- [INFO] The flag-off path (plain
Error, 'Server returned invalid HTTP response: …') has no test; every WPT target turns the flag on. (src/workerd/api/http.c++:2023) - [INFO] The pull request description says there is no compatibility flag and quotes
TypeError: Received an invalid HTTP response., but this flag was added and the message is 'Server returned invalid HTTP response: <reason>'. (src/workerd/io/compatibility-date.capnp:1856)
View full review
- The new compatibility flag is tested only with the flag on. Nothing covers the default path, which now rejects with an
Errorand the new message. - The pull request description says there is no compatibility flag and quotes a different error message.
✅ All other checks passed
🔒 Security: ✅ LGTM
The change only alters how a response head that fails to parse is reported. It adds no new input path.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
⚡ Performance: ✅ LGTM
The new work runs only on the error path.
📝 Documentation: ✅ LGTM
The flag's doc comment describes both behaviours accurately.
Reviewed commit: 316c7617
When a server's response head doesn't parse, such as a header value with a NUL byte, Fetch treats it as a network error and rejects with a TypeError. workerd's outbound client, kj-hyper, reported hyper's parse error as DISCONNECTED, so fetch() rejected with "Network connection lost.". kj's HttpClient, with its default error handler, failed with its protocol error description, which JavaScript saw as an internal error. In this patch kj-hyper fails a response head that doesn't parse with FAILED and kj's description, "The headers sent by the server are not valid.", followed by hyper's cause. fetch() turns kj's response-parse descriptions into "Server returned invalid HTTP response: <reason>". With the new fetch_invalid_response_type_error compatibility flag it rejects with a TypeError; without it, with an Error. The flag has no enable date yet. fetch-invalid-response-test checks both cases against a server that sends a NUL byte in a header value. The fetch/api and fetch/misc WPT targets enable the flag. basic/header-value-null-byte.any.js now passes, and so do the three security/1xx-response.any.js cases, where a server answers with only a 1xx status: hyper skips the 1xx head and fails to parse the body that follows as the next status line. The two basic/request-headers-case.any.js cases stay expected failures, with the reason in place of "To be investigated": the first name's casing is kept, but each value goes on its own header line, which RFC 9110 allows, and the test expects one combined line.
316c761 to
430a437
Compare
There was a problem hiding this comment.
✅ Approved — No defects found. Both earlier notes are resolved: the flag-off path now has a test, and the description matches the code.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only alters how a response head that fails to parse is reported. It adds no new input path.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md changes are needed.
📋 Code Quality: ✅ LGTM
Both earlier notes are resolved. The new wd-test covers the flag-off (Error) and flag-on (TypeError) paths, and the description now matches the code.
- kj-hyper: a parse error maps to FAILED with kj's description. That check runs after the
io::Errordowncast, so I/O errors map as before. http.c++: the reason matcher uses its view of the exception description right away, so the view doesn't outlive the description.- Compatibility flag: ordinal
@208is not reused.
⚡ Performance: ✅ LGTM
The new work runs only on the error path. Nothing on the success path changes.
📝 Documentation: ✅ LGTM
The flag's doc comment describes both behaviours accurately.
Reviewed commit: 430a437e
When a server's response head doesn't parse, such as a header value with a NUL byte, Fetch treats it as a network error and rejects with a TypeError. workerd's outbound client, kj-hyper, reported hyper's parse error as DISCONNECTED, so
fetch()rejected with "Network connection lost.". kj'sHttpClientwith its default error handler failed with its protocol error description, which JavaScript saw as an internal error.In this patch:
fetch()turns kj's response-parse descriptions intoServer returned invalid HTTP response: <reason>. With the newfetch_invalid_response_type_errorcompatibility flag it rejects with a TypeError; without it, with an Error. The flag has no enable date yet.fetch/apiandfetch/miscWPT targets enable the flag.basic/header-value-null-byte.any.jsnow passes, and so do the threesecurity/1xx-response.any.jscases, where the server answers with only a 1xx status: hyper skips the 1xx head and fails to parse the body that follows as the next status line.basic/request-headers-case.any.jscases stay expected failures, with the reason in place of "To be investigated". The first name's casing is kept, but each value goes on its own header line, which RFC 9110 allows, and the test expects one combined line.