Skip to content

Commit 486262b

Browse files
authored
Add the possibility to disallow subdomains
1 parent 221256a commit 486262b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Source/library/src/main/java/im/delight/android/webview/AdvancedWebView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,12 @@ protected static String makeUrlUnique(final String url) {
11061106

11071107
return unique.toString();
11081108
}
1109-
1109+
11101110
public boolean isPermittedUrl(final String url) {
1111+
isPermittedUrl(url, true)
1112+
}
1113+
1114+
public boolean isPermittedUrl(final String url, boolean allowSubdomains) {
11111115
// if the permitted hostnames have not been restricted to a specific set
11121116
if (mPermittedHostnames.size() == 0) {
11131117
// all hostnames are allowed
@@ -1142,7 +1146,7 @@ public boolean isPermittedUrl(final String url) {
11421146
// for every hostname in the set of permitted hosts
11431147
for (String expectedHost : mPermittedHostnames) {
11441148
// if the two hostnames match or if the actual host is a subdomain of the expected host
1145-
if (actualHost.equals(expectedHost) || actualHost.endsWith("." + expectedHost)) {
1149+
if (actualHost.equals(expectedHost) || (allowSubdomains && actualHost.endsWith("." + expectedHost))) {
11461150
// the actual hostname of the URL to be checked is allowed
11471151
return true;
11481152
}

0 commit comments

Comments
 (0)