-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1872206 [wpt PR 43808] - Add more dangling markup tests to WPT, a…
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808
- Loading branch information
1 parent
6bfe037
commit 6bac0e2
Showing
6 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
testing/web-platform/tests/fetch/security/dangling-markup/media.html
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,27 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
var resources = {"audio": "/media/sound_5.mp3", "video":"/media/test.mp4"}; | ||
|
||
for (const key in resources){ | ||
async_test(t => { | ||
let elem = document.body.appendChild(document.createElement(key)); | ||
elem.onerror = t.unreached_func(`${key} should load`); | ||
elem.oncanplay = t.step_func(() => { | ||
t.done(); | ||
}); | ||
elem.src = resources[key]; | ||
}, `Should load ${key}`); | ||
|
||
async_test(t => { | ||
let elem = document.body.appendChild(document.createElement(key)); | ||
elem.onerror = t.step_func(() => { | ||
t.done(); | ||
}); | ||
elem.oncanplay = t.unreached_func(`${key} should not load`); | ||
elem.src = resources[key] + "?\n<"; | ||
}, `Should not load ${key} with dangling markup in URL`); | ||
} | ||
</script> |
51 changes: 51 additions & 0 deletions
51
testing/web-platform/tests/fetch/security/dangling-markup/option.html
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,51 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="./resources/helper.js"></script> | ||
<body> | ||
<script> | ||
|
||
var tests = [ | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<select name="dangling"><option> | ||
`, | ||
` | ||
<div> | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<select name="dangling"><option> | ||
`, | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post" id="form"> | ||
<input type="submit"> | ||
</form> | ||
<select name="dangling" form="form"><option> | ||
`, | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<select name="dangling"><option label="yay"> | ||
`, | ||
` | ||
<div> | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<select name="dangling"><option label="yay"> | ||
`, | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post" id="form"> | ||
<input type="submit"> | ||
</form> | ||
<select name="dangling" form="form"><option label="yay"> | ||
` | ||
]; | ||
|
||
tests.forEach(markup => { | ||
async_test(t => { | ||
var i = createFrame(`${markup}sekrit<element attribute></element>`); | ||
assert_no_submission(t, i); | ||
}, markup.replace(/[\n\r]/g, '')); | ||
}); | ||
</script> |
63 changes: 63 additions & 0 deletions
63
testing/web-platform/tests/fetch/security/dangling-markup/resources/helper.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,63 @@ | ||
function assert_no_message_from_frame(test, frame) { | ||
window.addEventListener("message", test.step_func(e => { | ||
assert_not_equals(e.source, frame.contentWindow); | ||
})); | ||
} | ||
|
||
function appendFrameAndGetElement(test, frame) { | ||
return new Promise((resolve, reject) => { | ||
frame.onload = test.step_func(_ => { | ||
frame.onload = null; | ||
resolve(frame.contentDocument.querySelector('#dangling')); | ||
}); | ||
document.body.appendChild(frame); | ||
}); | ||
} | ||
|
||
function appendAndSubmit(test, frame) { | ||
return new Promise((resolve, reject) => { | ||
frame.onload = test.step_func(_ => { | ||
frame.onload = null; | ||
frame.contentDocument.querySelector('form').addEventListener("error", _ => { | ||
resolve("error"); | ||
}); | ||
frame.contentDocument.querySelector('form').addEventListener("submit", _ => { | ||
resolve("submit"); | ||
}); | ||
frame.contentDocument.querySelector('[type=submit]').click(); | ||
}); | ||
document.body.appendChild(frame); | ||
}); | ||
} | ||
|
||
function assert_no_submission(test, frame) { | ||
assert_no_message_from_frame(test, frame); | ||
|
||
appendAndSubmit(test, frame) | ||
.then(test.step_func_done(result => { | ||
assert_equals(result, "error"); | ||
frame.remove(); | ||
})); | ||
} | ||
|
||
function assert_img_loaded(test, frame) { | ||
appendFrameAndGetElement(test, frame) | ||
.then(test.step_func_done(img => { | ||
assert_equals(img.naturalHeight, 103, "Height"); | ||
assert_equals(img.naturalWidth, 76, "Width"); | ||
})); | ||
} | ||
|
||
function assert_img_not_loaded(test, frame) { | ||
appendFrameAndGetElement(test, frame) | ||
.then(test.step_func_done(img => { | ||
assert_equals(img.naturalHeight, 0, "Height"); | ||
assert_equals(img.naturalWidth, 0, "Width"); | ||
})); | ||
} | ||
|
||
function createFrame(markup) { | ||
var i = document.createElement('iframe'); | ||
i.srcdoc = `${markup}sekrit`; | ||
return i; | ||
} |
34 changes: 34 additions & 0 deletions
34
testing/web-platform/tests/fetch/security/dangling-markup/textarea.html
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,34 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="./resources/helper.js"></script> | ||
<body> | ||
<script> | ||
|
||
var tests = [ | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<textarea name="dangling"> | ||
`, | ||
` | ||
<div> | ||
<form action="/resource-timing/resources/document-navigated.html" method="post"> | ||
<input type="submit"> | ||
<textarea name="dangling"> | ||
`, | ||
` | ||
<form action="/resource-timing/resources/document-navigated.html" method="post" id="form"> | ||
<input type="submit"> | ||
</form> | ||
<textarea name="dangling" form="form"> | ||
` | ||
]; | ||
|
||
tests.forEach(markup => { | ||
async_test(t => { | ||
var i = createFrame(`${markup}sekrit<element attribute></element>`); | ||
assert_no_submission(t, i); | ||
}, markup.replace(/[\n\r]/g, '')); | ||
}); | ||
</script> |