Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<head>
<title>Non parser-inserted external module scripts should run 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>Non parser-inserted external module scripts should run with `strict-dynamic` in the script-src directive.</h1>
<div id='log'></div>
<script nonce='dummy'>
window.addEventListener('securitypolicyviolation', function(e) {
assert_unreached('No CSP violation report has fired.');
});
async_test(function(t) {
window.addEventListener('message', t.step_func(function(e) {
if (e.data === 'appendChild-module') {
t.done();
}
}));
var e = document.createElement('script');
e.type = 'module';
e.src = 'simpleSourcedModule.js?appendChild-module';
e.onerror = t.unreached_func('Error should not be triggered.');
document.body.appendChild(e);
}, 'Module script injected via `appendChild` is allowed with `strict-dynamic`.');
</script>
<script nonce='dummy'>
async_test(function(t) {
window.addEventListener('message', t.step_func(function(e) {
if (e.data === 'appendChild-module-incorrectNonce') {
t.done();
}
}));
var e = document.createElement('script');
e.type = 'module';
e.src = 'simpleSourcedModule.js?appendChild-module-incorrectNonce';
e.setAttribute('nonce', 'wrong');
e.onerror = t.unreached_func('Error should not be triggered.');
document.body.appendChild(e);
}, 'Module script injected via `appendChild` is allowed with `strict-dynamic`, even if it carries an incorrect nonce.');
</script>
</body>
</html>