Closed Bug 1841100 Opened 3 years ago Closed 2 years ago

Broadcast Channel inside partitioned iframe can't communicate with unpartitioned origin

Categories

(Core :: DOM: postMessage, defect)

Firefox 110
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: saddy802, Unassigned)

Details

Attachments

(1 file)

Attached file index2.html

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.

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.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

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?

Flags: needinfo?(saddy802)

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

Flags: needinfo?(saddy802)
Severity: -- → S2

So I assume we have different partitioning if you have two different tabs.

Flags: needinfo?(pbz)

The definition tells me BroadcastChannel issues are covered in DOM:postMEssage.

Severity: S2 → --
Component: DOM: Core & HTML → DOM: postMessage

Tim, are you familiar with how we partition BroadcastChannel? If not feel free to give the NI back to me.

Flags: needinfo?(pbz) → needinfo?(tihuang)

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.

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.

Flags: needinfo?(tihuang)

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

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID
Summary: Broadcast Channel inside iframe doesn't work → Broadcast Channel inside partitioned iframe can't communicate with unpartitioned origin
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: