From 6e053579cf5e66ca2b1e84aea5d80ba5cbbe60bb Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Wed, 13 Mar 2019 11:13:28 -0700 Subject: [PATCH 1/2] Null check for missing pathname This is causing a crash if someone whitelists just a protocol, ex `file://` See #539 --- bin/templates/scripts/cordova/lib/prepare.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index f81085f82..278af0a8b 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -1052,7 +1052,9 @@ function parseWhitelistUrlForATS (url, options) { var subdomain1 = '/*.'; // wildcard in hostname var subdomain2 = '*://*.'; // wildcard in hostname and protocol var subdomain3 = '*://'; // wildcard in protocol only - if (href.pathname.indexOf(subdomain1) === 0) { + if(!href.pathname) { + return null; + } else if (href.pathname.indexOf(subdomain1) === 0) { retObj.NSIncludesSubdomains = true; retObj.Hostname = href.pathname.substring(subdomain1.length); } else if (href.pathname.indexOf(subdomain2) === 0) { From 5f003f909fe28bebbedd064405f0c81364fe7912 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Wed, 13 Mar 2019 11:21:40 -0700 Subject: [PATCH 2/2] whitespace I love how a little whitespace can bring the whole universe crashing to a halt. --- bin/templates/scripts/cordova/lib/prepare.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 278af0a8b..a15380ed6 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -1052,8 +1052,8 @@ function parseWhitelistUrlForATS (url, options) { var subdomain1 = '/*.'; // wildcard in hostname var subdomain2 = '*://*.'; // wildcard in hostname and protocol var subdomain3 = '*://'; // wildcard in protocol only - if(!href.pathname) { - return null; + if (!href.pathname) { + return null; } else if (href.pathname.indexOf(subdomain1) === 0) { retObj.NSIncludesSubdomains = true; retObj.Hostname = href.pathname.substring(subdomain1.length);