Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 25e78f6

Browse files
committed
Bug 1870807 - Test access to storage APIs from iframes. r=dom-storage-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D198838
1 parent ffdcf2e commit 25e78f6

17 files changed

+1314
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
leak-threshold: [default:51200]
2+
prefs: [privacy.partition.always_partition_third_party_non_cookie_storage:true]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--
2+
Any copyright is dedicated to the Public Domain.
3+
http://creativecommons.org/publicdomain/zero/1.0/
4+
-->
5+
<html>
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="timeout" content="long" />
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="testHelpers.js"></script>
12+
<iframe id="write-frame-window"></iframe>
13+
<iframe id="write-frame-worker"></iframe>
14+
<iframe id="read-frame-window"></iframe>
15+
<iframe id="read-frame-worker"></iframe>
16+
<script>
17+
const messageHub = createMotherListener();
18+
19+
async function runTests() {
20+
const params = new URL(window.location.href).searchParams;
21+
const api = params.get("api");
22+
assert_true(!!api);
23+
console.log("Tested API " + api);
24+
25+
const testIdWindow = "DifferentOriginIFramesWith" + api;
26+
const testIdWorker = "Worker" + testIdWindow;
27+
28+
const writeWindows = new Map();
29+
30+
const writeFrameWindow = document.getElementById("write-frame-window");
31+
writeWindows.set(testIdWindow, writeFrameWindow.contentWindow);
32+
33+
const writeFrameWorker = document.getElementById("write-frame-worker");
34+
writeWindows.set(testIdWorker, writeFrameWorker.contentWindow);
35+
36+
const readWindows = new Map();
37+
38+
messageHub.registerReadWindow(testIdWindow);
39+
const readFrameWindow = document.getElementById("read-frame-window");
40+
readFrameWindow.src =
41+
"https://{{hosts[][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify.https.html?id=" +
42+
testIdWindow;
43+
readWindows.set(testIdWindow, readFrameWindow.contentWindow);
44+
45+
messageHub.registerReadWindow(testIdWorker);
46+
const readFrameWorker = document.getElementById("read-frame-worker");
47+
readFrameWorker.src =
48+
"https://{{hosts[][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify-worker.https.html?id=" +
49+
testIdWorker;
50+
readWindows.set(testIdWorker, readFrameWorker.contentWindow);
51+
52+
const setup = { readWindows, writeWindows };
53+
54+
await messageHub.getReadWindow(testIdWindow);
55+
async_test(t => {
56+
messageHub.registerWindow(t, testIdWindow, api, "deny", setup);
57+
58+
writeFrameWindow.src =
59+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify.https.html?id=" +
60+
testIdWindow;
61+
}, "Access not allowed for two iframes of different origin " + api);
62+
63+
await messageHub.getReadWindow(testIdWorker);
64+
async_test(t => {
65+
messageHub.registerWorker(t, testIdWorker, api, "deny", setup);
66+
67+
writeFrameWorker.src =
68+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-worker.https.html?id=" +
69+
testIdWorker;
70+
}, "Worker access not allowed for two iframes of different origin " + api);
71+
}
72+
</script>
73+
</head>
74+
<body onload="runTests();"></body>
75+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--
2+
Any copyright is dedicated to the Public Domain.
3+
http://creativecommons.org/publicdomain/zero/1.0/
4+
-->
5+
<html>
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="timeout" content="long" />
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="testHelpers.js"></script>
12+
<iframe id="write-frame-window"></iframe>
13+
<iframe id="write-frame-worker"></iframe>
14+
<iframe id="read-frame-window"></iframe>
15+
<iframe id="read-frame-worker"></iframe>
16+
<script>
17+
const messageHub = createMotherListener();
18+
19+
async function runTests() {
20+
const params = new URL(window.location.href).searchParams;
21+
const api = params.get("api");
22+
assert_true(!!api);
23+
console.log("Tested API " + api);
24+
25+
const testIdWindow = "SameOriginIFramesWith" + api;
26+
const testIdWorker = "Worker" + testIdWindow;
27+
28+
const writeWindows = new Map();
29+
30+
const writeFrameWindow = document.getElementById("write-frame-window");
31+
writeWindows.set(testIdWindow, writeFrameWindow.contentWindow);
32+
33+
const writeFrameWorker = document.getElementById("write-frame-worker");
34+
writeWindows.set(testIdWorker, writeFrameWorker.contentWindow);
35+
36+
const readWindows = new Map();
37+
38+
messageHub.registerReadWindow(testIdWindow);
39+
const readFrameWindow = document.getElementById("read-frame-window");
40+
readFrameWindow.src =
41+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify.https.html?id=" +
42+
testIdWindow;
43+
readWindows.set(testIdWindow, readFrameWindow.contentWindow);
44+
45+
messageHub.registerReadWindow(testIdWorker);
46+
const readFrameWorker = document.getElementById("read-frame-worker");
47+
readFrameWorker.src =
48+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify-worker.https.html?id=" +
49+
testIdWorker;
50+
readWindows.set(testIdWorker, readFrameWorker.contentWindow);
51+
52+
const setup = { readWindows, writeWindows };
53+
54+
await messageHub.getReadWindow(testIdWindow);
55+
async_test(t => {
56+
messageHub.registerWindow(t, testIdWindow, api, "allow", setup);
57+
58+
writeFrameWindow.src =
59+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify.https.html?id=" +
60+
testIdWindow;
61+
}, "Access allowed for two iframes with the same origin " + api);
62+
63+
await messageHub.getReadWindow(testIdWorker);
64+
async_test(t => {
65+
messageHub.registerWorker(t, testIdWorker, api, "allow", setup);
66+
67+
writeFrameWorker.src =
68+
"https://{{hosts[alt][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify.https.html?id=" +
69+
testIdWorker;
70+
}, "Worker access allowed from two iframes with the same origin " + api);
71+
}
72+
</script>
73+
</head>
74+
<body onload="runTests();"></body>
75+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!--
2+
Any copyright is dedicated to the Public Domain.
3+
http://creativecommons.org/publicdomain/zero/1.0/
4+
-->
5+
<html>
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="timeout" content="long" />
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="testHelpers.js"></script>
12+
<script>
13+
const messageHub = createMotherListener();
14+
15+
async function runTests() {
16+
const params = new URL(window.location.href).searchParams;
17+
const api = params.get("api");
18+
assert_true(!!api);
19+
console.log("Tested API " + api);
20+
21+
const testIdWindow = "DifferentOriginWindowsWith" + api;
22+
const testIdWorker = "Worker" + testIdWindow;
23+
24+
const writeWindows = new Map();
25+
26+
const readWindowURL =
27+
"https://{{hosts[alt][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify-wrapper.https.sub.html";
28+
29+
const readWindows = new Map();
30+
31+
messageHub.registerReadWindow(testIdWindow);
32+
readWindows.set(
33+
testIdWindow,
34+
window.open(readWindowURL + "?id=" + testIdWindow)
35+
);
36+
37+
messageHub.registerReadWindow(testIdWorker);
38+
readWindows.set(
39+
testIdWorker,
40+
window.open(readWindowURL + "?id=" + testIdWorker)
41+
);
42+
43+
const setup = { readWindows, writeWindows };
44+
45+
await messageHub.getReadWindow(testIdWindow);
46+
async_test(t => {
47+
messageHub.registerWindow(t, testIdWindow, api, "deny", setup);
48+
49+
writeWindows.set(
50+
testIdWindow,
51+
window.open(
52+
"https://{{hosts[][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
53+
testIdWindow
54+
)
55+
);
56+
}, "Access not allowed for two iframes with the same origin on windows with different origins " + api);
57+
58+
await messageHub.getReadWindow(testIdWorker);
59+
async_test(t => {
60+
messageHub.registerWorker(t, testIdWorker, api, "deny", setup);
61+
62+
writeWindows.set(
63+
testIdWorker,
64+
window.open(
65+
"https://{{hosts[][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
66+
testIdWorker
67+
)
68+
);
69+
}, "Reading from worker not allowed for two iframes with the same origin on windows with different origins " + api);
70+
}
71+
</script>
72+
</head>
73+
<body onload="runTests();"></body>
74+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!--
2+
Any copyright is dedicated to the Public Domain.
3+
http://creativecommons.org/publicdomain/zero/1.0/
4+
-->
5+
<html>
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="timeout" content="long" />
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="testHelpers.js"></script>
12+
<script>
13+
const messageHub = createMotherListener();
14+
15+
async function runTests() {
16+
const params = new URL(window.location.href).searchParams;
17+
const api = params.get("api");
18+
assert_true(!!api);
19+
console.log("Tested API " + api);
20+
21+
const testIdWindow = "SameOriginWindowsWith" + api;
22+
const testIdWorker = "WorkerSameOriginWindowsWith" + api;
23+
24+
const writeWindows = new Map();
25+
26+
const readWindowURL =
27+
"https://{{hosts[][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify-wrapper.https.sub.html";
28+
29+
const readWindows = new Map();
30+
31+
messageHub.registerReadWindow(testIdWindow);
32+
readWindows.set(
33+
testIdWindow,
34+
window.open(readWindowURL + "?id=" + testIdWindow)
35+
);
36+
37+
messageHub.registerReadWindow(testIdWorker);
38+
readWindows.set(
39+
testIdWorker,
40+
window.open(readWindowURL + "?id=" + testIdWorker)
41+
);
42+
43+
const setup = { readWindows, writeWindows };
44+
45+
await messageHub.getReadWindow(testIdWindow);
46+
async_test(t => {
47+
messageHub.registerWindow(t, testIdWindow, api, "allow", setup);
48+
49+
writeWindows.set(
50+
testIdWindow,
51+
window.open(
52+
"https://{{hosts[][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
53+
testIdWindow
54+
)
55+
);
56+
}, "Access allowed for two iframes with the same origin " + api);
57+
58+
await messageHub.getReadWindow(testIdWorker);
59+
async_test(t => {
60+
messageHub.registerWorker(t, testIdWorker, api, "allow", setup);
61+
62+
writeWindows.set(
63+
testIdWorker,
64+
window.open(
65+
"https://{{hosts[][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
66+
testIdWorker
67+
)
68+
);
69+
}, "Worker access allowed for two iframes with the same origin " + api);
70+
}
71+
</script>
72+
</head>
73+
<body onload="runTests();"></body>
74+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--
2+
Any copyright is dedicated to the Public Domain.
3+
http://creativecommons.org/publicdomain/zero/1.0/
4+
-->
5+
<html>
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="timeout" content="long" />
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="testHelpers.js"></script>
12+
<iframe id="read-frame-window"></iframe>
13+
<iframe id="read-frame-worker"></iframe>
14+
<script>
15+
const messageHub = createMotherListener();
16+
17+
async function runTests() {
18+
const params = new URL(window.location.href).searchParams;
19+
const api = params.get("api");
20+
assert_true(!!api);
21+
console.log("Tested API " + api);
22+
23+
const testIdWindow = "ReadIFrameWriteDifferentOriginWindowWith" + api;
24+
const testIdWorker = "Worker" + testIdWindow;
25+
26+
const writeWindows = new Map();
27+
28+
const readWindows = new Map();
29+
30+
messageHub.registerReadWindow(testIdWindow);
31+
const readFrameWindow = document.getElementById("read-frame-window");
32+
readFrameWindow.src =
33+
"https://{{hosts[][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify.https.html?id=" +
34+
testIdWindow;
35+
readWindows.set(testIdWindow, readFrameWindow.contentWindow);
36+
37+
messageHub.registerReadWindow(testIdWorker);
38+
const readFrameWorker = document.getElementById("read-frame-worker");
39+
readFrameWorker.src =
40+
"https://{{hosts[][www2]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-read-and-notify.https.html?id=" +
41+
testIdWorker;
42+
readWindows.set(testIdWorker, readFrameWorker.contentWindow);
43+
44+
const setup = { readWindows, writeWindows };
45+
46+
await messageHub.getReadWindow(testIdWindow);
47+
async_test(t => {
48+
messageHub.registerWindow(t, testIdWindow, api, "deny", setup);
49+
50+
writeWindows.set(
51+
testIdWindow,
52+
window.open(
53+
"https://{{hosts[alt][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
54+
testIdWindow
55+
)
56+
);
57+
}, "Read for iframe not allowed when write was done by an iframe in a window of different origin " + api);
58+
59+
await messageHub.getReadWindow(testIdWorker);
60+
async_test(t => {
61+
messageHub.registerWorker(t, testIdWorker, api, "deny", setup);
62+
63+
writeWindows.set(
64+
testIdWorker,
65+
window.open(
66+
"https://{{hosts[alt][www1]}}:{{ports[https][0]}}/_mozilla/dom/quota/support/test-write-and-notify-wrapper.https.sub.html?id=" +
67+
testIdWorker
68+
)
69+
);
70+
}, "Read by worker in iframe not allowed when write was done by an iframe in a window of different origin " + api);
71+
}
72+
</script>
73+
</head>
74+
<body onload="runTests();"></body>
75+
</html>

0 commit comments

Comments
 (0)