Files
firefox/testing/web-platform/tests/reporting/same-origin-same-site-credentials.https.sub.html
T
Ian Clelland ec3ca2a64f Bug 1734667 [wpt PR 30983] - Add credentials to same-origin Report uploads, a=testonly
Automatic update from web-platform-tests
Add credentials to same-origin Report uploads

When the reporting endpoint is same-origin with the page generating
reports, the reporting API specifies that credentials should be included
with the report delivery.

This change enables that behaviour for V1 reporting endpoints only --
any endpoints configured with the Report-To header are unaffected. This
CL corrects the way that we distinguish V0 from V1 endpoints at delivery
time, which also corrects the metrics collection for delivered reports,
and adds a test for a case which was previously missed.

Bug: 1163645
Change-Id: I8fcd934b3026b57374e7e7df31c9af9a8d93962d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3169200
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Maksim Orlovich <[email protected]>
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: Mike West <[email protected]>
Reviewed-by: Christian Dullweber <[email protected]>
Commit-Queue: Ian Clelland <[email protected]>
Cr-Commit-Position: refs/heads/main@{#929239}

--

wpt-commits: be7a5dacb872f190cfa6ed7062c2837cfb2c951c
wpt-pr: 30983
2021-10-14 04:45:22 +00:00

54 lines
2.7 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test that credentials are sent properly in a same-origin and also same-site nested context</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src='resources/report-helper.js'></script>
</head>
<body>
<script>
const base_url = `${location.protocol}//${location.host}`;
const endpoint = `${base_url}/reporting/resources/report.py`;
const id = 'd0d517bf-891b-457a-b970-8b2b2c81a0bf';
promise_test(async t => {
// If this is not run from the expected origin, then the A->A->A frame embedding will not be correct,
// and the cookies set in the top-level page will never be returned with the reports.
assert_true(location.href.startsWith("https://{{hosts[][]}}:{{ports[https][0]}}/"),
"Test running on unexpected origin; subsequent assertions will fail.");
// Set credentials, and set up test to clear them afterwards.
await fetch('/cookies/resources/setSameSite.py?reporting', {mode: 'no-cors', credentials: 'include', cache: 'no-store'});
t.add_cleanup(() => fetch("/cookies/resources/dropSameSite.py", {mode: 'no-cors', credentials: 'include', cache: 'no-store'}));
// Insert a same-origin frame which will then frame this origin to
// trigger a CSP error.
const frame = document.createElement('iframe');
frame.src = "https://{{hosts[][]}}:{{ports[https][0]}}/reporting/resources/middle-frame.https.sub.html";
document.body.appendChild(frame);
// Wait for the inner frame to signal that the report has been generated.
await new Promise(resolve => {
window.addEventListener('message', ev => {
if (ev.data === "done")
resolve(ev.data);
});
document.body.appendChild(frame);
});
const reports = await pollReports(endpoint, id);
checkReportExists(reports, 'csp-violation', "https://{{hosts[][]}}:{{ports[https][0]}}/reporting/resources/same-origin-report.https.sub.html");
// All credentials set at the top-level should be received.
const cookies = await pollCookies(endpoint, id);
assert_equals(cookies.samesite_none, "[samesite_none=reporting]", "Credential value was correct");
assert_equals(cookies.samesite_unspecified, "[samesite_unspecified=reporting]", "Credential value was correct");
assert_equals(cookies.samesite_lax, "[samesite_lax=reporting]", "Credential value was correct");
assert_equals(cookies.samesite_strict, "[samesite_strict=reporting]", "Credential value was correct");
assert_equals(Object.keys(cookies).length, 4, "No additional cookies were received");
}, "Reporting endpoints received credentials.");
</script>
</body>
</html>