NSItemProvider throwing exception related to secure coding

Our app has a share extension. And we recently noticed something with iOS 17.3.1.

From Safari, when we receive the plist and try to load it, we are seeing exceptions for classes not allowed to be unarchived.

[itemProvider loadItemForTypeIdentifier:[UTTypePropertyList identifier] options:nil completionHandler:^(NSDictionary *jsDict, NSError *error) {
}

We see these exceptions:

value for key 'NS.keys' was of unexpected class 'NSString' (0x1ee7d2970) [/System/Library/Frameworks/Foundation.framework].
Allowed classes are:
 {(
    "'NSDictionary' (0x1ee7cad38) [/System/Library/Frameworks/CoreFoundation.framework]"
)}
(null)

Our preprocessing javascript file is basic, and only passes a title and URL as part of the payload.

arguments.completionFunction({
    "URL": document.URL
    "title": document.title,
});
value for key 'NS.keys' was of unexpected class 'NSString' (0x1ee7d2970) [/System/Library/Frameworks/Foundation.framework].
Allowed classes are:
 {(
    "'NSDictionary' (0x1ee7cad38) [/System/Library/Frameworks/CoreFoundation.framework]"
)}
(null)
Printing description of exception->exception:
Exception while decoding argument 0 (#1 of invocation):
<NSInvocation: 0x28224e600>
return value: {v} void
target: {@?} 0x0 (block)
argument 1: {@} 0x0
argument 2: {@} 0x0
Exception: value for key 'NS.keys' was of unexpected class 'NSString' (0x1ee7d2970) [/System/Library/Frameworks/Foundation.framework].
Allowed classes are:
 {(
    "'NSDictionary' (0x1ee7cad38) [/System/Library/Frameworks/CoreFoundation.framework]"
)}
(
	0   CoreFoundation                      0x000000019d576684 5A6C1F41-BF70-32F6-A1D6-5B894DD21362 + 968324
	...
)

This is interesting as well. I had a fix that was working, but now all of the sudden it's not.

[itemProvider loadDataRepresentationForTypeIdentifier:[UTTypePropertyList identifier] completionHandler:^(NSData * _Nullable data, NSError * _Nullable error) {
    ///use NSKeyedUnarchver to unarchive a dictionary.
}

The dictionary is decoded, but the result is empty:

{
    NSExtensionJavaScriptPreprocessingResultsKey =     {
    };
}

If you set an exception breakpoint (using the plus button at the bottom left of the Breakpoints navigator), what does the backtrace look like?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have the same issue。

<NSXPCConnection: 0x2831280a0> connection to service with pid 1367 created from an endpoint: Exception caught during decoding of reply to message 'resolveWithIdentifier:className:options:reply:', dropping incoming message and calling failure block.

Ignored Exception: Exception while decoding argument 0 (#1 of invocation): <NSInvocation: 0x28153aec0> return value: {v} void target: {@?} 0x0 (block) argument 1: {@} 0x0 argument 2: {@} 0x0

Exception: value for key 'NS.objects' was of unexpected class 'NSString' (0x20286a970) [/System/Library/Frameworks/Foundation.framework]. Allowed classes are: {( "'NSDictionary' (0x202862d38) [/System/Library/Frameworks/CoreFoundation.framework]" )}

@eskimo Do you have any internal Apple connections to help investigate this?

qiuyg wrote:

I have the same issue.

Is it actually the same issue?

I realise it’s the same exception, but gngrwzrd was specifically talking about interacting with Safari, and the backtrace in your post has no evidence to confirm or deny that. Can you explain more about the context in which you’re seeing this failure?


Do you have any internal Apple connections to help investigate this?

Well, yes, that’s pretty much my day job here in DTS (-:

However, I was hoping to handle this here, so everyone can benefit. Were you able to run the test I suggested earlier?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo Thanks. Yes here is the stack trace. I had to take an image because the forum is not letting me include it - it's saying something is inappropriate :).

Also to add a bit more info - this only happens from the Safari share button that's built into the window chrome. And I attached an another screen - the red circle is where this exception is thrown from.

@eskimo There's also a second exception but this doesn't appear to be the source.

So, lemme see if I understand the sequence correctly:

  1. Use taps the share button and invokes your extension.

  2. Your extension calls -loadItemForTypeIdentifier:options:completionHandler:, as you showed in your first post, supplying a completion handler.

  3. Your process crashes with this exception before that completion handler is called.

Is that right?

And this happens with any website, not just the one you specifically mentioned?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo Correct. Any website. Not just the screenshot provided.

OK.

This worked in previous systems, right?

Your code snippet shows you requesting the UTTypePropertyList type (com.apple.property-list). Presumably that returned a dictionary of properties. What properties were you relying on?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo Yes it worked in previous systems. It seemed to be the release iOS 17.3.1. As I mentioned in my first post. When the share button is pressed, Apple / Safari runs a preprocessor.js file, which has a callback that gets encoded as a plist, and passed to the share extension. Ours sends only two keys:

arguments.completionFunction({
    "URL": document.URL
    "title": document.title,
});

So the plist (dictionary) only contains NSString type. Which is currently not allowed to be decoded based on the exception thrown.

Hmmm, tricky.

Does this reproduce on the 17.4rc?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo Yes in iOS 17.4 simulator it still happens.

@eskimo I put together a demo. I actually stumbled across the solution as I was putting this together. The issue is Objective-C VS Swift. My project is using Objectice-C to ask for a plist from NSItemProvider. When I use swift however, there's no problem. My demo has both so you can see it. Look at ViewController for instructions, and ShareViewController for objective-c VS swift. Also make sure to set an exception breakpoint for all objc exceptions.

How can I send you this demo, I can't upload zip files here.

NSItemProvider throwing exception related to secure coding
 
 
Q