Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 49d2e914a4ccb448ba8fc295a0c4838814c6dce5
      
https://github.com/WebKit/WebKit/commit/49d2e914a4ccb448ba8fc295a0c4838814c6dce5
  Author: Anthony Tarbinian <[email protected]>
  Date:   2026-05-13 (Wed, 13 May 2026)

  Changed paths:
    M LayoutTests/platform/ios-site-isolation/TestExpectations
    M LayoutTests/platform/mac-site-isolation/TestExpectations
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    A Source/WebCore/bindings/js/NonSerializedDataToken.h
    M Source/WebCore/bindings/js/SerializedScriptValue.cpp
    M Source/WebCore/bindings/js/SerializedScriptValue.h
    M Source/WebCore/bindings/js/SerializedScriptValueInternals.h
    A Source/WebCore/platform/NonSerializedDataIdentifier.h
    M Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
    M Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
    M Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
    M Source/WebKit/Scripts/webkit/messages.py
    M Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp
    M Source/WebKit/Shared/WTFArgumentCoders.serialization.in
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp
    M Source/WebKit/WebProcess/Network/NetworkProcessConnection.h
    M Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in
    M Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp
    M Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h

  Log Message:
  -----------
  [Site Isolation] Preserve non-serializable SharedArrayBuffer when IPC message 
returns to originating process
https://bugs.webkit.org/show_bug.cgi?id=314037
rdar://problem/176222943

Reviewed by Ryosuke Niwa.

When a message containing non-serializable data (e.g. SharedArrayBuffer)
is sent via MessagePort.postMessage and the target port is in a different 
process,
the message goes through IPC. Fields marked [NotSerialized] in
WebCoreArgumentCoders.serialization.in (such as sharedBufferContentsArray)
are dropped during IPC encoding. If the target port is later transferred
back to the originating process, the message follows the port back,
but the non-serializable data is already gone.

This patch preserves non-serializable data across IPC round-trips by
stashing it in a per-process registry before the message leaves,
and restoring it when the message returns.

Before sending a message through IPC in 
WebMessagePortChannelProvider::postMessageToRemote,
if the SerializedScriptValue has a non-empty sharedBufferContentsArray,
store it in m_nonSerializedDataRegistry keyed by a unique token.
This token includes two fields:
        - The process ID where the message originated from
        - A per-process ObjectIdentifier to distinguish
          between messages.
Then, mark the token on the message so it travels through IPC.

After receiving messages from IPC in 
WebMessagePortChannelProvider::takeAllMessagesForPort,
check each message for a token. If the token's ProcessIdentifier
matches the current process and the message is found in the registry
(meaning the message returned to the originating process), restore the
sharedBufferContentsArray.

If the token doesn't match the current process (meaning the
message originated from a different process) we notify
the process who sent the message to drop it from it's cache
via IPC. Since web processes can't communicate to each other,
this message is proxied through the NetworkProcess.

This patch fixes subtest 4 titled "postMessaging with a MessageChannel that's 
been cross-site should succeed" of
imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-iframe-messagechannel.https.html
which fails with site isolation enabled.

Although, subtest 2 is still failling, it fails consistently
with and without SI which is why we can remove this
test from SI TestExpectations.

* LayoutTests/platform/ios-site-isolation/TestExpectations:
* LayoutTests/platform/mac-site-isolation/TestExpectations:
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/NonSerializedDataToken.h: Added.
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValue::sharedBufferContentsArray):
(WebCore::SerializedScriptValue::nonSerializedDataToken const):
(WebCore::SerializedScriptValue::setNonSerializedDataToken):
* Source/WebCore/bindings/js/SerializedScriptValue.h:
* Source/WebCore/bindings/js/SerializedScriptValueInternals.h:
* Source/WebCore/platform/NonSerializedDataIdentifier.h: Added.
* Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::dropNonSerializableInProcessCache):
* Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h:
* Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* Source/WebKit/Scripts/webkit/messages.py:
(serialized_identifiers):
(headers_for_type):
* Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp:
(IPC::serializedIdentifiers):
* Source/WebKit/Shared/WTFArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::dropNonSerializableInProcessCache):
* Source/WebKit/WebProcess/Network/NetworkProcessConnection.h:
* Source/WebKit/WebProcess/Network/NetworkProcessConnection.messages.in:
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.cpp:
(WebKit::WebMessagePortChannelProvider::dropNonSerializableInProcessCache):
(WebKit::WebMessagePortChannelProvider::takeAllMessagesForPort):
        When the message is being accessed,
        take the message out of the in-process
        cache based on it's unique identifier.
(WebKit::WebMessagePortChannelProvider::postMessageToRemote):
        Cache non-serializable SharedArrayBuffer messages
        before they get dropped before attempted IPC.
* Source/WebKit/WebProcess/WebCoreSupport/WebMessagePortChannelProvider.h:

Canonical link: https://commits.webkit.org/313226@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to