summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/script-src/script-src-strict_dynamic_double_policy_report_only.html
blob: 1ceb74c63d1392672a36a2506b63c50199aa39fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE HTML>
<html>

<head>
    <title>A separate Report-Only policy does not influence `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:
    1) Content-Security-Policy: script-src 'strict-dynamic' 'nonce-dummy'
    2) Content-Security-Policy-Report-Only: script-src 'none'
    -->
</head>

<body>
    <h1>A separate Report-Only policy does not influence `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 === 'appendChild-reportOnly') {
                    t.done();
                }
            }));
            window.addEventListener('securitypolicyviolation', t.step_func(function(violation) {
                if (violation.blockedURI.split('?')[1] !== 'appendChild-reportOnly') {
                    return;
                }
                assert_equals(violation.effectiveDirective, 'script-src-elem');
                // Check that the violation comes from the Report-Only policy.
                assert_equals(violation.originalPolicy, "script-src 'none'");
                t.done();
            }));
            var e = document.createElement('script');
            e.id = 'appendChild-reportOnly';
            e.src = 'simpleSourcedScript.js?' + e.id;
            e.onerror = t.unreached_func('Error should not be triggered.');
            document.body.appendChild(e);
        }, 'Script injected via `appendChild` is allowed with `strict-dynamic` + Report-Only `script-src \'none\'` policy.');
    </script>
</body>

</html>