Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<title>Parser-inserted external module scripts without a correct nonce are not allowed with `strict-dynamic` in the script-src directive.</title>
<script src='/resources/testharness.js' nonce='dummy'></script>
<script src='/resources/testharnessreport.js' nonce='dummy'></script>
<!-- CSP served: script-src 'strict-dynamic' 'nonce-dummy' -->
</head>
<body>
<h1>Parser-inserted external module scripts without a correct nonce are not allowed with `strict-dynamic` in the script-src directive.</h1>
<div id='log'></div>
<script nonce='dummy'>
async_test(function(t) {
window.addEventListener('message', t.step_func(function(e) {
if (e.data === 'markup-module') {
assert_unreached('Parser-inserted external module script in markup without a correct nonce is not allowed with `strict-dynamic`.');
}
}));
window.addEventListener('securitypolicyviolation', t.step_func(function(violation) {
if (!violation.blockedURI.includes('simpleSourcedModule.js?markup-module')) {
return;
}
assert_equals(violation.effectiveDirective, 'script-src-elem');
t.done();
}));
}, 'Parser-inserted external module script in markup without a correct nonce is not allowed with `strict-dynamic`.');
</script>
<script type="module" src="simpleSourcedModule.js?markup-module"></script>
<script nonce='dummy'>
async_test(function(t) {
window.addEventListener('message', t.step_func(function(e) {
if (e.data === 'documentWrite-module') {
assert_unreached('Parser-inserted external module script via `document.write` without a correct nonce is not allowed with `strict-dynamic`.');
}
}));
window.addEventListener('securitypolicyviolation', t.step_func(function(violation) {
if (!violation.blockedURI.includes('simpleSourcedModule.js?documentWrite-module')) {
return;
}
assert_equals(violation.effectiveDirective, 'script-src-elem');
t.done();
}));
document.write('<scr' + 'ipt type="module" src="simpleSourcedModule.js?documentWrite-module"></scr' + 'ipt>');
}, 'Parser-inserted external module script via `document.write` without a correct nonce is not allowed with `strict-dynamic`.');
</script>
<script nonce='dummy'>
async_test(function(t) {
window.addEventListener('message', t.step_func(function(e) {
if (e.data === 'documentWriteln-module') {
assert_unreached('Parser-inserted external module script via `document.writeln` without a correct nonce is not allowed with `strict-dynamic`.');
}
}));
window.addEventListener('securitypolicyviolation', t.step_func(function(violation) {
if (!violation.blockedURI.includes('simpleSourcedModule.js?documentWriteln-module')) {
return;
}
assert_equals(violation.effectiveDirective, 'script-src-elem');
t.done();
}));
document.writeln('<scr' + 'ipt type="module" src="simpleSourcedModule.js?documentWriteln-module"></scr' + 'ipt>');
}, 'Parser-inserted external module script via `document.writeln` without a correct nonce is not allowed with `strict-dynamic`.');
</script>
</body>
</html>