Skip to content

Commit

Permalink
[shared storage] Implement the Shared-Storage-Cross-Origin-Worklet-Al…
Browse files Browse the repository at this point in the history
…lowed response header check

When creating a cross-origin worklet, require the
"Shared-Storage-Cross-Origin-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
  • Loading branch information
yaoxiachromium authored and chromium-wpt-export-bot committed Apr 4, 2024
1 parent 2b71570 commit 30993ca
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&access_control_allow_credentials_header=true` +
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
`&token=${ancestor_key}`;

await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
`&token=${ancestor_key}`;

await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
`&token=${ancestor_key}`;

await fetch(set_cookie_url, { mode: 'no-cors', credentials: 'include' });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!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}` +
`&access_control_allow_credentials_header=true` +
`&shared_storage_cross_origin_worklet_allowed_header=?0` +
`&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 with the Shared-Storage-Cross-Origin-Worklet-Allowed ' +
'response header value set to false (?0)');

</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`?access_control_allow_origin_header=${window.origin}` +
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
`&token=${ancestor_key}`;

return promise_rejects_dom(t, "OperationError",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const helper_url = crossOrigin +
`/shared-storage/resources/credentials-test-helper.py` +
`&access_control_allow_credentials_header=true` +
`&shared_storage_cross_origin_worklet_allowed_header=?1` +
`&token=${ancestor_key}`;

return promise_rejects_dom(t, "OperationError",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!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}` +
`&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 Shared-Storage-Cross-Origin-Worklet-Allowed ' +
'response header');

</script>
</body>
3 changes: 3 additions & 0 deletions shared-storage/resources/credentials-test-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def main(request, response):
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 b"shared_storage_cross_origin_worklet_allowed_header" in request.GET:
response.headers.append(b"Shared-Storage-Cross-Origin-Worklet-Allowed", request.GET[b"shared_storage_cross_origin_worklet_allowed_header"])

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

0 comments on commit 30993ca

Please sign in to comment.