⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 291589 in webkit


Ignore:
Timestamp:
Mar 21, 2022, 4:46:48 PM (4 years ago)
Author:
Chris Dumez
Message:

LayoutTests/imported/w3c:
BroadcastChannel instances in distinct opaque origins can communicate
https://bugs.webkit.org/show_bug.cgi?id=238090
<rdar://problem/90511155>

Reviewed by Alex Christensen.

Import web-platform-tests test coverage.

  • web-platform-tests/webmessaging/broadcastchannel/opaque-origin-expected.txt: Added.
  • web-platform-tests/webmessaging/broadcastchannel/opaque-origin.html: Added.
  • web-platform-tests/webmessaging/broadcastchannel/w3c-import.log:

Source/WebCore:
BroadcastChannel instances in distinct opaque origins can communicate
https://bugs.webkit.org/show_bug.cgi?id=238090
<rdar://problem/90511155>

Reviewed by Alex Christensen.

The issue is that we would use a ClientOrigin to distinguish origins for BroadcastChannel,
which relies on SecurityOriginData internally. A unique/opaque SecurityOrigin becomes an empty
SecurityOriginData upon conversion. As a result, when comparing ClientOrigin objects from
unique SecurityOrigins, they would compare as equal.

To address the issue, I introduced a new PartitionedSecurityOrigin type which is similar
to ClientOrigin but stores SecurityOrigin objects internally, instead of SecurityOriginData
objects. PartitionedSecurityOrigin's operator==() is such that different SecurityOrigins
would not be equal but the same unique SecurityOrigin would be. I then used this new
PartitionedSecurityOrigin type as key in our HashMap on the WebProcess side instead of
ClientOrigin. This allows communication between several BroadcastChannels from the same
unique origin, while preventing communication between distinct opaque origins.

When the PartitionedSecurityOrigin contains an opaque security origin, we don't involve
the Network Process at all since the destination can only be in the same WebProcess.

Test: imported/w3c/web-platform-tests/webmessaging/broadcastchannel/opaque-origin.html

  • Headers.cmake:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/BroadcastChannel.cpp:

(WebCore::shouldPartitionOrigin):
(WebCore::BroadcastChannel::MainThreadBridge::registerChannel):
(WebCore::BroadcastChannel::MainThreadBridge::unregisterChannel):
(WebCore::BroadcastChannel::MainThreadBridge::postMessage):

  • dom/BroadcastChannelRegistry.h:
  • loader/EmptyClients.cpp:
  • page/PartitionedSecurityOrigin.h: Added.

(WebCore::PartitionedSecurityOrigin::PartitionedSecurityOrigin):
(WebCore::PartitionedSecurityOrigin::isHashTableDeletedValue const):
(WebCore::PartitionedSecurityOrigin::isHashTableEmptyValue const):
(WebCore::operator==):
(WTF::add):
(WTF::PartitionedSecurityOriginHash::hash):
(WTF::PartitionedSecurityOriginHash::equal):
(WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::emptyValue):
(WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::constructEmptyValue):
(WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::isEmptyValue):
(WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::peek):
(WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::take):

Source/WebKit:
BroadcastChannel instances in distinct opaque origins can communicate
https://bugs.webkit.org/show_bug.cgi?id=238090
<rdar://problem/90511155>

Reviewed by Alex Christensen.

The issue is that we would use a ClientOrigin to distinguish origins for BroadcastChannel,
which relies on SecurityOriginData internally. A unique/opaque SecurityOrigin becomes an empty
SecurityOriginData upon conversion. As a result, when comparing ClientOrigin objects from
unique SecurityOrigins, they would compare as equal.

To address the issue, I introduced a new PartitionedSecurityOrigin type which is similar
to ClientOrigin but stores SecurityOrigin objects internally, instead of SecurityOriginData
objects. PartitionedSecurityOrigin's operator==() is such that different SecurityOrigins
would not be equal but the same unique SecurityOrigin would be. I then used this new
PartitionedSecurityOrigin type as key in our HashMap on the WebProcess side instead of
ClientOrigin. This allows communication between several BroadcastChannels from the same
unique origin, while preventing communication between distinct opaque origins.

When the PartitionedSecurityOrigin contains an opaque security origin, we don't involve
the Network Process at all since the destination can only be in the same WebProcess.

  • WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp:

(WebKit::toClientOrigin):
(WebKit::WebBroadcastChannelRegistry::registerChannel):
(WebKit::WebBroadcastChannelRegistry::unregisterChannel):
(WebKit::WebBroadcastChannelRegistry::postMessage):
(WebKit::WebBroadcastChannelRegistry::postMessageLocally):
(WebKit::WebBroadcastChannelRegistry::postMessageToRemote):
(WebKit::WebBroadcastChannelRegistry::networkProcessCrashed):

  • WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h:

Source/WebKitLegacy:
Dust off Mac CMake build
https://bugs.webkit.org/show_bug.cgi?id=238121

Reviewed by Yusuke Suzuki.

  • PlatformMac.cmake:
Location:
trunk
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291555 r291589  
     12022-03-21  Chris Dumez  <cdumez@apple.com>
     2
     3        BroadcastChannel instances in distinct opaque origins can communicate
     4        https://bugs.webkit.org/show_bug.cgi?id=238090
     5        <rdar://problem/90511155>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Import web-platform-tests test coverage.
     10
     11        * web-platform-tests/webmessaging/broadcastchannel/opaque-origin-expected.txt: Added.
     12        * web-platform-tests/webmessaging/broadcastchannel/opaque-origin.html: Added.
     13        * web-platform-tests/webmessaging/broadcastchannel/w3c-import.log:
     14
    1152022-03-21  Ziran Sun  <zsun@igalia.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/w3c-import.log

    r285503 r291589  
    2020/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/detached-iframe.html
    2121/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/interface.any.js
     22/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/opaque-origin.html
    2223/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/ordering.html
    2324/LayoutTests/imported/w3c/web-platform-tests/webmessaging/broadcastchannel/origin.window.js
  • trunk/Source/WebCore/ChangeLog

    r291588 r291589  
     12022-03-21  Chris Dumez  <cdumez@apple.com>
     2
     3        BroadcastChannel instances in distinct opaque origins can communicate
     4        https://bugs.webkit.org/show_bug.cgi?id=238090
     5        <rdar://problem/90511155>
     6
     7        Reviewed by Alex Christensen.
     8
     9        The issue is that we would use a ClientOrigin to distinguish origins for BroadcastChannel,
     10        which relies on SecurityOriginData internally. A unique/opaque SecurityOrigin becomes an empty
     11        SecurityOriginData upon conversion. As a result, when comparing ClientOrigin objects from
     12        unique SecurityOrigins, they would compare as equal.
     13
     14        To address the issue, I introduced a new PartitionedSecurityOrigin type which is similar
     15        to ClientOrigin but stores SecurityOrigin objects internally, instead of SecurityOriginData
     16        objects. PartitionedSecurityOrigin's operator==() is such that different SecurityOrigins
     17        would not be equal but the same unique SecurityOrigin would be. I then used this new
     18        PartitionedSecurityOrigin type as key in our HashMap on the WebProcess side instead of
     19        ClientOrigin. This allows communication between several BroadcastChannels from the same
     20        unique origin, while preventing communication between distinct opaque origins.
     21
     22        When the PartitionedSecurityOrigin contains an opaque security origin, we don't involve
     23        the Network Process at all since the destination can only be in the same WebProcess.
     24
     25        Test: imported/w3c/web-platform-tests/webmessaging/broadcastchannel/opaque-origin.html
     26
     27        * Headers.cmake:
     28        * WebCore.xcodeproj/project.pbxproj:
     29        * dom/BroadcastChannel.cpp:
     30        (WebCore::shouldPartitionOrigin):
     31        (WebCore::BroadcastChannel::MainThreadBridge::registerChannel):
     32        (WebCore::BroadcastChannel::MainThreadBridge::unregisterChannel):
     33        (WebCore::BroadcastChannel::MainThreadBridge::postMessage):
     34        * dom/BroadcastChannelRegistry.h:
     35        * loader/EmptyClients.cpp:
     36        * page/PartitionedSecurityOrigin.h: Added.
     37        (WebCore::PartitionedSecurityOrigin::PartitionedSecurityOrigin):
     38        (WebCore::PartitionedSecurityOrigin::isHashTableDeletedValue const):
     39        (WebCore::PartitionedSecurityOrigin::isHashTableEmptyValue const):
     40        (WebCore::operator==):
     41        (WTF::add):
     42        (WTF::PartitionedSecurityOriginHash::hash):
     43        (WTF::PartitionedSecurityOriginHash::equal):
     44        (WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::emptyValue):
     45        (WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::constructEmptyValue):
     46        (WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::isEmptyValue):
     47        (WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::peek):
     48        (WTF::HashTraits<WebCore::PartitionedSecurityOrigin>::take):
     49
    1502022-03-21  Kate Cheney  <katherine_cheney@apple.com>
    251
  • trunk/Source/WebCore/Headers.cmake

    r291548 r291589  
    11421142    page/PageOverlayController.h
    11431143    page/PagePasteboardContext.h
     1144    page/PartitionedSecurityOrigin.h
    11441145    page/PerformanceLogging.h
    11451146    page/PerformanceLoggingClient.h
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r291564 r291589  
    13581358                4688E98027B6B45000567CD2 /* CoreLocationGeolocationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 4688E97F27B6B44400567CD2 /* CoreLocationGeolocationProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13591359                4688EE3C26DD2610002AF5C4 /* CrossOriginMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4688EE3A26DD260C002AF5C4 /* CrossOriginMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1360                46893B8427E8D74C002CC13D /* PartitionedSecurityOrigin.h in Headers */ = {isa = PBXBuildFile; fileRef = 46893B8327E8D716002CC13D /* PartitionedSecurityOrigin.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13601361                46943DC92763F817004B610E /* SharedWorkerObjectIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46943DC72763F80E004B610E /* SharedWorkerObjectIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13611362                46985F2327A4A6AD0097A32B /* SharedWorkerKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 46985F2227A4A6860097A32B /* SharedWorkerKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    92899290                4688E97F27B6B44400567CD2 /* CoreLocationGeolocationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreLocationGeolocationProvider.h; sourceTree = "<group>"; };
    92909291                4688EE3A26DD260C002AF5C4 /* CrossOriginMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CrossOriginMode.h; sourceTree = "<group>"; };
     9292                46893B8327E8D716002CC13D /* PartitionedSecurityOrigin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PartitionedSecurityOrigin.h; sourceTree = "<group>"; };
    92919293                468B8BDE25CC849300F67822 /* JSBaseAudioContextCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSBaseAudioContextCustom.cpp; sourceTree = "<group>"; };
    92929294                46943DC72763F80E004B610E /* SharedWorkerObjectIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerObjectIdentifier.h; sourceTree = "<group>"; };
     
    2426324265                                371E65CD13661EED00BEEDB0 /* PageSerializer.cpp */,
    2426424266                                371E65CB13661EDC00BEEDB0 /* PageSerializer.h */,
     24267                                46893B8327E8D716002CC13D /* PartitionedSecurityOrigin.h */,
    2426524268                                BC4A53282560563B0028C592 /* PDFImageCachingPolicy.h */,
    2426624269                                7C72471E2516758800C363CD /* Performance+NavigationTiming.idl */,
     
    3660336606                                5C4A0FDA25C3449A00D9EE97 /* ParsedRequestRange.h in Headers */,
    3660436607                                536D5A23193E8E0C00CE4CAB /* ParsingUtilities.h in Headers */,
     36608                                46893B8427E8D74C002CC13D /* PartitionedSecurityOrigin.h in Headers */,
    3660536609                                F55B3DCA1251F12D003EF269 /* PasswordInputType.h in Headers */,
    3660636610                                4B2708C70AF19EE40065127F /* Pasteboard.h in Headers */,
  • trunk/Source/WebCore/dom/BroadcastChannel.cpp

    r290566 r291589  
    3131#include "MessageEvent.h"
    3232#include "Page.h"
     33#include "PartitionedSecurityOrigin.h"
    3334#include "SecurityOrigin.h"
    3435#include "SerializedScriptValue.h"
     
    8788    const BroadcastChannelIdentifier m_identifier;
    8889    const String m_name; // Main thread only.
    89     ClientOrigin m_origin; // Main thread only.
     90    std::optional<PartitionedSecurityOrigin> m_origin; // Main thread only.
    9091};
    9192
     
    121122{
    122123    ensureOnMainThread([this, contextIdentifier = m_broadcastChannel->scriptExecutionContext()->identifier()](auto& document) {
    123         m_origin = { shouldPartitionOrigin(document) ? document.topOrigin().data() : document.securityOrigin().data(), document.securityOrigin().data() };
     124        m_origin = PartitionedSecurityOrigin { shouldPartitionOrigin(document) ? document.topOrigin() : document.securityOrigin(), document.securityOrigin() };
    124125        if (auto* page = document.page())
    125             page->broadcastChannelRegistry().registerChannel(m_origin, m_name, m_identifier);
     126            page->broadcastChannelRegistry().registerChannel(*m_origin, m_name, m_identifier);
    126127        channelToContextIdentifier().add(m_identifier, contextIdentifier);
    127128    });
     
    132133    ensureOnMainThread([this](auto& document) {
    133134        if (auto* page = document.page())
    134             page->broadcastChannelRegistry().unregisterChannel(m_origin, m_name, m_identifier);
     135            page->broadcastChannelRegistry().unregisterChannel(*m_origin, m_name, m_identifier);
    135136        channelToContextIdentifier().remove(m_identifier);
    136137    });
     
    145146
    146147        auto blobHandles = message->blobHandles();
    147         page->broadcastChannelRegistry().postMessage(m_origin, m_name, m_identifier, WTFMove(message), [blobHandles = WTFMove(blobHandles)] {
     148        page->broadcastChannelRegistry().postMessage(*m_origin, m_name, m_identifier, WTFMove(message), [blobHandles = WTFMove(blobHandles)] {
    148149            // Keeps Blob data inside messageData alive until the message has been delivered.
    149150        });
  • trunk/Source/WebCore/dom/BroadcastChannelRegistry.h

    r282105 r291589  
    3232namespace WebCore {
    3333
     34struct PartitionedSecurityOrigin;
    3435class SerializedScriptValue;
    35 struct ClientOrigin;
    3636
    3737class BroadcastChannelRegistry : public RefCounted<BroadcastChannelRegistry> {
    3838public:
    3939    virtual ~BroadcastChannelRegistry() { }
    40     virtual void registerChannel(const ClientOrigin&, const String& name, BroadcastChannelIdentifier) = 0;
    41     virtual void unregisterChannel(const ClientOrigin&, const String& name, BroadcastChannelIdentifier) = 0;
    42     virtual void postMessage(const ClientOrigin&, const String& name, BroadcastChannelIdentifier source, Ref<SerializedScriptValue>&&, CompletionHandler<void()>&&) = 0;
     40    virtual void registerChannel(const PartitionedSecurityOrigin&, const String& name, BroadcastChannelIdentifier) = 0;
     41    virtual void unregisterChannel(const PartitionedSecurityOrigin&, const String& name, BroadcastChannelIdentifier) = 0;
     42    virtual void postMessage(const PartitionedSecurityOrigin&, const String& name, BroadcastChannelIdentifier source, Ref<SerializedScriptValue>&&, CompletionHandler<void()>&&) = 0;
    4343};
    4444
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r290849 r291589  
    11891189    EmptyBroadcastChannelRegistry() = default;
    11901190
    1191     void registerChannel(const ClientOrigin&, const String&, BroadcastChannelIdentifier) final { }
    1192     void unregisterChannel(const ClientOrigin&, const String&, BroadcastChannelIdentifier) final { }
    1193     void postMessage(const ClientOrigin&, const String&, BroadcastChannelIdentifier, Ref<SerializedScriptValue>&&, CompletionHandler<void()>&&) final { }
     1191    void registerChannel(const PartitionedSecurityOrigin&, const String&, BroadcastChannelIdentifier) final { }
     1192    void unregisterChannel(const PartitionedSecurityOrigin&, const String&, BroadcastChannelIdentifier) final { }
     1193    void postMessage(const PartitionedSecurityOrigin&, const String&, BroadcastChannelIdentifier, Ref<SerializedScriptValue>&&, CompletionHandler<void()>&&) final { }
    11941194};
    11951195
  • trunk/Source/WebKit/ChangeLog

    r291579 r291589  
     12022-03-21  Chris Dumez  <cdumez@apple.com>
     2
     3        BroadcastChannel instances in distinct opaque origins can communicate
     4        https://bugs.webkit.org/show_bug.cgi?id=238090
     5        <rdar://problem/90511155>
     6
     7        Reviewed by Alex Christensen.
     8
     9        The issue is that we would use a ClientOrigin to distinguish origins for BroadcastChannel,
     10        which relies on SecurityOriginData internally. A unique/opaque SecurityOrigin becomes an empty
     11        SecurityOriginData upon conversion. As a result, when comparing ClientOrigin objects from
     12        unique SecurityOrigins, they would compare as equal.
     13
     14        To address the issue, I introduced a new PartitionedSecurityOrigin type which is similar
     15        to ClientOrigin but stores SecurityOrigin objects internally, instead of SecurityOriginData
     16        objects. PartitionedSecurityOrigin's operator==() is such that different SecurityOrigins
     17        would not be equal but the same unique SecurityOrigin would be. I then used this new
     18        PartitionedSecurityOrigin type as key in our HashMap on the WebProcess side instead of
     19        ClientOrigin. This allows communication between several BroadcastChannels from the same
     20        unique origin, while preventing communication between distinct opaque origins.
     21
     22        When the PartitionedSecurityOrigin contains an opaque security origin, we don't involve
     23        the Network Process at all since the destination can only be in the same WebProcess.
     24
     25        * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp:
     26        (WebKit::toClientOrigin):
     27        (WebKit::WebBroadcastChannelRegistry::registerChannel):
     28        (WebKit::WebBroadcastChannelRegistry::unregisterChannel):
     29        (WebKit::WebBroadcastChannelRegistry::postMessage):
     30        (WebKit::WebBroadcastChannelRegistry::postMessageLocally):
     31        (WebKit::WebBroadcastChannelRegistry::postMessageToRemote):
     32        (WebKit::WebBroadcastChannelRegistry::networkProcessCrashed):
     33        * WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h:
     34
    1352022-03-21  Brent Fulgham  <bfulgham@apple.com>
    236
  • trunk/Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.cpp

    r282377 r291589  
    2727#include "NetworkBroadcastChannelRegistry.h"
    2828
     29#include "NetworkProcessProxyMessages.h"
    2930#include "WebBroadcastChannelRegistryMessages.h"
    3031#include <WebCore/MessageWithMessagePorts.h>
     
    3334namespace WebKit {
    3435
    35 NetworkBroadcastChannelRegistry::NetworkBroadcastChannelRegistry() = default;
     36#define REGISTRY_MESSAGE_CHECK(assertion) REGISTRY_MESSAGE_CHECK_COMPLETION(assertion, (void)0)
     37#define REGISTRY_MESSAGE_CHECK_COMPLETION(assertion, completion) do { \
     38    ASSERT(assertion); \
     39    if (UNLIKELY(!(assertion))) { \
     40        if (auto webProcessIdentifier = m_networkProcess->webProcessIdentifierForConnection(connection)) \
     41            m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::TerminateWebProcess(webProcessIdentifier), 0); \
     42        { completion; } \
     43        return; \
     44    } \
     45} while (0)
     46
     47static bool isValidClientOrigin(const WebCore::ClientOrigin& clientOrigin)
     48{
     49    return !clientOrigin.topOrigin.isEmpty() && !clientOrigin.clientOrigin.isEmpty();
     50}
     51
     52NetworkBroadcastChannelRegistry::NetworkBroadcastChannelRegistry(NetworkProcess& networkProcess)
     53    : m_networkProcess(networkProcess)
     54{
     55}
    3656
    3757void NetworkBroadcastChannelRegistry::registerChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name)
    3858{
     59    REGISTRY_MESSAGE_CHECK(isValidClientOrigin(origin));
     60
    3961    auto& channelsForOrigin = m_broadcastChannels.ensure(origin, [] { return NameToConnectionIdentifiersMap { }; }).iterator->value;
    4062    auto& connectionIdentifiersForName = channelsForOrigin.ensure(name, [] { return Vector<IPC::Connection::UniqueID> { }; }).iterator->value;
     
    4567void NetworkBroadcastChannelRegistry::unregisterChannel(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name)
    4668{
     69    REGISTRY_MESSAGE_CHECK(isValidClientOrigin(origin));
     70
    4771    auto channelsForOriginIterator = m_broadcastChannels.find(origin);
    4872    ASSERT(channelsForOriginIterator != m_broadcastChannels.end());
     
    6084void NetworkBroadcastChannelRegistry::postMessage(IPC::Connection& connection, const WebCore::ClientOrigin& origin, const String& name, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler)
    6185{
     86    REGISTRY_MESSAGE_CHECK_COMPLETION(isValidClientOrigin(origin), completionHandler());
     87
    6288    auto channelsForOriginIterator = m_broadcastChannels.find(origin);
    6389    ASSERT(channelsForOriginIterator != m_broadcastChannels.end());
     
    102128}
    103129
     130#undef REGISTRY_MESSAGE_CHECK
     131#undef REGISTRY_MESSAGE_CHECK_COMPLETION
     132
    104133} // namespace WebKit
  • trunk/Source/WebKit/NetworkProcess/NetworkBroadcastChannelRegistry.h

    r282377 r291589  
    3737namespace WebKit {
    3838
     39class NetworkProcess;
     40
    3941class NetworkBroadcastChannelRegistry {
    4042    WTF_MAKE_FAST_ALLOCATED;
    4143public:
    42     NetworkBroadcastChannelRegistry();
     44    explicit NetworkBroadcastChannelRegistry(NetworkProcess&);
    4345
    4446    void removeConnection(IPC::Connection&);
     
    5153
    5254private:
     55    Ref<NetworkProcess> m_networkProcess;
    5356    using NameToConnectionIdentifiersMap = HashMap<String, Vector<IPC::Connection::UniqueID>>;
    5457    HashMap<WebCore::ClientOrigin, NameToConnectionIdentifiersMap> m_broadcastChannels;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r291492 r291589  
    25532553}
    25542554
     2555WebCore::ProcessIdentifier NetworkProcess::webProcessIdentifierForConnection(IPC::Connection& connection) const
     2556{
     2557    for (auto& [processIdentifier, webConnection] : m_webProcessConnections) {
     2558        if (&webConnection->connection() == &connection)
     2559            return processIdentifier;
     2560    }
     2561    return { };
     2562}
     2563
    25552564NetworkConnectionToWebProcess* NetworkProcess::webProcessConnection(ProcessIdentifier identifier) const
    25562565{
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r291492 r291589  
    333333
    334334    NetworkConnectionToWebProcess* webProcessConnection(WebCore::ProcessIdentifier) const;
     335    WebCore::ProcessIdentifier webProcessIdentifierForConnection(IPC::Connection&) const;
    335336    WebCore::MessagePortChannelRegistry& messagePortChannelRegistry() { return m_messagePortChannelRegistry; }
    336337
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r291003 r291589  
    139139    , m_privateClickMeasurement(managerOrProxy(*this, networkProcess, parameters))
    140140    , m_privateClickMeasurementDebugModeEnabled(parameters.enablePrivateClickMeasurementDebugMode)
    141     , m_broadcastChannelRegistry(makeUniqueRef<NetworkBroadcastChannelRegistry>())
     141    , m_broadcastChannelRegistry(makeUniqueRef<NetworkBroadcastChannelRegistry>(networkProcess))
    142142    , m_testSpeedMultiplier(parameters.testSpeedMultiplier)
    143143    , m_allowsServerPreconnect(parameters.allowsServerPreconnect)
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp

    r282483 r291589  
    4141}
    4242
    43 void WebBroadcastChannelRegistry::registerChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
     43// Unique origins are only stored in process in m_channelsPerOrigin and never sent to the NetworkProcess as a ClientOrigin.
     44// The identity of unique origins wouldn't be preserved when serializing them as a SecurityOriginData (via ClientOrigin).
     45// Since BroadcastChannels from a unique origin can only communicate with other BroadcastChannels from the same unique origin,
     46// the destination channels have to be within the same WebProcess anyway.
     47static std::optional<WebCore::ClientOrigin> toClientOrigin(const WebCore::PartitionedSecurityOrigin& origin)
     48{
     49    if (origin.topOrigin->isUnique() || origin.clientOrigin->isUnique())
     50        return std::nullopt;
     51    return WebCore::ClientOrigin { origin.topOrigin->data(), origin.clientOrigin->data() };
     52}
     53
     54void WebBroadcastChannelRegistry::registerChannel(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
    4455{
    4556    auto& channelsForOrigin = m_channelsPerOrigin.ensure(origin, [] { return HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>> { }; }).iterator->value;
     
    4758    channelsForName.append(identifier);
    4859
    49     if (channelsForName.size() == 1)
    50         networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { origin, name }, 0);
     60    if (channelsForName.size() == 1) {
     61        if (auto clientOrigin = toClientOrigin(origin))
     62            networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { *clientOrigin, name }, 0);
     63    }
    5164}
    5265
    53 void WebBroadcastChannelRegistry::unregisterChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
     66void WebBroadcastChannelRegistry::unregisterChannel(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
    5467{
    5568    auto channelsPerOriginIterator = m_channelsPerOrigin.find(origin);
     
    6982
    7083    channelsForOrigin.remove(channelsForOriginIterator);
    71     networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::UnregisterChannel { origin, name }, 0);
     84    if (auto clientOrigin = toClientOrigin(origin))
     85        networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::UnregisterChannel { *clientOrigin, name }, 0);
    7286
    7387    if (channelsForOrigin.isEmpty())
     
    7589}
    7690
    77 void WebBroadcastChannelRegistry::postMessage(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler)
     91void WebBroadcastChannelRegistry::postMessage(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler)
    7892{
    7993    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
    8094    postMessageLocally(origin, name, source, message.copyRef(), callbackAggregator.copyRef());
    81     networkProcessConnection().sendWithAsyncReply(Messages::NetworkBroadcastChannelRegistry::PostMessage { origin, name, WebCore::MessageWithMessagePorts { WTFMove(message), { } } }, [callbackAggregator] { }, 0);
     95    if (auto clientOrigin = toClientOrigin(origin))
     96        networkProcessConnection().sendWithAsyncReply(Messages::NetworkBroadcastChannelRegistry::PostMessage { *clientOrigin, name, WebCore::MessageWithMessagePorts { WTFMove(message), { } } }, [callbackAggregator] { }, 0);
    8297}
    8398
    84 void WebBroadcastChannelRegistry::postMessageLocally(const WebCore::ClientOrigin& origin, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&& message, Ref<WTF::CallbackAggregator>&& callbackAggregator)
     99void WebBroadcastChannelRegistry::postMessageLocally(const WebCore::PartitionedSecurityOrigin& origin, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&& message, Ref<WTF::CallbackAggregator>&& callbackAggregator)
    85100{
    86101    auto channelsPerOriginIterator = m_channelsPerOrigin.find(origin);
     
    101116}
    102117
    103 void WebBroadcastChannelRegistry::postMessageToRemote(const WebCore::ClientOrigin& origin, const String& name, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler)
     118void WebBroadcastChannelRegistry::postMessageToRemote(const WebCore::ClientOrigin& clientOrigin, const String& name, WebCore::MessageWithMessagePorts&& message, CompletionHandler<void()>&& completionHandler)
    104119{
    105120    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
     121    WebCore::PartitionedSecurityOrigin origin { clientOrigin.topOrigin.securityOrigin(), clientOrigin.clientOrigin.securityOrigin() };
    106122    postMessageLocally(origin, name, std::nullopt, *message.message, callbackAggregator.copyRef());
    107123}
     
    110126{
    111127    for (auto& [origin, channelsForOrigin] : m_channelsPerOrigin) {
     128        auto clientOrigin = toClientOrigin(origin);
     129        if (!clientOrigin)
     130            continue;
    112131        for (auto& name : channelsForOrigin.keys())
    113             networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { origin, name }, 0);
     132            networkProcessConnection().send(Messages::NetworkBroadcastChannelRegistry::RegisterChannel { *clientOrigin, name }, 0);
    114133    }
    115134}
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.h

    r282483 r291589  
    2929#include <WebCore/BroadcastChannelRegistry.h>
    3030#include <WebCore/ClientOrigin.h>
     31#include <WebCore/PartitionedSecurityOrigin.h>
     32#include <WebCore/SecurityOrigin.h>
    3133#include <wtf/HashMap.h>
    3234#include <wtf/Vector.h>
     
    4951    }
    5052
    51     void registerChannel(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
    52     void unregisterChannel(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
    53     void postMessage(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&&, CompletionHandler<void()>&&) final;
     53    void registerChannel(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
     54    void unregisterChannel(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
     55    void postMessage(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&&, CompletionHandler<void()>&&) final;
    5456
    5557    void networkProcessCrashed();
     
    6163
    6264    void postMessageToRemote(const WebCore::ClientOrigin&, const String& name, WebCore::MessageWithMessagePorts&&, CompletionHandler<void()>&&);
    63     void postMessageLocally(const WebCore::ClientOrigin&, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&&, Ref<WTF::CallbackAggregator>&&);
     65    void postMessageLocally(const WebCore::PartitionedSecurityOrigin&, const String& name, std::optional<WebCore::BroadcastChannelIdentifier> sourceInProcess, Ref<WebCore::SerializedScriptValue>&&, Ref<WTF::CallbackAggregator>&&);
    6466
    65     HashMap<WebCore::ClientOrigin, HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>>> m_channelsPerOrigin;
     67    HashMap<WebCore::PartitionedSecurityOrigin, HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>>> m_channelsPerOrigin;
    6668};
    6769
  • trunk/Source/WebKitLegacy/ChangeLog

    r291562 r291589  
    77
    88        * PlatformMac.cmake:
     9
     102022-03-21  Chris Dumez  <cdumez@apple.com>
     11
     12        BroadcastChannel instances in distinct opaque origins can communicate
     13        https://bugs.webkit.org/show_bug.cgi?id=238090
     14        <rdar://problem/90511155>
     15
     16        Reviewed by Alex Christensen.
     17
     18        * WebCoreSupport/WebBroadcastChannelRegistry.cpp:
     19        (WebBroadcastChannelRegistry::registerChannel):
     20        (WebBroadcastChannelRegistry::unregisterChannel):
     21        (WebBroadcastChannelRegistry::postMessage):
     22        * WebCoreSupport/WebBroadcastChannelRegistry.h:
    923
    10242022-03-08  Chris Dumez  <cdumez@apple.com>
  • trunk/Source/WebKitLegacy/WebCoreSupport/WebBroadcastChannelRegistry.cpp

    r284142 r291589  
    4545}
    4646
    47 void WebBroadcastChannelRegistry::registerChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
     47void WebBroadcastChannelRegistry::registerChannel(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
    4848{
    4949    ASSERT(isMainThread());
     
    5454}
    5555
    56 void WebBroadcastChannelRegistry::unregisterChannel(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
     56void WebBroadcastChannelRegistry::unregisterChannel(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier identifier)
    5757{
    5858    ASSERT(isMainThread());
     
    6767}
    6868
    69 void WebBroadcastChannelRegistry::postMessage(const WebCore::ClientOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler)
     69void WebBroadcastChannelRegistry::postMessage(const WebCore::PartitionedSecurityOrigin& origin, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler)
    7070{
    7171    ASSERT(isMainThread());
  • trunk/Source/WebKitLegacy/WebCoreSupport/WebBroadcastChannelRegistry.h

    r282105 r291589  
    2525
    2626#include <WebCore/BroadcastChannelRegistry.h>
    27 #include <WebCore/ClientOrigin.h>
     27#include <WebCore/PartitionedSecurityOrigin.h>
    2828#include <wtf/Forward.h>
    2929#include <wtf/WeakPtr.h>
     
    3535    static Ref<WebBroadcastChannelRegistry> getOrCreate(bool privateSession);
    3636
    37     void registerChannel(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
    38     void unregisterChannel(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
    39     void postMessage(const WebCore::ClientOrigin&, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&&, CompletionHandler<void()>&&) final;
     37    void registerChannel(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
     38    void unregisterChannel(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier) final;
     39    void postMessage(const WebCore::PartitionedSecurityOrigin&, const String& name, WebCore::BroadcastChannelIdentifier source, Ref<WebCore::SerializedScriptValue>&&, CompletionHandler<void()>&&) final;
    4040
    4141private:
     
    4343
    4444    using NameToChannelIdentifiersMap = HashMap<String, Vector<WebCore::BroadcastChannelIdentifier>>;
    45     HashMap<WebCore::ClientOrigin, NameToChannelIdentifiersMap> m_channels;
     45    HashMap<WebCore::PartitionedSecurityOrigin, NameToChannelIdentifiersMap> m_channels;
    4646};
Note: See TracChangeset for help on using the changeset viewer.