Skip to content

Commit 7a67e00

Browse files
authored
fix(PluginManager): AllowBridgeAccess default policy to handle scheme & hostname (#1332)
1 parent dc4e065 commit 7a67e00

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

framework/src/org/apache/cordova/AllowListPlugin.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ public void handleStartTag(XmlPullParser xml) {
8282
if (strNode.equals("content")) {
8383
String startPage = xml.getAttributeValue(null, "src");
8484
allowedNavigations.addAllowListEntry(startPage, false);
85-
86-
// Allow origin for WebViewAssetLoader
87-
if (!this.prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) {
88-
allowedNavigations.addAllowListEntry("https://" + this.prefs.getString("hostname", "localhost"), false);
89-
}
9085
} else if (strNode.equals("allow-navigation")) {
9186
String origin = xml.getAttributeValue(null, "href");
9287
if ("*".equals(origin)) {

framework/src/org/apache/cordova/PluginManager.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ Licensed to the Apache Software Foundation (ASF) under one
4141
*/
4242
public class PluginManager {
4343
private static String TAG = "PluginManager";
44+
45+
// @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants
46+
private static String SCHEME_HTTPS = "https";
47+
// @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants
48+
private static String DEFAULT_HOSTNAME = "localhost";
49+
4450
private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ? 60 : 16;
4551

4652
// List of service entries
@@ -366,6 +372,24 @@ public void onNewIntent(Intent intent) {
366372
}
367373
}
368374

375+
/**
376+
* @todo should we move this somewhere public and accessible by all plugins?
377+
* For now, it is placed where it is used and kept private so we can decide later and move without causing a breaking change.
378+
* An ideal location might be in the "ConfigXmlParser" at the time it generates the "launchUrl".
379+
*
380+
* @todo should we be restrictive on the "file://" return? e.g. "file:///android_asset/www/"
381+
* Would be considered as a breaking change if we apply a more granular check.
382+
*/
383+
private String getLaunchUrlPrefix() {
384+
if (!app.getPreferences().getBoolean("AndroidInsecureFileModeEnabled", false)) {
385+
String scheme = app.getPreferences().getString("scheme", SCHEME_HTTPS).toLowerCase();
386+
String hostname = app.getPreferences().getString("hostname", DEFAULT_HOSTNAME);
387+
return scheme + "://" + hostname + '/';
388+
}
389+
390+
return "file://";
391+
}
392+
369393
/**
370394
* Called when the webview is going to request an external resource.
371395
*
@@ -452,7 +476,7 @@ public boolean shouldAllowBridgeAccess(String url) {
452476
}
453477

454478
// Default policy:
455-
return url.startsWith("file://");
479+
return url.startsWith(getLaunchUrlPrefix());
456480
}
457481

458482
/**

0 commit comments

Comments
 (0)