-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new tests for credentials and isolation in reporting.
This adds WPT to ensure that credentials are not sent to cross-origin reporting endpoints, that they *are* sent to same-origin reporting endpoints (currently failing; tracked as crbug.com/1163645), and that reports which come from documents with different origins are not sent in the same bundle, even when configured to deliver reports to the same endpoint. Change-Id: Icb36647d02ad33e8a2f10901782ad9b92cd0f191 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2657296 Commit-Queue: Ian Clelland <iclelland@chromium.org> Reviewed-by: Rodney Ding <rodneyding@google.com> Cr-Commit-Position: refs/heads/main@{#920222} NOKEYCHECK=True GitOrigin-RevId: 1301ef614054581a025c24336e15072f0613c21a
- Loading branch information
1 parent
a42624c
commit ba19044
Showing
10 changed files
with
174 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
blink/web_tests/external/wpt/reporting/cross-origin-report-no-credentials.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test that reports are sent without credentials to cross-origin endpoints</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 => { | ||
// Set credentials, and set up test to clear them afterwards. | ||
await fetch('/cookies/resources/set-cookie.py?name=report&path=%2F', {mode: 'no-cors', credentials: 'include', cache: 'no-store'}); | ||
t.add_cleanup(() => fetch("/cookies/resources/set.py?report=; path=%2F; expires=Thu, 01 Jan 1970 00:00:01 GMT")); | ||
|
||
// Trigger a CSP error. | ||
await new Promise(resolve => { | ||
const img = document.createElement('img'); | ||
img.src = "/reporting/resources/fail.png"; | ||
img.addEventListener('error', resolve); | ||
document.body.appendChild(img); | ||
}); | ||
|
||
// Wait for report to be received. | ||
await wait(3000); | ||
const reports = await pollReports(endpoint, id); | ||
checkReportExists(reports, 'csp-violation', location.href); | ||
|
||
// Validate that credentials were not sent to cross-origin endpoint. | ||
const cookies = await pollCookies(endpoint, id); | ||
assert_equals(Object.keys(cookies).length, 0, "Credentials were absent from report"); | ||
}, "Reporting endpoints did not receive credentials."); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...ests/external/wpt/reporting/cross-origin-report-no-credentials.https.sub.html.sub.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Reporting-Endpoints: csp-endpoint="https://{{domains[www1]}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=d0d517bf-891b-457a-b970-8b2b2c81a0bf" | ||
Content-Security-Policy: script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-endpoint |
46 changes: 46 additions & 0 deletions
46
blink/web_tests/external/wpt/reporting/cross-origin-reports-isolated.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test that reports from different origins are not sent together</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 => { | ||
|
||
// Attach a cross-origin iframe which should post back here immediately | ||
// before generating a CSP error. That error should be reported to the | ||
// same endpoint that this frame reports to. | ||
await new Promise(resolve => { | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = "https://{{domains[www]}}:{{ports[https][0]}}/reporting/resources/csp-error.https.sub.html"; | ||
addEventListener('message', resolve); | ||
document.body.appendChild(iframe); | ||
}); | ||
|
||
// Trigger a CSP error and report in this frame as well. | ||
await new Promise(resolve => { | ||
const img = document.createElement('img'); | ||
img.src = "/reporting/resources/fail.png"; | ||
img.addEventListener('error', resolve); | ||
document.body.appendChild(img); | ||
}); | ||
|
||
// Wait for 2 reports to be received. | ||
await wait(3000); | ||
const reports = await pollReports(endpoint, id, 2); | ||
assert_equals(reports.length, 2); | ||
|
||
// Validate that reports were sent in separate requests. | ||
const request_count = await pollNumResults(endpoint, id); | ||
assert_equals(request_count, 2); | ||
}, "Reports were sent in two requests."); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...web_tests/external/wpt/reporting/cross-origin-reports-isolated.https.sub.html.sub.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Reporting-Endpoints: csp-endpoint="https://{{domains[www]}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=d0d517bf-891b-457a-b970-8b2b2c81a0bf" | ||
Content-Security-Policy: script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-endpoint |
19 changes: 19 additions & 0 deletions
19
blink/web_tests/external/wpt/reporting/resources/csp-error.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Notify parent on load and generate a CSP error</title> | ||
</head> | ||
<body> | ||
<script> | ||
addEventListener('load', () => { | ||
// Alert the parent frame that this frame has loaded. | ||
parent.postMessage('Loaded','*'); | ||
|
||
// Trigger a CSP error, which should generate a report. | ||
const img = document.createElement('img'); | ||
img.src = "/reporting/resources/fail.png"; | ||
document.body.appendChild(img); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
blink/web_tests/external/wpt/reporting/resources/csp-error.https.sub.html.sub.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Reporting-Endpoints: csp-endpoint="https://{{domains[www]}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=d0d517bf-891b-457a-b970-8b2b2c81a0bf" | ||
Content-Security-Policy: script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
blink/web_tests/external/wpt/reporting/same-origin-report-credentials.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Test that reports are sent with credentials to same-origin endpoints</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 => { | ||
// Set credentials, and set up test to clear them afterwards. | ||
await fetch('/cookies/resources/set-cookie.py?name=report&path=%2F', {mode: 'no-cors', credentials: 'include', cache: 'no-store'}); | ||
t.add_cleanup(() => fetch("/cookies/resources/set.py?report=; path=%2F; expires=Thu, 01 Jan 1970 00:00:01 GMT")); | ||
|
||
// Trigger a CSP error. | ||
await new Promise(resolve => { | ||
const img = document.createElement('img'); | ||
img.src = "/reporting/resources/fail.png"; | ||
img.addEventListener('error', resolve); | ||
document.body.appendChild(img); | ||
}); | ||
|
||
// Wait for report to be received. | ||
await wait(3000); | ||
const reports = await pollReports(endpoint, id); | ||
checkReportExists(reports, 'csp-violation', location.href); | ||
|
||
// Validate that credentials were sent to same-origin endpoint. | ||
const cookies = await pollCookies(endpoint, id); | ||
assert_true('report' in cookies, "Credentials were present in report"); | ||
assert_equals(cookies.report, "[report=1]", "Credential value was correct"); | ||
}, "Reporting endpoints received credentials."); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...eb_tests/external/wpt/reporting/same-origin-report-credentials.https.sub.html.sub.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Reporting-Endpoints: csp-endpoint="/reporting/resources/report.py?reportID=d0d517bf-891b-457a-b970-8b2b2c81a0bf" | ||
Content-Security-Policy: script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-endpoint |