Support "message_serialization": "structured_clone" for extension messaging
Component: WebKit Web Extensions | e8d9b34
Source/WebKit/Shared/Extensions/WebExtensionContextParameters.serialization.in
Source/WebKit/Shared/Extensions/WebExtensionContextParameters.h
Source/WebKit/CMakeLists.txt
Web extension APIs run in WebContent processes (background, content scripts, popups), and the UIProcess brokers messaging between them: the sender's process calls an IPC handler such as runtimeSendMessage, tabsSendMessage or portPostMessage, and the UIProcess forwards to the target's WebExtensionContextProxy. Until now the payload was always a JSON string, which is inert text. SerializedScriptValue is the structured-clone wire format postMessage uses; it can carry typed arrays, Maps, Blobs and other complex objects and is deserialized into live JS objects on the receiving side.
This commit adds a message_serialization manifest key. With structured_clone, runtime.sendMessage, tabs.sendMessage and Port.postMessage serialize with SerializedScriptValue. Messages and replies travel as a new WebExtensionMessage IPC type holding either a JSON string or a SerializedScriptValue, and receivers accept both. Replies become std::optional, and an invalid manifest value records InvalidManifestEntry and falls back to JSON. Web pages and native apps have no manifest to opt in, so those paths stay JSON.
Significance
Extensions can now pass ArrayBuffer, Map, Date and Blob across contexts without base64 chunking. Structured-clone payloads, including Blob references, now cross WebContent to UIProcess to WebContent through a new IPC variant type.
Audit directions
The new variant is a deserialization and relay path reachable by a compromised sender:
- How
runtimeSendMessage,tabsSendMessageandportPostMessagetreat the variant: whether they validate or inspect it, and whetherlength()is computed consistently for both alternatives. - Whether a compromised sender can force a structured clone onto a receiver that did not opt in, or onto native ports and web-page targets that are supposed to stay JSON.
- Blob lifetime: the sender keeps the message alive until the reply arrives, but replies, one-way sends, port messages and early disconnects may not have the same guarantee.
- Receiver-side
toJSValuedeserialization into the extension's global object (content script and isolated worlds), including failure and exception handling. - The
std::optionalreply split between missing and empty replies, at every call site and callback. - The skip logic for queued native port messages and the JSON fallback on an invalid manifest value.