Skip to content

Commit

Permalink
CSP: Enhance WPTs to check inline and eval blockedURIs
Browse files Browse the repository at this point in the history
This adds a few assertions to Web Platform Tests for Content Security
Policies checking if inline script execution and eval are allowed, so
that they also ensure that the blockedURI in the CSP violation matches
'inline' or 'eval'.

Bug: 563976
Change-Id: Ie2b93fe838768703e652dcfd5bd25b1334abcf57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2743762
Auto-Submit: Antonio Sartori <[email protected]>
Reviewed-by: Arthur Sonzogni <[email protected]>
Commit-Queue: Antonio Sartori <[email protected]>
Cr-Commit-Position: refs/heads/master@{#862765}
  • Loading branch information
antosart authored and chromium-wpt-export-bot committed Mar 15, 2021
1 parent 182810f commit accfb3c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
}
</script>

<script async defer src="../support/checkReport.sub.js?reportField=violated-directive&reportValue=script-src%20%27unsafe-inline%27"></script>
<script async defer src="../support/checkReport.sub.js?reportField=blocked-uri&reportValue=eval"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Set-Cookie: eval-allowed-in-report-only-mode-and-sends-report={{$id:uuid()}}; Path=/content-security-policy/script-src
Content-Security-Policy-Report-Only: script-src 'unsafe-inline'; report-uri /reporting/resources/report.py?op=put&reportID={{$id}}
Content-Security-Policy-Report-Only: script-src 'unsafe-inline' 'self'; report-uri /reporting/resources/report.py?op=put&reportID={{$id}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<title>injected-inline-script-blocked</title>
<script nonce='abc' src="/resources/testharness.js"></script>
<script nonce='abc' src="/resources/testharnessreport.js"></script>
<script nonce='abc' src='../support/logTest.sub.js?logs=["violated-directive=script-src-elem",]'></script>
<script nonce='abc' src='../support/logTest.sub.js?logs=["violated-directive=script-src-elem","blocked-uri=inline"]'></script>
<script nonce='abc' src='../support/alertAssert.sub.js?alerts=[]'></script>
</head>

<body>
<script nonce='abc'>
window.addEventListener('securitypolicyviolation', function(e) {
log("violated-directive=" + e.violatedDirective);
log("blocked-uri=" + e.blockedURI);
});
</script>
<script src="support/inject-script.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1>Scripts injected via `eval` are not allowed with `strict-dynamic` without `u
window.addEventListener('securitypolicyviolation', t.step_func_done(function(e) {
assert_false(evalScriptRan);
assert_equals(e.effectiveDirective, 'script-src');
assert_equals(e.blockedURI, 'eval');
}));

assert_throws_js(Error,
Expand Down

0 comments on commit accfb3c

Please sign in to comment.