From 3b9341c5f054ed4d948ec29c514a6098c9a018b3 Mon Sep 17 00:00:00 2001 From: Camillia Smith Barnes Date: Fri, 26 Jul 2024 15:46:17 +0000 Subject: [PATCH] Bug 1909902 [wpt PR 47290] - Shared Storage: Allow x-origin module script in addModule, a=testonly Automatic update from web-platform-tests Shared Storage: Allow x-origin module script in addModule The same-origin restriction for module script loaded by `sharedStorage.worklet.addModule()` is no longer needed, so we remove it. See https://github.com/WICG/shared-storage/pull/158 and https://groups.google.com/a/chromium.org/g/blink-dev/c/YZ4XGewKVuk. Only cross-origin scripts loaded with createWorklet() that use the script origin as their data origin will need the "Shared-Storage-Cross-Origin-Worklet-Allowed: ?1" response header, however. To differentiate between worklets that need to be checked for this header and ones that don't, we add a new "Sec-Shared-Storage-Data-Origin" request header with the data origin used to the requests where the data origin is cross-origin to the context origin. We then use this information to determine if the "Shared-Storage-Cross-Origin-Worklet-Allowed" response header is needed. Bug: 348660660 Change-Id: I55f7f5d6d282b679505be5f23901f26ff7d7d374 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5648386 Commit-Queue: Cammie Smith Barnes Reviewed-by: Andrey Kosyakov Reviewed-by: Brendon Tiszka Reviewed-by: Tsuyoshi Horo Reviewed-by: Yao Xiao Cr-Commit-Position: refs/heads/main@{#1332965} -- wpt-commits: c1ba090fe97109f63812fe90a4b612d602f6a87f wpt-pr: 47290 --- ...oss-origin-script.tentative.https.sub.html | 40 +++++++++++++++++++ ...let-with-data-url.tentative.https.sub.html | 25 ++++++++++++ .../add-module.tentative.https.sub.html | 5 --- .../resources/simple-module2.js | 20 ++++++++++ .../resources/simple-module2.js.headers | 1 + 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 testing/web-platform/tests/shared-storage/add-module-cross-origin-script.tentative.https.sub.html create mode 100644 testing/web-platform/tests/shared-storage/add-module-or-create-worklet-with-data-url.tentative.https.sub.html create mode 100644 testing/web-platform/tests/shared-storage/resources/simple-module2.js create mode 100644 testing/web-platform/tests/shared-storage/resources/simple-module2.js.headers diff --git a/testing/web-platform/tests/shared-storage/add-module-cross-origin-script.tentative.https.sub.html b/testing/web-platform/tests/shared-storage/add-module-cross-origin-script.tentative.https.sub.html new file mode 100644 index 0000000000000..6ac73bdeddca7 --- /dev/null +++ b/testing/web-platform/tests/shared-storage/add-module-cross-origin-script.tentative.https.sub.html @@ -0,0 +1,40 @@ + + + + + + + + + + diff --git a/testing/web-platform/tests/shared-storage/add-module-or-create-worklet-with-data-url.tentative.https.sub.html b/testing/web-platform/tests/shared-storage/add-module-or-create-worklet-with-data-url.tentative.https.sub.html new file mode 100644 index 0000000000000..8bc785efcb6c2 --- /dev/null +++ b/testing/web-platform/tests/shared-storage/add-module-or-create-worklet-with-data-url.tentative.https.sub.html @@ -0,0 +1,25 @@ + + + + + + + diff --git a/testing/web-platform/tests/shared-storage/add-module.tentative.https.sub.html b/testing/web-platform/tests/shared-storage/add-module.tentative.https.sub.html index 7859e750c96d7..33ff70d1145e3 100644 --- a/testing/web-platform/tests/shared-storage/add-module.tentative.https.sub.html +++ b/testing/web-platform/tests/shared-storage/add-module.tentative.https.sub.html @@ -11,11 +11,6 @@ sharedStorage.worklet.addModule("https://")); }, 'addModule with invalid url'); -promise_test(async t => { - return promise_rejects_dom(t, "DataError", - sharedStorage.worklet.addModule("https://foo.com")); -}, 'addModule with cross-origin url'); - promise_test(() => { return sharedStorage.worklet.addModule( "/shared-storage/resources/simple-module.js"); diff --git a/testing/web-platform/tests/shared-storage/resources/simple-module2.js b/testing/web-platform/tests/shared-storage/resources/simple-module2.js new file mode 100644 index 0000000000000..dd5f31f36e838 --- /dev/null +++ b/testing/web-platform/tests/shared-storage/resources/simple-module2.js @@ -0,0 +1,20 @@ +// Copyright 2024 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +class TestURLSelectionOperation { + async run(urls, data) { + if (data && data.hasOwnProperty('setKey') && + data.hasOwnProperty('setValue')) { + await sharedStorage.set(data['setKey'], data['setValue']); + } + + if (data && data.hasOwnProperty('mockResult')) { + return data['mockResult']; + } + + return -1; + } +} + +register('test-url-selection-operation', TestURLSelectionOperation); diff --git a/testing/web-platform/tests/shared-storage/resources/simple-module2.js.headers b/testing/web-platform/tests/shared-storage/resources/simple-module2.js.headers new file mode 100644 index 0000000000000..cb762eff80684 --- /dev/null +++ b/testing/web-platform/tests/shared-storage/resources/simple-module2.js.headers @@ -0,0 +1 @@ +Access-Control-Allow-Origin: *