Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shared storage] Support cross-origin worklet #44596

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/shared-storage/resources/util.js"></script>
<script src="/fenced-frame/resources/utils.js"></script>

<body>
<script>
'use strict';

promise_test(async () => {
const ancestor_key = token();
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
`?name=key0` +
`&path=/shared-storage/`;
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&access_control_allow_credentials_header=true` +
`&token=${ancestor_key}`;

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

const worklet = await sharedStorage.createWorklet(
helper_url + `&action=store-cookie`,
{ credentials: "include" });

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

const request_cookie_text = await request_cookie_fetch_response.text();

assert_equals(request_cookie_text, "key0=1");
}, 'createWorklet() with cross-origin module script and credentials "include"');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/shared-storage/resources/util.js"></script>
<script src="/fenced-frame/resources/utils.js"></script>

<body>
<script>
'use strict';

promise_test(async () => {
const ancestor_key = token();
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
`?name=key0` +
`&path=/shared-storage/`;
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&token=${ancestor_key}`;

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

const worklet = await sharedStorage.createWorklet(
helper_url + `&action=store-cookie`,
{ credentials: "omit" });

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

const request_cookie_text = await request_cookie_fetch_response.text();

assert_equals(request_cookie_text, "NO_COOKIE_HEADER");
}, 'createWorklet() with cross-origin module script and credentials "omit"');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/shared-storage/resources/util.js"></script>
<script src="/fenced-frame/resources/utils.js"></script>

<body>
<script>
'use strict';

promise_test(async () => {
const ancestor_key = token();
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const set_cookie_url = crossOrigin + `/cookies/resources/set-cookie.py` +
`?name=key0` +
`&path=/shared-storage/`;
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&token=${ancestor_key}`;

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

const worklet = await sharedStorage.createWorklet(
helper_url + `&action=store-cookie`,
{ credentials: "same-origin" });

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

const request_cookie_text = await request_cookie_fetch_response.text();

assert_equals(request_cookie_text, "NO_COOKIE_HEADER");
}, 'createWorklet() with cross-origin module script and credentials "same-origin"');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/shared-storage/resources/util.js"></script>
<script src="/fenced-frame/resources/utils.js"></script>

<body>
<script>
'use strict';

promise_test(async t => {
const ancestor_key = token();
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&token=${ancestor_key}`;

return promise_rejects_dom(t, "OperationError",
sharedStorage.createWorklet(
helper_url + `&action=store-cookie`,
{ credentials: "include" }));
}, 'createWorklet() with cross-origin module script and credentials ' +
'"include", and without the Access-Control-Allow-Credentials response ' +
'header');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/shared-storage/resources/util.js"></script>
<script src="/fenced-frame/resources/utils.js"></script>

<body>
<script>
'use strict';

promise_test(async t => {
const ancestor_key = token();
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`&access_control_allow_credentials_header=true` +
`&token=${ancestor_key}`;

return promise_rejects_dom(t, "OperationError",
sharedStorage.createWorklet(
helper_url + `&action=store-cookie`,
{ credentials: "include" }));
}, 'createWorklet() with cross-origin module script and credentials ' +
'"include", and without the Access-Control-Allow-Origin response header');

</script>
</body>
6 changes: 6 additions & 0 deletions shared-storage/resources/credentials-test-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def main(request, response):
response.status = 200
response.headers.append(b"Content-Type", b"text/javascript")

if b"access_control_allow_credentials_header" in request.GET:
response.headers.append(b"Access-Control-Allow-Credentials", request.GET[b"access_control_allow_credentials_header"])

if b"access_control_allow_origin_header" in request.GET:
response.headers.append(b"Access-Control-Allow-Origin", request.GET[b"access_control_allow_origin_header"])

if action == b"store-cookie":
cookie = request.headers.get(b"Cookie", b"NO_COOKIE_HEADER")
request.server.stash.put(token, cookie)
Expand Down