Skip to content

Commit 3d172bc

Browse files
authored
Fetch/XHR: response header value containing 0x00
As discussed in whatwg/xhr#165 these should turn the response into a network error.
1 parent 2c9aebf commit 3d172bc

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// META: global=window,worker
2+
3+
promise_test(t => {
4+
return promise_rejects(t, new TypeError(), fetch("../../../xhr/resources/parse-headers.py?my-custom-header="+encodeURIComponent("x\0x")));
5+
}, "Ensure fetch() rejects null bytes in headers");

xhr/headers-normalize-response.htm

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
<title>Whitespace and null in header values</title>
44
<script src=/resources/testharness.js></script>
55
<script src=/resources/testharnessreport.js></script>
6-
<script src=support.js?pipe=sub></script>
7-
8-
<h1>Whitespace and null in response header values</h1>
9-
106
<div id=log></div>
11-
127
<script>
8+
function error(val) {
9+
test(() => {
10+
const client = new XMLHttpRequest();
11+
client.open("GET", "resources/parse-headers.py?my-custom-header="+encodeURIComponent(val), false);
12+
assert_throws("NetworkError", () => client.send());
13+
}, "Header value: " + val.replace("\0", "\\0"));
14+
}
1315

1416
function matchHeaderValue(val) {
1517
test(function () {
@@ -20,12 +22,12 @@ <h1>Whitespace and null in response header values</h1>
2022
var r = client.getResponseHeader("My-Custom-Header");
2123

2224
assert_equals(r, trimmed);
23-
}, "Header value: " + val.replace(/\t/g, "[tab]").replace(/ /g, "_").replace("\0", "\\0"));
25+
}, "Header value: " + val.replace(/\t/g, "[tab]").replace(/ /g, "_"));
2426
}
2527

26-
matchHeaderValue("hello world\0");
27-
matchHeaderValue("\0hello world");
28-
matchHeaderValue("hello\0world");
28+
error("hello world\0");
29+
error("\0hello world");
30+
error("hello\0world");
2931
matchHeaderValue(" hello world");
3032
matchHeaderValue("hello world ");
3133
matchHeaderValue(" hello world ");
@@ -34,9 +36,8 @@ <h1>Whitespace and null in response header values</h1>
3436
matchHeaderValue("\thello world\t");
3537
matchHeaderValue("hello world");
3638
matchHeaderValue("hello\tworld");
37-
matchHeaderValue("\0");
39+
error("\0");
3840
matchHeaderValue(" ");
3941
matchHeaderValue("\t");
4042
matchHeaderValue("");
41-
4243
</script>

0 commit comments

Comments
 (0)