Skip to content

Commit

Permalink
[CSP] test that quote characters other than U+0027 APOSTROPHE don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip committed May 14, 2020
1 parent e4d5929 commit 707e848
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions content-security-policy/generic/quote-characters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
var tests = [
{ "csp": "img-src 'none';", "expected": false, "name": "precondition: single quotes are accepted" },
// See https://github.com/w3c/webappsec-csp/issues/434 for background on what is tested.
{ "csp": 'img-src "none";', "expected": true, "name": "double quotes should not be accepted" },
{ "csp": "img-src \u0091none'", "expected": true, "name": "U+0091 + single quote should not be accepted" },
{ "csp": "img-src 'none\u0092", "expected": true, "name": "single quote + U+0092 should not be accepted" },
{ "csp": "img-src \u0091none\u0092", "expected": true, "name": "U+0091 + U+0092 should not be accepted" },
{ "csp": "img-src \u2018none\u2019;", "expected": true, "name": "U+2018 + U+2019 should not be accepted" },
];

tests.forEach(test => {
async_test(t => {
var url = "support/load_img_and_post_result_meta.sub.html?csp=" + encodeURIComponent(test.csp);
test_image_loads_as_expected(test, t, url);
}, test.name + " - meta tag");

async_test(t => {
var url = "support/load_img_and_post_result_meta.sub.html?csp=" + encodeURIComponent(test.csp);
test_image_loads_as_expected(test, t, url);
}, test.name + " - HTTP header");
});

function test_image_loads_as_expected(test, t, url) {
var i = document.createElement("iframe");
i.src = url;
window.addEventListener("message", t.step_func(function(e) {
if (e.source != i.contentWindow) return;
if (test.expected) {
assert_equals(e.data, "img loaded");
} else {
assert_equals(e.data, "img not loaded");
}
t.done();
}));
document.body.appendChild(i);
}
</script>
</body>
</html>

0 comments on commit 707e848

Please sign in to comment.