-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WPTs for invalid headers in Early Hints
When an Early Hints response contains an invalid header value the page should not be loaded. Bug: 1305896 Change-Id: Idafca361d186b4f07ab26d7ed16c9bd1cbfd3369 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3552064 Reviewed-by: Yutaka Hirano <[email protected]> Commit-Queue: Kenichi Ishibashi <[email protected]> Cr-Commit-Position: refs/heads/main@{#985831}
- Loading branch information
1 parent
7a48508
commit e9c5c4c
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
loading/early-hints/invalid-headers-in-early-hints.h2.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// META: script=/resources/testharness.js | ||
// META: script=/resources/testharnessreport.js | ||
|
||
async function testInvalidHeader(t, header_value) { | ||
const params = new URLSearchParams(); | ||
params.set("header-value", header_value); | ||
const test_url = "resources/invalid-headers-in-early-hints.h2.py?" + params.toString(); | ||
const opened_window = window.open(test_url, "invalid-header-in-early-hints"); | ||
|
||
// Use step_timeout() because neither "load" event nor postMessage() would | ||
// work. Opening the test page should result in a network protocol error and | ||
// accessing the document of the opened window should throw a SecurityError. | ||
await new Promise(resolve => t.step_timeout(resolve, 1000)); | ||
assert_throws_dom("SecurityError", () => { | ||
opened_window.document; | ||
}, "window.open() should not load the test page successfully."); | ||
} | ||
|
||
promise_test(async (t) => { | ||
await testInvalidHeader(t, "foo\r\nbar"); | ||
}, "Early Hints contains invalid header: newline byte"); | ||
|
||
promise_test(async (t) => { | ||
await testInvalidHeader(t, "foo\x00bar"); | ||
}, "Early Hints contains invalid header: nul byte"); |
20 changes: 20 additions & 0 deletions
20
loading/early-hints/resources/invalid-headers-in-early-hints.h2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
|
||
|
||
def handle_headers(frame, request, response): | ||
header_value = request.GET.first(b"header-value") | ||
early_hints = [ | ||
(b":status", b"103"), | ||
(b"invalid-header", header_value), | ||
] | ||
response.writer.write_raw_header_frame(headers=early_hints, | ||
end_headers=True) | ||
|
||
response.status = 200 | ||
response.headers[b"content-type"] = "text/html" | ||
response.write_status_headers() | ||
|
||
|
||
def main(request, response): | ||
test_content = "<div>This page should not be loaded.</div>" | ||
response.writer.write_data(item=test_content, last=True) |