← All reports

[4] Forged `IsPlayingMediaDidChange` activates the display-capture process capability without consent

MediumWebKit UIProcessAuthBypass

The UI process granted a screen-capture capability on the renderer's word alone.

b29ee02

A logic bug, not memory corruption, and Medium because the attacker needs a compromised renderer first. Past that gate, the renderer could talk the UI process into granting an OS-level screen-capture capability without ever showing a prompt.

WebKit's UI process is the privileged broker in a multi-process browser: it owns permission prompts and treats everything the sandboxed web-content process reports as untrusted. On Cocoa platforms it can also grant OS-level process capabilities through a capability granter. A MediaCapability is the object representing one such grant, and one of them covers display (screen/window) capture. The expected rule is that the display-capture capability is activated only after the UI process itself has prompted for, or recorded approval of, a getDisplayMedia() request.

The angle: an attacker who already has renderer code execution could make the UI process activate the display-capture capability with no user prompt, and could keep it from being revoked.

From the commit message: internals().mediaState is stored verbatim from WebContent IPC, yet shouldActivateDisplayCaptureCapability() used it to drive a privileged action. A compromised WebContent process could set display-capture bits and have the UI process grant BEProcessCapability screenCapture back to itself and to the GPU process, with no getDisplayMedia() prompt. Both HasActiveScreenCaptureDevice and the IsPromptingFor*Capture bits reach the predicate, and both are forgeable. Activation is now gated on a UI-process authorization record instead. The commit deliberately does not use a MESSAGE_CHECK: an in-flight message still carrying display-capture bits after the UI process resets access or navigates would otherwise terminate a legitimate WebContent process.

Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

+bool WebPageProxy::hasDisplayCaptureAuthorization() const
+{
+#if ENABLE(MEDIA_STREAM)
+ return m_isPromptingForDisplayCapture || m_hasGrantedDisplayCapture;
+#else
+ return false;
+#endif
+}
+
bool WebPageProxy::shouldActivateDisplayCaptureCapability() const
{
if (!isViewVisible())
return false;
 
+ if (!hasDisplayCaptureAuthorization())
+ return false;
+
return internals().mediaState.containsAny(MediaProducer::DisplayCaptureMask | MediaProducer::IsPromptingForDisplayCaptureMask);
}
...
if (!displayCaptureCapability || !displayCaptureCapability->isActivatingOrActive())
return false;
 
+ if (!hasDisplayCaptureAuthorization())
+ return true;
+

Source/WebKit/UIProcess/WebPageProxy.cpp

@@ willStartCapture
[[fallthrough]];
case WebCore::MediaStreamRequest::Type::DisplayMedia:
m_mutedCaptureKindsDesiredByWebApp.remove(WebCore::MediaProducerMediaCaptureKind::Display);
+ m_isPromptingForDisplayCapture = false;
+ m_hasGrantedDisplayCapture = true;
break;
...
@@ setIsPromptingForGetDisplayMedia
+#if ENABLE(MEDIA_STREAM)
+ m_isPromptingForDisplayCapture = isPrompting;
+#endif
...
@@ stopMediaCapture
+ if (kind == MediaProducerMediaCaptureKind::Display || kind == MediaProducerMediaCaptureKind::EveryKind)
+ m_hasGrantedDisplayCapture = false;
...
@@ updatePlayingMediaDidChange
RefPtr userMediaPermissionRequestManager = m_userMediaPermissionRequestManager;
- ASSERT(userMediaPermissionRequestManager);
if (userMediaPermissionRequestManager)

LayoutTests/http/tests/ipc/display-capture-capability-forged-media-state.html

+const IsPromptingForScreenCapture = 1 << 29;
+ IPC.sendMessage("UI", IPC.webPageProxyID, IPC.messages.WebPageProxy_IsPlayingMediaDidChange.name,
+ [{ type: "uint32_t", value: IsPromptingForScreenCapture }]);
+ waitForUIProcessToDispatchQueuedMessages();
+ expect("the forged media state does not activate the capability",
+ testRunner.isDisplayCaptureCapabilityActive(), false);

The change makes three moves. It introduces a UI-owned authorization record. It wires that record into both capability predicates. It adds test plumbing that forges the offending IPC message.

In WebPageProxy.h, two bools are added: m_isPromptingForDisplayCapture and m_hasGrantedDisplayCapture. They are set and cleared in WebPageProxy.cpp:

In WebPageProxyCocoa.mm, hasDisplayCaptureAuthorization() ORs the two flags. shouldActivateDisplayCaptureCapability() returns false without authorization before it consults the mediaState bits. shouldDeactivateDisplayCaptureCapability() returns true (revoke) for an active or activating capability whenever authorization is absent.

The test plumbing comprises WebPageProxyTesting::isDisplayCaptureCapabilityActive(), the WKWebView/WebKitTestRunner bindings, an API test, and a layout test. The layout test sends a forged WebPageProxy_IsPlayingMediaDidChange carrying bit 29 (IsPromptingForScreenCapture) and asserts the capability stays inactive.

Privileged capability grant driven by state the less-privileged peer reports about itself, rather than by an authorization record the privileged side owns.

Process model. WebKit splits a page across a sandboxed WebContent process (page script and layout), a GPU process (media and graphics work), and the privileged UI process. The UI process owns permission decisions and treats WebContent as untrusted when it receives IPC.

MediaProducerMediaStateFlags. This bitfield summarizes a page's media activity: playing audio or video, an active or muted camera, microphone, screen or window capture, and whether a capture permission prompt is pending. WebContent reports it to the UI process via the IsPlayingMediaDidChange message, and WebPageProxy keeps an aggregate in internals().mediaState. DisplayCaptureMask and IsPromptingForDisplayCaptureMask are the subsets of these flags that relate to screen and window capture.

The getDisplayMedia() permission flow. When a page calls getDisplayMedia(), the request reaches the UI process's user-media permission manager, which may show a system or app prompt; setIsPromptingForGetDisplayMedia tracks the prompt state. On approval, WebPageProxy::willStartCapture configures the page for the granted capture kind, switching on MediaStreamRequest::Type. stopMediaCapture and resetState tear capture state down, and didCommitLoadForFrame on the main frame marks a navigation boundary.

Process capabilities. On platforms built with ENABLE(EXTENSION_CAPABILITIES), the UI process can grant OS-level process capabilities to helper processes through the process pool's extensionCapabilityGranter(). A MediaCapability represents one such grant and exposes states like isActivatingOrActive(). WebPageProxy decides when to activate or deactivate its displayCaptureCapability using the predicates shouldActivateDisplayCaptureCapability() and shouldDeactivateDisplayCaptureCapability().

MESSAGE_CHECK. This WebKit IPC-validation macro treats the sending process as compromised and terminates it when its condition fails.

This is a confused-deputy authorization bypass: the UI process granted a privilege based on the renderer's own description of itself.

  WebContent (compromised)              UI process
  +------------------------+   IPC     +---------------------------------------+
  | IsPlayingMediaDidChange| --------> | internals().mediaState := bit 29      |
  |   (1 << 29)            |           | shouldActivateDisplayCaptureCapability|
  +------------------------+           |   isViewVisible() && bits present     |
           ^                           |   -> true                             |
           |  capability granted       | extensionCapabilityGranter()->grant(  |
           +-------------------------- |   *displayCaptureCapability, *this)   |
                                       +---------------------------------------+
           (no getDisplayMedia() prompt, no permission record, at any step)

Before the fix, the predicate on the right checked only view visibility and whether mediaState contained any display-capture or prompting bit. Nothing tied those bits to a permission decision the UI process had made. The commit message states that internals().mediaState is stored verbatim from WebContent IPC, and the regression test confirms that a single forged message carrying bit 29 reaches the predicate. Once the predicate went true, the activation path called grant(). Deactivation had the mirror flaw: shouldDeactivateDisplayCaptureCapability() returned false whenever the same forgeable bits were present, so a renderer could also keep an active capability alive.

The removed ASSERT is a secondary finding. It sat in updatePlayingMediaDidChange(), which forged capture bits make reachable from WebContent IPC, so a renderer could trip it in debug builds. Release builds were already safe because of the null check that followed. The regression test's single-message forgery through the IPC testing API suggests IPC-boundary pattern auditing, or IPC-focused fuzzing that sends arbitrary WebPageProxy messages and watches UI-side state.

The bug is reachable only from a compromised WebContent process, or from the IPC testing API in test builds. Ordinary script must go through getDisplayMedia() and its prompt. For an attacker who already has renderer code execution, the pre-fix code would activate the display-capture capability with no user consent. This is a post-compromise escalation step, not an entry point.

Two audit questions bound the real-world impact. The first is what the display-capture MediaCapability unlocks once grant() succeeds. Holding it might be enough for a compromised WebContent or GPU process to reach display-capture APIs directly, or capture might still be brokered by UI-process code that runs its own permission checks.

The second is the lifetime of m_hasGrantedDisplayCapture. It is set at the DisplayMedia case of willStartCapture(), which the preceding case also reaches via [[fallthrough]]. It is cleared only on main-frame commit, resetState(), and stopMediaCapture(Display|EveryKind). If a legitimate non-display or already-ended capture session left it set, for example a page-initiated track stop with no UI-side stopMediaCapture, forged mediaState bits could again steer activation during that window. The ceiling remains logic-level: activating the capability without a prompt and suppressing its revocation. The forged-IPC ASSERT was a debug-only crash, not a primitive.

Before the fix, the UI-process privilege boundary for display capture was weakened. The security model assumes the display-capture process capability is activated only after the UI process has prompted for, or recorded, a getDisplayMedia() grant. A renderer able to forge IPC broke that assumption with its own IsPlayingMediaDidChange report, and could also block revocation. Exploited after a renderer compromise, this would give the attacker an OS-level capability the UI process normally withholds until consent. Per the commit message, the grant reaches the WebContent and GPU processes; what remains open is whether holding the screenCapture capability lets those processes capture display contents directly, or whether capture is still brokered by UI-process code with its own permission checks.

Insight: The fix gates the privileged action at its point of use, keyed on UI-owned state, rather than adding a MESSAGE_CHECK on the incoming bits. Legitimate bits can arrive after the UI process has reset access or navigated, so validating the message would kill benign processes. Whenever renderer-reported state is inherently racy with UI-side state changes, gating the privilege is fail-safe, while validating the message is brittle. The fix is also symmetric across activation and deactivation, because forged state can serve either to acquire a grant or to keep one from being revoked. The authorization flag is somewhat coarse, though: the [[fallthrough]] means it records something broader than "the user approved getDisplayMedia()". More broadly, every WebPageProxy consumer that turns mediaState into a privilege, rather than a display affordance, is a candidate for the same bug.