Skip to content

Commit 5b96f58

Browse files
Shared Storage: Align createWorklet's default data origin w/addModule's
We align the default data origin for createWorklet with that of addModule to be the invoking context's origin. We also hook up the dataOrigin option in createWorklet's options dictionary, so that the script origin can be manually specified to be used as the data origin instead. See WICG/shared-storage#158, WICG/shared-storage#161, and https://groups.google.com/a/chromium.org/g/blink-dev/c/YZ4XGewKVuk. Bug:353738488 Change-Id: I3578e48f14c9fb1005211b94889ce01ef209162c
1 parent c1ba090 commit 5b96f58

File tree

25 files changed

+408
-123
lines changed

25 files changed

+408
-123
lines changed

private-aggregation/private-aggregation-permissions-policy-default.https.sub.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
await CreateWorkletAndVerifyContributeToHistogram(
3535
/*shared_storage_origin=*/cross_origin, paa_data);
3636
}, 'In a page with default "private-aggregation" permissions policy, ' +
37-
'createWorklet() with cross-origin script, and then execute ' +
38-
'contributeToHistogram() inside the worklet');
37+
'createWorklet() with cross-origin script and script data origin, and then '
38+
+ 'execute contributeToHistogram() inside the worklet');
3939

4040
</script>
4141
</body>

private-aggregation/private-aggregation-permissions-policy-none.https.sub.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
await CreateWorkletAndVerifyContributeToHistogram(
3535
/*shared_storage_origin=*/cross_origin, paa_data, /*expected_error=*/true);
3636
}, 'In a page with "private-aggregation=()" permissions policy, ' +
37-
'createWorklet() with cross-origin script, and then execute ' +
38-
'contributeToHistogram() inside the worklet');
37+
'createWorklet() with cross-origin script and script data origin, and then '
38+
+ 'execute contributeToHistogram() inside the worklet');
3939

4040
</script>
4141
</body>

private-aggregation/private-aggregation-permissions-policy-self.https.sub.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
await CreateWorkletAndVerifyContributeToHistogram(
3535
/*shared_storage_origin=*/cross_origin, paa_data, /*expected_error=*/true);
3636
}, 'In a page with "private-aggregation=(self)" permissions policy, ' +
37-
'createWorklet() with cross-origin script, and then execute ' +
38-
'contributeToHistogram() inside the worklet');
37+
'createWorklet() with cross-origin script and script data origin, and then '
38+
+ 'execute contributeToHistogram() inside the worklet');
3939

4040
</script>
4141
</body>

private-aggregation/resources/util.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ async function CreateWorkletAndVerifyContributeToHistogram(shared_storage_origin
3535
let url1 = generateURL("/shared-storage/resources/frame1.html",
3636
[ancestor_key]);
3737

38-
let worklet = await sharedStorage.createWorklet(shared_storage_origin +
39-
"/private-aggregation/resources/shared-storage-helper-module.js");
38+
let worklet = await sharedStorage.createWorklet(
39+
shared_storage_origin +
40+
'/private-aggregation/resources/shared-storage-helper-module.js',
41+
{dataOrigin: 'script-origin'});
4042

4143
let select_url_result = await worklet.selectURL(
4244
"contribute-to-histogram", [{url: url0}, {url: url1}],

shared-storage/add-module-or-create-worklet-with-data-url.tentative.https.sub.html

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,28 @@
1515
}, 'addModule() with data URL module script');
1616

1717
promise_test(async t => {
18-
// Opaque data origins are not permitted.
19-
return promise_rejects_dom(t, "InvalidAccessError",
18+
// Loading the worklet script uses CORS, which doesn't support the data
19+
// scheme.
20+
return promise_rejects_dom(t, "OperationError",
2021
sharedStorage.createWorklet(
2122
`data:application/javascript;alert("Hi!")`));
2223
}, 'createWorklet() with data URL module script and default data origin');
2324

25+
promise_test(async t => {
26+
// Loading the worklet script uses CORS, which doesn't support the data
27+
// scheme.
28+
return promise_rejects_dom(t, "OperationError",
29+
sharedStorage.createWorklet(
30+
`data:application/javascript;alert("Hi!")`,
31+
{ dataOrigin: "context-origin" }));
32+
}, 'createWorklet() with data URL module script and dataOrigin "context-origin"');
33+
34+
promise_test(async t => {
35+
// Opaque data origins are not permitted.
36+
return promise_rejects_dom(t, "InvalidAccessError",
37+
sharedStorage.createWorklet(
38+
`data:application/javascript;alert("Hi!")`,
39+
{ dataOrigin: "script-origin" }));
40+
}, 'createWorklet() with data URL module script and dataOrigin "script-origin"');
2441
</script>
2542
</body>

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

+39-8
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,63 @@
99
<script>
1010
'use strict';
1111

12-
promise_test(async () => {
12+
async function verifyStoreCookieCrossOriginCreateWorkletIncludeCredentials(
13+
helper_url_params, data_origin_option) {
1314
const ancestor_key = token();
1415
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
1516
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
1617
`?name=key0` +
1718
`&path=/shared-storage/`;
1819
const helper_url = crossOrigin +
1920
`/shared-storage/resources/credentials-test-helper.py` +
20-
`?access_control_allow_origin_header=${window.origin}` +
21-
`&access_control_allow_credentials_header=true` +
22-
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
23-
`&token=${ancestor_key}`;
21+
helper_url_params + `&token=${ancestor_key}`;
2422

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

25+
const options = (data_origin_option === '') ? { credentials: "include" }
26+
: { credentials: "include", dataOrigin: data_origin_option };
27+
2728
const worklet = await sharedStorage.createWorklet(
28-
helper_url + `&action=store-cookie`,
29-
{ credentials: "include" });
29+
helper_url + `&action=store-cookie`, options);
3030

3131
const request_cookie_fetch_response =
3232
await fetch(helper_url + `&action=get-cookie`);
3333

3434
const request_cookie_text = await request_cookie_fetch_response.text();
3535

3636
assert_equals(request_cookie_text, "key0=1");
37-
}, 'createWorklet() with cross-origin module script and credentials "include"');
37+
}
38+
39+
promise_test(async () => {
40+
const helper_url_params =
41+
`?access_control_allow_origin_header=${window.origin}` +
42+
`&access_control_allow_credentials_header=true`;
43+
44+
await verifyStoreCookieCrossOriginCreateWorkletIncludeCredentials(
45+
helper_url_params, /*data_origin_option=*/'');
46+
}, 'createWorklet() with cross-origin module script, credentials "include",'
47+
+ 'and default data origin (context origin).');
48+
49+
promise_test(async () => {
50+
const helper_url_params =
51+
`?access_control_allow_origin_header=${window.origin}` +
52+
`&access_control_allow_credentials_header=true`;
53+
54+
await verifyStoreCookieCrossOriginCreateWorkletIncludeCredentials(
55+
helper_url_params, /*data_origin_option=*/'context-origin');
56+
}, 'createWorklet() with cross-origin module script, credentials "include",'
57+
+ 'and "context-origin" as dataOrigin.');
58+
59+
promise_test(async () => {
60+
const helper_url_params =
61+
`?access_control_allow_origin_header=${window.origin}` +
62+
`&access_control_allow_credentials_header=true` +
63+
`&shared_storage_cross_origin_worklet_allowed_header=?1`;
64+
65+
await verifyStoreCookieCrossOriginCreateWorkletIncludeCredentials(
66+
helper_url_params, /*data_origin_option=*/'script-origin');
67+
}, 'createWorklet() with cross-origin module script, credentials "include",'
68+
+ 'and "script-origin" as dataOrigin.');
3869

3970
</script>
4071
</body>

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

+39-7
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,63 @@
99
<script>
1010
'use strict';
1111

12-
promise_test(async () => {
12+
async function verifyStoreCookieCrossOriginCreateWorkletOmitCredentials(
13+
helper_url_params, data_origin_option) {
1314
const ancestor_key = token();
1415
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
1516
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
1617
`?name=key0` +
1718
`&path=/shared-storage/`;
1819
const helper_url = crossOrigin +
1920
`/shared-storage/resources/credentials-test-helper.py` +
20-
`?access_control_allow_origin_header=${window.origin}` +
21-
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
22-
`&token=${ancestor_key}`;
21+
helper_url_params + `&token=${ancestor_key}`;
2322

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

25+
const options = (data_origin_option === '') ? { credentials: "omit" }
26+
: { credentials: "omit", dataOrigin: data_origin_option };
27+
2628
const worklet = await sharedStorage.createWorklet(
27-
helper_url + `&action=store-cookie`,
28-
{ credentials: "omit" });
29+
helper_url + `&action=store-cookie`, options);
2930

3031
const request_cookie_fetch_response =
3132
await fetch(helper_url + `&action=get-cookie`);
3233

3334
const request_cookie_text = await request_cookie_fetch_response.text();
3435

3536
assert_equals(request_cookie_text, "NO_COOKIE_HEADER");
36-
}, 'createWorklet() with cross-origin module script and credentials "omit"');
37+
}
38+
39+
promise_test(async () => {
40+
const helper_url_params =
41+
`?access_control_allow_origin_header=${window.origin}` +
42+
`&access_control_allow_credentials_header=true`;
43+
44+
await verifyStoreCookieCrossOriginCreateWorkletOmitCredentials(
45+
helper_url_params, /*data_origin_option=*/'');
46+
}, 'createWorklet() with cross-origin module script, credentials "omit",'
47+
+ 'and default data origin (context origin).');
48+
49+
promise_test(async () => {
50+
const helper_url_params =
51+
`?access_control_allow_origin_header=${window.origin}` +
52+
`&access_control_allow_credentials_header=true`;
53+
54+
await verifyStoreCookieCrossOriginCreateWorkletOmitCredentials(
55+
helper_url_params, /*data_origin_option=*/'context-origin');
56+
}, 'createWorklet() with cross-origin module script, credentials "omit",'
57+
+ 'and "context-origin" as dataOrigin.');
58+
59+
promise_test(async () => {
60+
const helper_url_params =
61+
`?access_control_allow_origin_header=${window.origin}` +
62+
`&access_control_allow_credentials_header=true` +
63+
`&shared_storage_cross_origin_worklet_allowed_header=?1`;
64+
65+
await verifyStoreCookieCrossOriginCreateWorkletOmitCredentials(
66+
helper_url_params, /*data_origin_option=*/'script-origin');
67+
}, 'createWorklet() with cross-origin module script, credentials "omit",'
68+
+ 'and "script-origin" as dataOrigin.');
3769

3870
</script>
3971
</body>

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

+39-7
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,63 @@
99
<script>
1010
'use strict';
1111

12-
promise_test(async () => {
12+
async function verifyStoreCookieCrossOriginCreateWorkletSameOriginCredentials(
13+
helper_url_params, data_origin_option) {
1314
const ancestor_key = token();
1415
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
1516
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
1617
`?name=key0` +
1718
`&path=/shared-storage/`;
1819
const helper_url = crossOrigin +
1920
`/shared-storage/resources/credentials-test-helper.py` +
20-
`?access_control_allow_origin_header=${window.origin}` +
21-
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
22-
`&token=${ancestor_key}`;
21+
helper_url_params + `&token=${ancestor_key}`;
2322

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

25+
const options = (data_origin_option === '') ? { credentials: "same-origin" }
26+
: { credentials: "same-origin", dataOrigin: data_origin_option };
27+
2628
const worklet = await sharedStorage.createWorklet(
27-
helper_url + `&action=store-cookie`,
28-
{ credentials: "same-origin" });
29+
helper_url + `&action=store-cookie`, options);
2930

3031
const request_cookie_fetch_response =
3132
await fetch(helper_url + `&action=get-cookie`);
3233

3334
const request_cookie_text = await request_cookie_fetch_response.text();
3435

3536
assert_equals(request_cookie_text, "NO_COOKIE_HEADER");
36-
}, 'createWorklet() with cross-origin module script and credentials "same-origin"');
37+
}
38+
39+
promise_test(async () => {
40+
const helper_url_params =
41+
`?access_control_allow_origin_header=${window.origin}` +
42+
`&access_control_allow_credentials_header=true`;
43+
44+
await verifyStoreCookieCrossOriginCreateWorkletSameOriginCredentials(
45+
helper_url_params, /*data_origin_option=*/'');
46+
}, 'createWorklet() with cross-origin module script, credentials "same-origin",'
47+
+ 'and default data origin (context origin).');
48+
49+
promise_test(async () => {
50+
const helper_url_params =
51+
`?access_control_allow_origin_header=${window.origin}` +
52+
`&access_control_allow_credentials_header=true`;
53+
54+
await verifyStoreCookieCrossOriginCreateWorkletSameOriginCredentials(
55+
helper_url_params, /*data_origin_option=*/'context-origin');
56+
}, 'createWorklet() with cross-origin module script, credentials "same-origin",'
57+
+ 'and "context-origin" as dataOrigin.');
58+
59+
promise_test(async () => {
60+
const helper_url_params =
61+
`?access_control_allow_origin_header=${window.origin}` +
62+
`&access_control_allow_credentials_header=true` +
63+
`&shared_storage_cross_origin_worklet_allowed_header=?1`;
64+
65+
await verifyStoreCookieCrossOriginCreateWorkletSameOriginCredentials(
66+
helper_url_params, /*data_origin_option=*/'script-origin');
67+
}, 'createWorklet() with cross-origin module script, credentials "same-origin",'
68+
+ 'and "script-origin" as dataOrigin.');
3769

3870
</script>
3971
</body>

shared-storage/cross-origin-create-worklet-failure-false-shared-storage-cross-origin-worklet-allowed.tentative.https.sub.html

-31
This file was deleted.

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

+36-5
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,53 @@
99
<script>
1010
'use strict';
1111

12+
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
13+
1214
promise_test(async t => {
1315
const ancestor_key = token();
14-
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
1516
const helper_url = crossOrigin +
1617
`/shared-storage/resources/credentials-test-helper.py` +
1718
`?access_control_allow_origin_header=${window.origin}` +
18-
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
1919
`&token=${ancestor_key}`;
2020

2121
return promise_rejects_dom(t, "OperationError",
2222
sharedStorage.createWorklet(
2323
helper_url + `&action=store-cookie`,
2424
{ credentials: "include" }));
25-
}, 'createWorklet() with cross-origin module script and credentials ' +
26-
'"include", and without the Access-Control-Allow-Credentials response ' +
27-
'header');
25+
}, 'createWorklet() with cross-origin module script, credentials ' +
26+
'"include", default data origin (context origin), and without the ' +
27+
'Access-Control-Allow-Credentials response header');
28+
29+
promise_test(async t => {
30+
const ancestor_key = token();
31+
const helper_url = crossOrigin +
32+
`/shared-storage/resources/credentials-test-helper.py` +
33+
`?access_control_allow_origin_header=${window.origin}` +
34+
`&token=${ancestor_key}`;
35+
36+
return promise_rejects_dom(t, "OperationError",
37+
sharedStorage.createWorklet(
38+
helper_url + `&action=store-cookie`,
39+
{ credentials: "include", dataOrigin: "context-origin" }));
40+
}, 'createWorklet() with cross-origin module script, credentials ' +
41+
'"include", "context-origin" as dataOrigin, and without the ' +
42+
'Access-Control-Allow-Credentials response header');
43+
44+
promise_test(async t => {
45+
const ancestor_key = token();
46+
const helper_url = crossOrigin +
47+
`/shared-storage/resources/credentials-test-helper.py` +
48+
`?access_control_allow_origin_header=${window.origin}` +
49+
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
50+
`&token=${ancestor_key}`;
51+
52+
return promise_rejects_dom(t, "OperationError",
53+
sharedStorage.createWorklet(
54+
helper_url + `&action=store-cookie`,
55+
{ credentials: "include", dataOrigin: "script-origin" }));
56+
}, 'createWorklet() with cross-origin module script, credentials ' +
57+
'"include", "script-origin" as dataOrigin, and without the ' +
58+
'Access-Control-Allow-Credentials response header');
2859

2960
</script>
3061
</body>

0 commit comments

Comments
 (0)