← All reports

`WKTextEffectManager` effect-ID bookkeeping hardening

Component: WebKit UIProcess | dea315c

Source/WebKit/UIProcess/Cocoa/WKTextEffectManager.mm

- (void)forgetEffectForID:(NSUUID *)uuid
{
- if (RetainPtr context = [_effectIDToContext objectForKey:uuid])
+ RetainPtr protectedUUID = uuid;
+ if (RetainPtr context = [_effectIDToContext objectForKey:protectedUUID])
[_contextIDToEffectID removeObjectForKey:[context identifier]];
- [_effectIDToAnimationID removeObjectForKey:uuid];
- [_effectIDToContext removeObjectForKey:uuid];
+ [_effectIDToAnimationID removeObjectForKey:protectedUUID];
+ [_effectIDToContext removeObjectForKey:protectedUUID];
}

Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

MESSAGE_CHECK(uuid.isValid(), connection);
+ MESSAGE_CHECK(!internals().textIndicatorForAnimationID.contains(uuid), connection);

WKTextEffectManager is a Cocoa UI-process helper for Writing Tools text effects and animations. It keeps three parallel dictionaries: effect ID → animation ID, effect ID → Writing Tools context, and context identifier → effect ID. WebContent drives it through WebPageProxy messages such as AddTextEffectForID and RemoveTextEffectForID, so the effect UUID is attacker-influenced under the compromised-renderer model. The dictionaries hold their keys, and copying an immutable NSUUID is effectively a retain. Removing an entry can therefore drop the last strong reference to an NSUUID that the caller still holds unretained.

-forgetEffectForID: now holds a RetainPtr to the UUID across all three removals. The lookup callers previewForContext, prepareForTextAnimation and finishTextAnimation retain the effect ID they fetch. WebPageProxy::addTextEffectForID now rejects a second AddTextEffectForID for an already-registered ID with a MESSAGE_CHECK. A new IPC test sends the message twice and then removes the effect.

Duplicate registration, and removing the last dictionary reference to a key still in use, were both reachable by a compromised renderer through UI-process IPC. The commit's crash-only test does not demonstrate a concrete primitive, so the lifetime impact is inferred.

The general shape is an Objective-C key object passed unretained into a method that removes it from collections that may hold its last reference. Trace where RemoveTextEffectForID and other callers obtain the UUID, and whether it can alias a stored key.

Duplicate registration is the second thread to pull. The indicator maps use HashMap::add, which keeps the original value. Read the rest of addTextEffectForID and the manager's registration path to see whether a duplicate could leave the indicator maps, _contextIDToEffectID and the manager's own maps inconsistent with each other.

Beyond the three lookup callers this commit fixed, look for other places that hold an effect ID, animation ID or context across a call that can re-enter the manager or process more IPC, such as completion handlers and async blocks. The test relies on in-order handling, so try other sequences of add, remove and animation messages with colliding or interleaved UUIDs, and the same ID across different animation types.