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: Allow x-origin module script in addModule #47290

Merged
merged 1 commit into from
Jul 25, 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,40 @@
<!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 sameOrigin = location.origin;
const crossOrigin = 'https://{{domains[www]}}:{{ports[https][0]}}';
const crossOriginScript = crossOrigin
+ "/shared-storage/resources/simple-module2.js";
await sharedStorage.worklet.addModule(crossOriginScript);

const ancestor_key = token();
let url0 = generateURL("/shared-storage/resources/frame0.html",
[ancestor_key]);
let select_url_result = await sharedStorage.selectURL(
"test-url-selection-operation", [{url: url0}],
{data: {'mockResult': 0, 'setKey': 'a', 'setValue': 'b'},
resolveToConfig: true});
assert_true(validateSelectURLResult(select_url_result, true));
attachFencedFrame(select_url_result, 'opaque-ads');
const result = await nextValueFromServer(ancestor_key);
assert_equals(result, "frame0_loaded");

// The invoking context's origin is used as the data origin.
await verifyKeyValueForOrigin('a', 'b', sameOrigin);
await verifyKeyNotFoundForOrigin('a', crossOrigin);

// Clean up.
return sharedStorage.delete('a');
}, 'addModule with cross-origin url');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
'use strict';

promise_test(async t => {
// Loading the worklet script uses CORS, which doesn't support the data
// scheme.
return promise_rejects_dom(t, "OperationError",
sharedStorage.worklet.addModule(
`data:application/javascript;alert("Hi!")`));
}, 'addModule() with data URL module script');

promise_test(async t => {
// Opaque data origins are not permitted.
return promise_rejects_dom(t, "InvalidAccessError",
sharedStorage.createWorklet(
`data:application/javascript;alert("Hi!")`));
}, 'createWorklet() with data URL module script and default data origin');

</script>
</body>
5 changes: 0 additions & 5 deletions shared-storage/add-module.tentative.https.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 20 additions & 0 deletions shared-storage/resources/simple-module2.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions shared-storage/resources/simple-module2.js.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Access-Control-Allow-Origin: *