Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file:// in allow-navigation crashes on iOS #539

Closed
3 tasks done
ankon opened this issue Feb 19, 2019 · 1 comment
Closed
3 tasks done

file:// in allow-navigation crashes on iOS #539

ankon opened this issue Feb 19, 2019 · 1 comment

Comments

@ankon
Copy link

ankon commented Feb 19, 2019

Bug Report

Problem

Using <allow-navigation href="file://"></allow-navigation> crashes parseWhitelistUrlForATS on iOS.

TypeError: Cannot read property 'indexOf' of null
    at parseWhitelistUrlForATS (.../.cordova/platforms/ios/cordova/lib/prepare.js:1056:27)
    at .../.cordova/platforms/ios/cordova/lib/prepare.js:982:23
    at Array.reduce (<anonymous>)
    at processAccessAndAllowNavigationEntries (.../.cordova/platforms/ios/cordova/lib/prepare.js:973:10)
    at writeATSEntries (.../.cordova/platforms/ios/cordova/lib/prepare.js:1099:16)
    at updateProject (.../.cordova/platforms/ios/cordova/lib/prepare.js:215:15)
    at .../.cordova/platforms/ios/cordova/lib/prepare.js:59:20
    at _fulfilled (.../.cordova/node_modules/q/q.js:854:54)
    at .../.cordova/node_modules/q/q.js:883:30
    at Promise.promise.promiseDispatch (.../.cordova/node_modules/q/q.js:816:13)"

What is expected to happen?

"Nothing", as the setting is the default.

What does actually happen?

An error that indexOf isn't a function on undefined :)

Information

if (!retObj.Hostname) {
// check origin, if it allows subdomains (wildcard in hostname), we set NSIncludesSubdomains to YES. Default is NO
var subdomain1 = '/*.'; // wildcard in hostname
var subdomain2 = '*://*.'; // wildcard in hostname and protocol
var subdomain3 = '*://'; // wildcard in protocol only
if (href.pathname.indexOf(subdomain1) === 0) {
retObj.NSIncludesSubdomains = true;
retObj.Hostname = href.pathname.substring(subdomain1.length);
} else if (href.pathname.indexOf(subdomain2) === 0) {
retObj.NSIncludesSubdomains = true;
retObj.Hostname = href.pathname.substring(subdomain2.length);
} else if (href.pathname.indexOf(subdomain3) === 0) {
retObj.Hostname = href.pathname.substring(subdomain3.length);
} else {
// Handling "scheme:*" case to avoid creating of a blank key in NSExceptionDomains.
return null;
}
}

As per the documentation the value file:// is the default (https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/), but when using that value !retObject.HostName is true-ish, but there is no href.pathname.

Version information

cordova-ios 5.0.0.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
purplecabbage added a commit that referenced this issue Mar 13, 2019
This is causing a crash if someone whitelists just a protocol, ex `file://`
See #539
@purplecabbage
Copy link
Contributor

I have added a potential fix for the crash. In the mean time, there is no benefit to adding 'file://' to your whitelist since it is already allowed. If you feel you must, then please use 'file://*'

@dpogue dpogue added this to the 5.0.1 milestone Mar 15, 2019
dpogue pushed a commit that referenced this issue Mar 15, 2019
This is causing a crash if someone whitelists just a protocol, ex `file://`
See #539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants