Files
sousa-gecko/testing/web-platform/tests/content-security-policy/reporting-api/report-to-directive-allowed-in-meta.https.sub.html
T
Simon Farre 8eca60565d Bug 1909705 - Fix WPT to adhere to spec. r=dom-core,smaug
Make reporting of sourceFile, lineNumber, column more consistent

Changes the test so that it checks for nulls.

Added test (#2) that has script running and therefore should have source
information.

/content-security-policy/reporting-api/report-to-directive-allowed-in-meta.https.sub.html
also had the same problem, of expecting source code information with no
running javascript. Checks for null instead.

See https://w3c.github.io/webappsec-csp/#create-violation-for-global

Differential Revision: https://phabricator.services.mozilla.com/D278839
2026-03-04 13:40:12 +00:00

57 lines
2.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test that reports using the report-api service are sent when there's a violation</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<meta http-equiv="content-security-policy" content="script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-group">
</head>
<body>
<script>
var t1 = async_test("Test that image does not load");
async_test(function(t2) {
window.addEventListener("securitypolicyviolation", t2.step_func(function(e) {
assert_equals(e.blockedURI, "{{location[scheme]}}://{{location[host]}}/content-security-policy/support/fail.png");
assert_equals(e.violatedDirective, "img-src");
t2.done();
}));
}, "Event is fired");
async_test(function(t3) {
var observer = new ReportingObserver(function(reports, observer) {
t3.step(function() {
assert_equals(reports.length, 1);
// Ensure that the contents of the report are valid.
var base_url = "{{location[scheme]}}://{{location[host]}}/content-security-policy/"
var document_url = base_url + "reporting-api/report-to-directive-allowed-in-meta.https.sub.html";
assert_equals(reports[0].type, "csp-violation");
assert_equals(reports[0].url, document_url);
assert_equals(reports[0].body.documentURL, document_url);
assert_equals(reports[0].body.referrer, "");
assert_equals(reports[0].body.blockedURL,
base_url + "support/fail.png");
assert_equals(reports[0].body.effectiveDirective, "img-src");
assert_equals(reports[0].body.originalPolicy,
"script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-group");
assert_equals(reports[0].body.sourceFile, null);
assert_equals(reports[0].body.sample, "");
assert_equals(reports[0].body.disposition, "enforce");
assert_equals(reports[0].body.statusCode, 200);
assert_equals(reports[0].body.lineNumber, null);
assert_equals(reports[0].body.columnNumber, null);
});
t3.done();
});
observer.observe();
}, "Report is observable to ReportingObserver");
</script>
<img src='/content-security-policy/support/fail.png'
onload='t1.unreached_func("The image should not have loaded");'
onerror='t1.done();'>
<script async defer src='../support/checkReport.sub.js?reportField=effectiveDirective&reportValue=img-src%20%27none%27'></script>
</body>
</html>