diff options
Diffstat (limited to 'testing/web-platform/tests/content-security-policy/meta')
8 files changed, 219 insertions, 0 deletions
diff --git a/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html b/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html new file mode 100644 index 0000000000..70bfeb6b3b --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<html> + +<head> + <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.--> + <meta http-equiv="Content-Security-Policy" content="img-src 'none'"> + <title>combine-header-and-meta-policies</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src='../support/logTest.sub.js?logs=["TEST COMPLETE", "violated-directive=img-src", "violated-directive=style-src-elem"]'></script> + <script src="../support/alertAssert.sub.js?alerts=[]"></script> + <!-- enforcing multiple policies: +Content-Security-Policy: script-src 'self' 'unsafe-inline'; connect-src 'self'; style-src 'self' +Content-Security-Policy: img-src 'none' +--> +</head> + +<body> +<p>Test passes if both style and image are blocked and a report is generated for the + style block from the header-supplied policy.</p> + + <script> + window.addEventListener('securitypolicyviolation', function(e) { + log("violated-directive=" + e.violatedDirective); + }); + + var img = document.createElement('img'); + img.src = '../support/fail.png'; + img.onerror = function() { + log("TEST COMPLETE"); + }; + img.onload = function() { + log("FAIL"); + }; + document.body.appendChild(img); + + </script> + <style> + body { + background-color: blue; + } + + </style> + <script> + var el = document.querySelector('body'); + test(function() { + assert_equals(window.getComputedStyle(el).color, "rgb(0, 0, 0)") + }); + + </script> + <div id="log"></div> +</body> + +</html> diff --git a/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html.sub.headers b/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html.sub.headers new file mode 100644 index 0000000000..062d823228 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/combine-header-and-meta-policies.sub.html.sub.headers @@ -0,0 +1,5 @@ +Expires: Mon, 26 Jul 1997 05:00:00 GMT +Cache-Control: no-store, no-cache, must-revalidate +Cache-Control: post-check=0, pre-check=0, false +Pragma: no-cache +Content-Security-Policy: script-src 'self' 'unsafe-inline'; connect-src 'self'; style-src 'self'; diff --git a/testing/web-platform/tests/content-security-policy/meta/meta-img-src.html b/testing/web-platform/tests/content-security-policy/meta/meta-img-src.html new file mode 100644 index 0000000000..bc7ffd66a7 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/meta-img-src.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html> + +<head> + <meta id="meta_csp" http-equiv="Content-Security-Policy" content="img-src 'none'"> + <title>meta-img-src</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src='../support/logTest.sub.js?logs=["PASS","TEST COMPLETE"]'></script> +</head> + +<body> +<p>Test passes if the image is blocked.</p> + + <script> + function testImgSrc() { + var img = document.createElement('img'); + img.src = '../support/fail.png'; + img.onerror = function() { + log("PASS"); + }; + img.onload = function() { + log("FAIL"); + }; + document.body.appendChild(img); + } + testImgSrc(); + log("TEST COMPLETE"); + </script> + <div id="log"></div> +</body> + +</html> diff --git a/testing/web-platform/tests/content-security-policy/meta/meta-modified.html b/testing/web-platform/tests/content-security-policy/meta/meta-modified.html new file mode 100644 index 0000000000..d03115f31b --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/meta-modified.html @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> + +<head> + <meta id="meta_csp" http-equiv="Content-Security-Policy" content="img-src 'none'"> + <title>meta-modified</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src='../support/logTest.sub.js?logs=["PASS", "PASS","TEST COMPLETE"]'></script> +</head> + +<body> +<p>Test passes if the image is blocked both before and after policy modification.</p> + + <script> + function testImgSrc() { + var img = document.createElement('img'); + img.src = '../support/fail.png'; + img.onerror = function() { + log("PASS"); + }; + img.onload = function() { + log("FAIL"); + }; + document.body.appendChild(img); + } + testImgSrc(); + document.getElementById("meta_csp").setAttribute("content", "img-src *"); + testImgSrc(); + log("TEST COMPLETE"); + </script> + <div id="log"></div> +</body> + +</html> diff --git a/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html b/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html new file mode 100644 index 0000000000..7a706c2fc5 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<html> + +<head> + <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.--> + <title>meta-outside-head</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="../support/logTest.sub.js?logs=[]"></script> + <script src='../support/alertAssert.sub.js?alerts=["PASS (1/1)"]'></script> + <!-- enforcing policy: +script-src 'self' 'unsafe-inline' 'nonce-abc'; connect-src 'self'; +--> +</head> + +<body> + <script nonce='abc'> + window.addEventListener('securitypolicyviolation', function(e) { + alert_assert("Fail"); + }); + </script> + + <meta http-equiv="Content-Security-Policy" content="script-src 'self'"> + <p>This test checks that Content Security Policy delivered via a meta element is not enforced if the element is outside the document's head.</p> + <script nonce='abc'> + var aa = "PASS (1/1)"; + </script> + <script src="../meta/support/metaHelper.js"></script> + <div id="log"></div> +</body> + +</html> diff --git a/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html.sub.headers b/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html.sub.headers new file mode 100644 index 0000000000..8e90073147 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/meta-outside-head.sub.html.sub.headers @@ -0,0 +1 @@ +Content-Security-Policy: script-src 'self' 'unsafe-inline' 'nonce-abc'; connect-src 'self'; diff --git a/testing/web-platform/tests/content-security-policy/meta/sandbox-iframe.html b/testing/web-platform/tests/content-security-policy/meta/sandbox-iframe.html new file mode 100644 index 0000000000..d353cafae1 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/sandbox-iframe.html @@ -0,0 +1,54 @@ +<!DOCTYPE HTML> +<html> + +<head> + <meta http-equiv="Content-Security-Policy" content="base-uri {{location[scheme]}}://{{domains[]}}:{{ports[http][0]}}/base/"> + + <title>base-uri works correctly inside a sandboxed iframe.</title> + <script src='/resources/testharness.js'></script> + <script src='/resources/testharnessreport.js'></script> +</head> + +<body> + <h1>self is derived correctly inside inside a sandboxed iframe.</h1> + <div id='log'></div> + + <script> + window.addEventListener('securitypolicyviolation', function(e) { + assert_unreached('No CSP violation report should have been fired.'); + }); + + async_test(function(t) { + var i = document.createElement('iframe'); + i.sandbox = 'allow-scripts'; + i.style.display = 'none'; + i.srcdoc = ` + <meta http-equiv="Content-Security-Policy" content="img-src 'self'"> + <body> + <script> + + var img = document.createElement('img'); + img.src = '../support/fail.png'; + img.onerror = function() { + top.postMessage('FAIL', '*'); + }; + img.onload = function() { + top.postMessage('PASS', '*'); + }; + document.body.appendChild(img); + </sc` + `ript></body>`; + + window.addEventListener('message', t.step_func(function(e) { + if (e.source === i.contentWindow) { + assert_equals(e.data, 'PASS'); + t.done(); + } + })); + + document.body.appendChild(i); + }, 'img-src \'self\' works when specified in a meta tag.'); + </script> + +</body> + +</html> diff --git a/testing/web-platform/tests/content-security-policy/meta/support/metaHelper.js b/testing/web-platform/tests/content-security-policy/meta/support/metaHelper.js new file mode 100644 index 0000000000..9191a39c73 --- /dev/null +++ b/testing/web-platform/tests/content-security-policy/meta/support/metaHelper.js @@ -0,0 +1,5 @@ +if (typeof aa != 'undefined') { + alert_assert(aa); +} else { + alert_assert("Failed - allowed inline script blocked by meta policy outside head."); +} |