Skip to content

Commit 8525dd8

Browse files
[shared storage] Implement the Shared-Storage-Worklet-Allowed response header check
When creating a cross-origin worklet, require the "Shared-Storage-Worklet-Allowed: ?1" response header, or the request should fail (similar to the handling for CORS failure). Note that shared storage worklet request doesn't allow redirects, so it's sufficient to check inside `OnReceiveResponse` only. PR: WICG/shared-storage#131 Bug: 332564979 Change-Id: I6c2a07473527ede995cf4bd337d293f3168351bb
1 parent ba78e8f commit 8525dd8

8 files changed

+69
-0
lines changed

shared-storage/cross-origin-create-worklet-credentials-include.tentative.https.sub.html

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
`/shared-storage/resources/credentials-test-helper.py` +
2020
`?access_control_allow_origin_header=${window.origin}` +
2121
`&access_control_allow_credentials_header=true` +
22+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
2223
`&token=${ancestor_key}`;
2324

2425
await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });

shared-storage/cross-origin-create-worklet-credentials-omit.tentative.https.sub.html

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const helper_url = crossOrigin +
1919
`/shared-storage/resources/credentials-test-helper.py` +
2020
`?access_control_allow_origin_header=${window.origin}` +
21+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
2122
`&token=${ancestor_key}`;
2223

2324
await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });

shared-storage/cross-origin-create-worklet-credentials-same-origin.tentative.https.sub.html

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const helper_url = crossOrigin +
1919
`/shared-storage/resources/credentials-test-helper.py` +
2020
`?access_control_allow_origin_header=${window.origin}` +
21+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
2122
`&token=${ancestor_key}`;
2223

2324
await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/utils.js"></script>
5+
<script src="/shared-storage/resources/util.js"></script>
6+
<script src="/fenced-frame/resources/utils.js"></script>
7+
8+
<body>
9+
<script>
10+
'use strict';
11+
12+
promise_test(async t => {
13+
const ancestor_key = token();
14+
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
15+
const helper_url = crossOrigin +
16+
`/shared-storage/resources/credentials-test-helper.py` +
17+
`?access_control_allow_origin_header=${window.origin}` +
18+
`&access_control_allow_credentials_header=true` +
19+
`&shared_storage_cross_origin_worklet_allowed_header=?0` +
20+
`&token=${ancestor_key}`;
21+
22+
return promise_rejects_dom(t, "OperationError",
23+
sharedStorage.createWorklet(
24+
helper_url + `&action=store-cookie`,
25+
{ credentials: "include" }));
26+
}, 'createWorklet() with cross-origin module script and credentials ' +
27+
'"include", and with the Shared-Storage-Cross-Origin-Worklet-Allowed ' +
28+
'response header value set to false (?0)');
29+
30+
</script>
31+
</body>

shared-storage/cross-origin-create-worklet-failure-missing-access-control-allow-credentials.tentative.https.sub.html

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const helper_url = crossOrigin +
1616
`/shared-storage/resources/credentials-test-helper.py` +
1717
`?access_control_allow_origin_header=${window.origin}` +
18+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
1819
`&token=${ancestor_key}`;
1920

2021
return promise_rejects_dom(t, "OperationError",

shared-storage/cross-origin-create-worklet-failure-missing-access-control-allow-origin.tentative.https.sub.html

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const helper_url = crossOrigin +
1616
`/shared-storage/resources/credentials-test-helper.py` +
1717
`&access_control_allow_credentials_header=true` +
18+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
1819
`&token=${ancestor_key}`;
1920

2021
return promise_rejects_dom(t, "OperationError",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="/common/utils.js"></script>
5+
<script src="/shared-storage/resources/util.js"></script>
6+
<script src="/fenced-frame/resources/utils.js"></script>
7+
8+
<body>
9+
<script>
10+
'use strict';
11+
12+
promise_test(async t => {
13+
const ancestor_key = token();
14+
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
15+
const helper_url = crossOrigin +
16+
`/shared-storage/resources/credentials-test-helper.py` +
17+
`?access_control_allow_origin_header=${window.origin}` +
18+
`&access_control_allow_credentials_header=true` +
19+
`&token=${ancestor_key}`;
20+
21+
return promise_rejects_dom(t, "OperationError",
22+
sharedStorage.createWorklet(
23+
helper_url + `&action=store-cookie`,
24+
{ credentials: "include" }));
25+
}, 'createWorklet() with cross-origin module script and credentials ' +
26+
'"include", and without the Shared-Storage-Cross-Origin-Worklet-Allowed ' +
27+
'response header');
28+
29+
</script>
30+
</body>

shared-storage/resources/credentials-test-helper.py

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def main(request, response):
1919
if b"access_control_allow_origin_header" in request.GET:
2020
response.headers.append(b"Access-Control-Allow-Origin", request.GET[b"access_control_allow_origin_header"])
2121

22+
if b"shared_storage_cross_origin_worklet_allowed_header" in request.GET:
23+
response.headers.append(b"Shared-Storage-Cross-Origin-Worklet-Allowed", request.GET[b"shared_storage_cross_origin_worklet_allowed_header"])
24+
2225
if action == b"store-cookie":
2326
cookie = request.headers.get(b"Cookie", b"NO_COOKIE_HEADER")
2427
request.server.stash.put(token, cookie)

0 commit comments

Comments
 (0)