forked from github/cordova-android
CB-3854: Added support for wildcard. This probably could be improved, but it does work
This commit is contained in:
parent
3ace9348f6
commit
f1b377bf07
@ -203,6 +203,20 @@ public class Config {
|
|||||||
self._addWhiteListEntry(origin, subdomains);
|
self._addWhiteListEntry(origin, subdomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Trying to figure out how to match * is a pain
|
||||||
|
* So, we don't use a regex here
|
||||||
|
*/
|
||||||
|
|
||||||
|
private boolean originHasWildcard(String origin){
|
||||||
|
//First, check for a protocol, then split it if it has one.
|
||||||
|
if(origin.contains("//"))
|
||||||
|
{
|
||||||
|
origin = origin.split("//")[1];
|
||||||
|
}
|
||||||
|
origin.matches("\\*\\.[a-z]+\\.[a-z]+");
|
||||||
|
return origin.startsWith("*");
|
||||||
|
}
|
||||||
|
|
||||||
private void _addWhiteListEntry(String origin, boolean subdomains) {
|
private void _addWhiteListEntry(String origin, boolean subdomains) {
|
||||||
try {
|
try {
|
||||||
@ -210,8 +224,16 @@ public class Config {
|
|||||||
if (origin.compareTo("*") == 0) {
|
if (origin.compareTo("*") == 0) {
|
||||||
LOG.d(TAG, "Unlimited access to network resources");
|
LOG.d(TAG, "Unlimited access to network resources");
|
||||||
this.whiteList.add(Pattern.compile(".*"));
|
this.whiteList.add(Pattern.compile(".*"));
|
||||||
} else { // specific access
|
}
|
||||||
|
else { // specific access
|
||||||
// check if subdomains should be included
|
// check if subdomains should be included
|
||||||
|
if(originHasWildcard(origin))
|
||||||
|
{
|
||||||
|
subdomains = true;
|
||||||
|
//Remove the wildcard so this works properly
|
||||||
|
origin = origin.replace("*.", "");
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: we should not add more domains if * has already been added
|
// TODO: we should not add more domains if * has already been added
|
||||||
Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
|
Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
|
||||||
Matcher matcher = schemeRegex.matcher(origin);
|
Matcher matcher = schemeRegex.matcher(origin);
|
||||||
@ -250,6 +272,7 @@ public class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if URL is in approved list of URLs to load.
|
* Determine if URL is in approved list of URLs to load.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user