Commit fbdee9fd authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Enable FP reporting for sync-xhr violations.

This queues a report through the Reporting API whenever send() is called
on a synchronous XMLHttpRequest object from a frame in which sync-xhr is
not allowed according to feature policy.

Bug: 867471
Change-Id: If778ea5517fb5728992fe8287b278d1af729902f
Reviewed-on: https://chromium-review.googlesource.com/1191404Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587583}
parent a0debb48
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<script>
var t = async_test("Sync-xhr Report Format");
var check_report_format = (reports, observer) => {
let report = reports[0];
assert_equals(report.type, "feature-policy");
assert_equals(report.url, document.location.href);
assert_equals(report.body.feature, "sync-xhr");
assert_equals(report.body.sourceFile, document.location.href);
assert_equals(typeof report.body.message, "string");
assert_equals(typeof report.body.lineNumber, "number");
assert_equals(typeof report.body.columnNumber, "number");
};
new ReportingObserver(t.step_func_done(check_report_format),
{types: ['feature-policy']}).observe();
t.step_func(() => {
var xhr = new XMLHttpRequest();
xhr.open("GET", document.location.href, false);
assert_throws('NetworkError',
() => xhr.send(),
"Synchronous XHR.send should throw an exception when disabled");
})();
</script>
</body>
</html>
...@@ -747,7 +747,8 @@ bool XMLHttpRequest::InitSend(ExceptionState& exception_state) { ...@@ -747,7 +747,8 @@ bool XMLHttpRequest::InitSend(ExceptionState& exception_state) {
if (!async_) { if (!async_) {
if (GetExecutionContext()->IsDocument() && if (GetExecutionContext()->IsDocument() &&
!GetDocument()->GetFrame()->IsFeatureEnabled( !GetDocument()->GetFrame()->IsFeatureEnabled(
mojom::FeaturePolicyFeature::kSyncXHR)) { mojom::FeaturePolicyFeature::kSyncXHR,
ReportOptions::kReportOnFailure)) {
LogConsoleError(GetExecutionContext(), LogConsoleError(GetExecutionContext(),
"Synchronous requests are disabled by Feature Policy."); "Synchronous requests are disabled by Feature Policy.");
HandleNetworkError(); HandleNetworkError();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment