Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e7b60aea9920bae50b3ff730eb1d3a229fa1dbdd
https://github.com/WebKit/WebKit/commit/e7b60aea9920bae50b3ff730eb1d3a229fa1dbdd
Author: Adrian Taylor <[email protected]>
Date: 2026-09-11 (Fri, 11 Sep 2026)
Changed paths:
M Source/WebKit/CMakeLists.txt
M Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
M Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
M Source/WebKit/Platform/IPC/Connection.cpp
M Source/WebKit/Platform/IPC/Connection.h
A Source/WebKit/Platform/IPC/MessageCheck.swift
M Source/WebKit/UIProcess/WebBackForwardList.cpp
M Source/WebKit/UIProcess/WebBackForwardList.swift
M Source/WebKit/UIProcess/WebBackForwardListSwiftUtilities.h
M Source/WebKit/UIProcess/WebProcessProxy.cpp
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
Log Message:
-----------
[Swift] Idiomatic MESSAGE_CHECK for Swift IPC receivers
https://bugs.webkit.org/show_bug.cgi?id=323854
rdar://168139740
Reviewed by Richard Robinson.
This is part one of two (possibly three) commits to define an idiomatic Swift
version of WebKit's MESSAGE_CHECK macro family.
That macro family in C++ is used to reject a potentially malicious message
traveling across the IPC boundary from a less privileged to a more privileged
process. That macro does four things: it zaps the potentially-malicious
process; it logs the fault in some configurations; it triggers a debugger or
aborts in some configurations, and above all, it does an early return such that
there is no further handling of the message.
The Swift stand-in for MESSAGE_CHECK in WebBackForwardList.swift was a faithful
port of the macro's mechanism, but required the caller to do an early return
since we do not have Swift macros.
In this PR we switch the Swift equivalent to throwing a Swift error, thrown
with `try messageCheck { condition }`. The `try` makes the early exit visible at
the call site and enforced by the compiler.
Adds Platform/IPC/MessageCheck.swift with:
- InvalidMessage.
- messageCheck(_:), the equivalent of MESSAGE_CHECK_BASE and
MESSAGE_CHECK_WITH_MESSAGE_BASE.
- dispatchMessage(on:onInvalidMessage:body:), the normal catch site.
onInvalidMessage supplies the reply so that a message with a completion
handler cannot hang the sender.
- markMessageInvalid(_:on:), for a receiver that has to catch InvalidMessage
somewhere other than dispatchMessage.
In this commit, a message handler needs to manually call 'dispatchMessage' to
catch and handle errors. Subsequent commits will move this to autogenerated
shims.
See WebBackForwardList.swift for the net effect on 'typical' message handler
code. It's slightly simplified by this change, but the big simplification
comes when the autogenerated shims arrive.
Of the things done by a MESSAGE_CHECK:
- Most are done at the point of 'throw' - the fault log and the crash - since
those are the ones which matter for debuggability.
- The last, marking the connection as invalid to terminate the sender, is
done at the point of 'catch' because it has access to the required
IPC::Connection.
This work requires that Connection's m_errorString accepts a Swift string,
so it's converted to WTF::String. This is used only when the IPC testing
API is enabled. We retain an ASCIILiteral overload so that 810 existing
C++ call sites do not get bloated.
* Source/WebKit/CMakeLists.txt:
* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::takeInvalidMessageStringForTesting):
* Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::takeInvalidMessageStringForTesting):
* Source/WebKit/Platform/IPC/Connection.h:
(IPC::Connection::setErrorString):
(IPC::Connection::takeErrorString):
(IPC::Connection::markCurrentlyDispatchedMessageAsInvalid):
(IPC::markCurrentlyDispatchedMessageAsInvalid):
* Source/WebKit/Platform/IPC/Connection.cpp:
(IPC::Connection::logFailedMessageCheck):
* Source/WebKit/Platform/IPC/MessageCheck.swift: Added.
(InvalidMessage.markMessageInvalid(_:on:)):
* Source/WebKit/UIProcess/WebBackForwardList.cpp:
(messageCheckFailed): Deleted.
(connectionForProcess):
* Source/WebKit/UIProcess/WebBackForwardList.swift:
(Direction.messageCheckItemURLs(_:process:)):
(Direction.backForwardUpdateItem(_:frameState:)):
(Direction.updateItem(_:frameState:)):
(Direction.backForwardGoToItemShared(_:)):
(Direction.goToItemInternal(_:)):
(messageCheck(_:_:)): Deleted.
* Source/WebKit/UIProcess/WebBackForwardListSwiftUtilities.h:
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::takeInvalidMessageStringForTesting):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
Canonical link: https://commits.webkit.org/320937@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications