Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6833b7d7f7beadc95bb5cccba523332d630d7e42
      
https://github.com/WebKit/WebKit/commit/6833b7d7f7beadc95bb5cccba523332d630d7e42
  Author: Brady Eidson <[email protected]>
  Date:   2023-04-07 (Fri, 07 Apr 2023)

  Changed paths:
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/workers/service/SWClientConnection.cpp
    M Source/WebCore/workers/service/SWClientConnection.h
    A Source/WebCore/workers/service/ServiceWorkerClientPendingMessage.h
    M Source/WebCore/workers/service/ServiceWorkerContainer.cpp
    M Source/WebCore/workers/service/WorkerSWClientConnection.cpp
    M Source/WebCore/workers/service/WorkerSWClientConnection.h
    M Source/WebCore/workers/service/server/SWServer.cpp
    M Source/WebCore/workers/service/server/SWServer.h
    M Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
    M Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
    M 
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
    M Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
    M Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in

  Log Message:
  -----------
  Initial ServiceWorkerWindowClient in a Home Screen web app launched to handle 
notificationclick handler is inert for a short period
https://bugs.webkit.org/show_bug.cgi?id=252544
rdar://105684663

Reviewed by Youenn Fablet.

There is a period of time between when the Networking process is told about a 
new ScriptExecutionContext
(when the main resource load begins) and when that ScriptExecutionContext 
actually exists (when the page load commits)

During that timespan, a ServiceWorker can discover the new ServiceWorkerClient 
represented by this Context,
and try to postMessage to it, and the Networking process will try to forward 
that message along to the appropriate
WebContent process, but... it won't find its target.

So the message is dropped on the floor.

This probably was technically always theoretical if a ServiceWorker was 
handling the fetch event for the main resource
load for the DocumentLoader. But it was likely not discovered because in those 
cases, ServiceWorkers probably aren't
that interested in postMessage()'ing to the client.

In NotificationClick handlers - especially without a Fetch handler - the 
vulnerable timespan increases, as does the
likelihood that the ServiceWorker wants to postMessage() to this new client.

This patch fixes the bug by:
1 - Changing postMessage() from Networking to WebContent processes to return 
whether or not the target was found
2 - If the target was not found, the Networking process remembers the failed 
postMessage for future use
3 - When ServiceWorkerContainer::startMessages() is called, it first fetches 
pending messages from the Networking process
    before firing off its locally deferred messages.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::postMessageToServiceWorkerClient):
* Source/WebCore/workers/service/SWClientConnection.h:
* Source/WebCore/workers/service/ServiceWorkerClientPendingMessage.h: Added.
* Source/WebCore/workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::startMessages):
* Source/WebCore/workers/service/WorkerSWClientConnection.cpp:
(WebCore::WorkerSWClientConnection::getServiceWorkerClientPendingMessages):
* Source/WebCore/workers/service/WorkerSWClientConnection.h:
* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::registerServiceWorkerClient):
(WebCore::SWServer::unregisterServiceWorkerClient):
(WebCore::SWServer::addServiceWorkerClientPendingMessage):
(WebCore::SWServer::releaseServiceWorkerClientPendingMessage):
* Source/WebCore/workers/service/server/SWServer.h:
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::postMessageToServiceWorkerClient):
(WebKit::WebSWServerConnection::getServiceWorkerClientPendingMessages):
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h:
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.messages.in:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::getServiceWorkerClientPendingMessages):
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.h:
* Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in:

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


_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to