Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

[[ Bug 22816 ]] Fix permissions when loading a local html file #7407

Open
wants to merge 1 commit into
base: develop-9.6
Choose a base branch
from

Conversation

livecodepanos
Copy link
Contributor

This patch uses the loadFileURL:allowingReadAccessToURL: instance method of the WKWebView class to load a local html file.

This fixes an issue with insufficient permissions on iOS 12 devices that prevented the html file from being loaded.

Tested on iOS 12,13 and 14 devices.

@livecodepanos livecodepanos added this to the 9.6.1-rc-1 milestone Jul 23, 2020
@@ -1618,7 +1618,10 @@ - (void) loadRequest:(MCWKWebViewLoadRequest *)request inWebView:(WKWebView *)we
MCBrowserRunBlockOnMainFiber(^{
if (request.htmlText == nil)
{
[webView loadRequest:[NSURLRequest requestWithURL:request.url]];
if (request.url.host)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@livecodepanos any reason not to use if (![request.url isFileURL])

@runrevmark
Copy link
Contributor

Marking this as WIP as it isn't general enough - the 'allow access to' path needs to be the top-most folder to which file urls in the target url can refer. e.g. If a file foo/bar/baz.html refers to foo/rab.html, then the 'allow access' folder needs to be foo/ and not foo/bar as would be the case here.

This patch uses the `loadFileURL:allowingReadAccessToURL:` instance
method of the WKWebView class to load a local html file. This fixes
an issue with insufficient permissions on iOS 12 devices that prevented
the html file from being loaded.
@livecodepanos
Copy link
Contributor Author

@runrevmark I have updated the PR, by granting read access to the full Documents folder, if the html resource is placed in the Documents folder.

@livecodepanos livecodepanos removed the WIP label Jul 29, 2020
@livecodepanos livecodepanos modified the milestones: 9.6.1-rc-1, 9.6.2-rc-1 Aug 20, 2020
Copy link
Contributor

@runrevmark runrevmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we've had a report that this issue also affects iOS13, and presumably iOS14 (it would be good if we can verify this though).

This approach (setting the root folder to Documents if the target HTML file is in documents) would probably be reasonable if it were needed due to a quirk in an older iOS version on specific devices (which we originally thought), however it definitely isn't reasonable if it affects newer iOS versions too.

Imagine an app which downloads HTML to display and the user to inspect in a browser widget. At the moment the file can be downloaded to Documents and it will not be allowed to load any other html pages nor have access to anything else. With this patch, such an HTML file will have some level of access to the whole documents folder.

Basically we need to add a browser property which allows the 'root folder' of the local files loaded into the widget to be set in script - then it is up to the developer to ensure that they don't introduce a security issue.

@livecodepanos livecodepanos removed this from the 9.6.2-rc-1 milestone Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants