Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest: response header value containing 0x00 #10424

Merged
merged 2 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fetch/api/basic/header-value-null-byte.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// META: global=window,worker

promise_test(t => {
return promise_rejects(t, new TypeError(), fetch("../../../xhr/resources/parse-headers.py?my-custom-header="+encodeURIComponent("x\0x")));
}, "Ensure fetch() rejects null bytes in headers");
23 changes: 12 additions & 11 deletions xhr/headers-normalize-response.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<title>Whitespace and null in header values</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js?pipe=sub></script>

<h1>Whitespace and null in response header values</h1>

<div id=log></div>

<script>
function error(val) {
test(() => {
const client = new XMLHttpRequest();
client.open("GET", "resources/parse-headers.py?my-custom-header="+encodeURIComponent(val), false);
assert_throws("NetworkError", () => client.send());
}, "Header value: " + val.replace("\0", "\\0"));
}

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

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

matchHeaderValue("hello world\0");
matchHeaderValue("\0hello world");
matchHeaderValue("hello\0world");
error("hello world\0");
error("\0hello world");
error("hello\0world");
matchHeaderValue(" hello world");
matchHeaderValue("hello world ");
matchHeaderValue(" hello world ");
Expand All @@ -34,9 +36,8 @@ <h1>Whitespace and null in response header values</h1>
matchHeaderValue("\thello world\t");
matchHeaderValue("hello world");
matchHeaderValue("hello\tworld");
matchHeaderValue("\0");
error("\0");
matchHeaderValue(" ");
matchHeaderValue("\t");
matchHeaderValue("");

</script>