Bug 313692
| Summary: | [Site Isolation] postMessage of SharedArrayBuffer doesn't work in the same process | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Anthony Tarbinian <a.tarbinian> |
| Component: | New Bugs | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P1 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Anthony Tarbinian
The following tests are failing with site isolation enabled:
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.html
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.serviceworker.html
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.sharedworker.html
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.worker.html
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-messagechannel-success.https.html
These test failures involve when postMessage is called to pass a SharedArrayBuffer,
to another context (i.e. another frame, window, worker).
See the example JS below:
const channel = new MessageChannel();
const sab = new SharedArrayBuffer(16);
channel.port1.postMessage(sab);
There is an optimization in WebKit to keep the MessagePorts
in a local HashMap (WebMessagePortChannelProvider::m_inProcessPortMessages)
to avoid performing unecessary IPC if the sender and receiver
are in the same process.
See https://commits.webkit.org/255948@main
This optimization caused issues with site isolation enabled
since it's possible for the target to be in a different process.
The optimization was undone in https://commits.webkit.org/295627@main
Without the optimization, all messages sent over a MessageChannel
are sent over IPC with site isolation enabled.
See the following code in WebMessagePortChannelProvider::postMessageToRemote
which falls back to IPC when the port is not found in m_inProcessPortMessages.
Remote here doesn't mean a different process, its just the receiver of postMessage.
void WebMessagePortChannelProvider::postMessageToRemote(MessageWithMessagePorts&& message, const MessagePortIdentifier& remoteTarget)
{
auto iterator = m_inProcessPortMessages.find(remoteTarget);
if (iterator != m_inProcessPortMessages.end()) {
iterator->value.append(WTF::move(message));
WebProcess::singleton().messagesAvailableForPort(remoteTarget);
return;
}
for (auto& port : message.transferredPorts)
messagePortSentToRemote(port.first);
protect(networkProcessConnection())->send(Messages::NetworkConnectionToWebProcess::PostMessageToRemote { message, remoteTarget }, 0);
}
However, this causes issues for messages which are not serializable over
IPC, such as SharedArrayBuffer which are marked as [NotSerialized]
https://searchfox.org/wubkat/source/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in#8013
This means that sending a SharedArrayBuffer will fail even when
the sender and receiver are in the same process and there is no
need to cross IPC.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/175890575>
Anthony Tarbinian
Pull request: https://github.com/WebKit/WebKit/pull/63933
EWS
Committed 312641@main (e2355e43e2ef): <https://commits.webkit.org/312641@main>
Reviewed commits have been landed. Closing PR #63933 and removing active labels.