oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
139 stars 118 forks source link

Can't use fileurl with sandbox ressource #26

Closed frankois944 closed 6 years ago

frankois944 commented 6 years ago

Hello, This plugin can't get file inside the sandbox but inside the bundle yes

I saw inside the CDVWKWebViewFileXhr.m, you check if the file want to go to the bundle with the method isWebContentResourceSecure. So why not check if we want to go to the sandbox?

Like to add this method in CDVWKWebViewFileXhr.m :

- (BOOL)isSandBoxResource: (NSURL*) targetURL
{
    NSURL *baseURL = [NSURL fileURLWithPath:NSHomeDirectory()];
    NSString *basePath = [baseURL absoluteString];
    NSString *targetPath = [[targetURL standardizedURL] absoluteString];
    return ([targetPath hasPrefix:basePath]);
}

and add this condition inside readAsText line 178:

    if (![self isWebContentResourceSecure:targetURL] && ![self isSandBoxResource:targetURL]) 

Thanks

gvanmat commented 6 years ago

@frankois944 The plugin is specifically checking that the target file is within the "www" folder of the application bundle. This is where the index.html file is served from defining the document root. The cordova file plugin should be used for reading files outside the www folder of the applications bundle.