Broadcast Channel inside partitioned iframe can't communicate with unpartitioned origin
Categories
(Core :: DOM: postMessage, defect)
Tracking
()
People
(Reporter: saddy802, Unassigned)
Details
Attachments
(1 file)
|
2.18 KB,
text/html
|
Details |
Steps to reproduce:
I have two sites with different origins. Let it be foo.com and bar.com. Site foo.com fires messages through BroadcastChannel with 'payment-info' name. I also have an iframe, hosted on foo.com which is built in bar.com. Here's iframe code:
<html><head><script type="text/javascript">
(function () {
const bc = new BroadcastChannel('payment-info');
bc.addEventListener('message', (m) => {
const data = JSON.parse(m.data);
data.channel = 'payment-info';
if (window.top !== window) {
window.top.postMessage(JSON.stringify(data), '*');
}
});
})();
</script></head><body></body></html>
So iframe subscribes to 'payment-info' broadcast channel and when it fires, iframe post a message to it's parent window aka bar.com with some information.
On bar.com side I just listen to 'message' event and call 'receiveMessage' function with JSON.parse
window.addEventListener('message', function (message) {
receiveMessage(message);
});
Actual results:
I combined code from several files of index.html, index2.html and iframe.html which I used to test it locally in one file. index.html and iframe.html are considered to be from one origin and index2.html is from another. Unfortunately it's impossible to test it just as plain HTML/JS without two different servers with different domains
Expected results:
It's expected to work on my site bar.com in all browsers. It doesn't work in Safari and Firefox but works in Chrome.
Comment 1•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•3 years ago
|
||
I am trying to understand the scenario.
So you have bar.com embeds foo.com and foo.com has the follow code:
<html><head><script type="text/javascript">
(function () {
const bc = new BroadcastChannel('payment-info');
bc.addEventListener('message', (m) => {
const data = JSON.parse(m.data);
data.channel = 'payment-info';
if (window.top !== window) {
window.top.postMessage(JSON.stringify(data), '*');
}
});
})();
</script></head><body></body></html>
and bar.com has:
window.addEventListener('message', function (message) {
receiveMessage(message);
});
Was it the BroadcastChannel couldn't receive the message or the message event listener in bar.com couldn't receive the message?
Yep, all correct. There's one addition that we have two opened tabs. One is bar.com with embedded iframe from foo.com and another is page under foo.com that sends some messages through BroadcastChannel. And BroadcastChannel event listener that was called inside iframe can't receive the message
Updated•3 years ago
|
Comment 4•3 years ago
|
||
So I assume we have different partitioning if you have two different tabs.
Comment 5•3 years ago
|
||
The definition tells me BroadcastChannel issues are covered in DOM:postMEssage.
Comment 6•3 years ago
|
||
Tim, are you familiar with how we partition BroadcastChannel? If not feel free to give the NI back to me.
Comment 7•3 years ago
|
||
https://searchfox.org/mozilla-central/rev/a3852ea8db25c759bc8b108aeec870d66c95452c/dom/broadcastchannel/BroadcastChannel.cpp#160-195 is probably the relevant code, but I don't know when we do partitioning between tabs and when we do not.
Comment 8•2 years ago
|
||
Sorry for the extremely late response. :(
Yes, this partitioning is done using the code that Oilli pointed out. We treat broadcast channels as a type of Storage that is partitioned by the top-level site. So, if the two tabs load distinct sites and both embed the same third-party site as iframes, the two iframes will use different broadcast channels. Now, Firefox always partitions Storage by the top-level site regardless of Storage Access.
Comment 9•2 years ago
|
||
Per comment 8, this is working as expected according to partitioning rules. Note that there have been discussions in https://github.com/privacycg/storage-access/issues/102 and its many cross-referenced issues that may be relevant.
I'm marking this invalid because this is working as intended per our bug docs at https://wiki.mozilla.org/BMO/UserGuide/BugStatuses#Resolutions
Description
•