In an app extension, ExtensionPreProcessing.js does not have access to framed content from hosts other than that serving the top page.

Originator:johnbrayton
Number:rdar://30595706 Date Originated:2017-02-19
Status:Open Resolved:
Product:Mobile Safari Product Version:Mobile Safari on iOS 10.2.1 (14D27)
Classification:Other Bug Reproducible:Always
 
An iOS share extension can include an "ExtensionPreProcessing.js" file. It is able to interpret contents of the web page for use by the extension when invoked from Mobile Safari.

Let's say you have a web page at "http://foo.com/" and that this web page has a frame with a URL of "http://bar.com/". If the extension preprocessing script attempts to access contents of both the top web page and the frame, it will be unable to access the contents of the frame. This is the error that will appear in the Web Inspector Console:

Blocked a frame with origin "http://foo.com" from accessing a frame with origin "http://bar.com". Protocols, domains, and ports must match.

I imagine that this is a side effect of the restriction that a web page cannot access contents of its frames if they are served from a different host. I appreciate the reasoning behind that restriction, but I do not believe it should apply to scripts embedded in an app extension.

I included a sample app that demonstrates the problem.


Steps to Reproduce:

1.  Run the "ShareExtension" target of the attached project in Mobile Safari.

2.  In Mobile Safari, visit this URL:
    http://jb💩.tk
    
    Note that this page has a frame with a URL of:
    http://jbframed.blogspot.com
    
3.  Open Web Inspector from the Mac and navigate to the Console.

4.  Invoke the extension from within the share sheet.


Expected Results:

I would expect the script to return the following to the Swift code:

    NSExtensionJavaScriptPreprocessingResultsKey =     {
        docUrl = "http://xn--jb-9t72a.tk/";
        title = "xn--jb-9t72a.tk";
        frame = {
            docUrl = "http://jbframed.blogspot.com/";
            title = "framed blog";
        };
    };

I would then expect the Swift code to print that to the console.


Actual Results:

The app logs the following:

inputObj: {
    NSExtensionJavaScriptPreprocessingResultsKey =     {
        docUrl = "http://xn--jb-9t72a.tk/";
        title = "xn--jb-9t72a.tk";
    };
}

This error appears in the Console of Web Inspector:

Blocked a frame with origin "http://xn--jb-9t72a.tk" from accessing a frame with origin "http://jbframed.blogspot.com". Protocols, domains, and ports must match.


Configuration:  

iPhone 5S being invoked by Xcode 8.2.1 (8C1002)

Version & Build:  

Mobile Safari on iOS 10.2.1 (14D27)

Additional Notes:

This issue makes it more complicated for my app, Feed Hawk (https://www.goldenhillsoftware.com/feed-hawk/), to get RSS feed information when domain forwarding (using frames) is used to assign a domain name to a blog. My workaround is for the app to retrieve the framed page independently.

===

My sample project is at:
https://www.virtualsanity.com/radars/radar30595706.zip

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!