|
9 | 9 | import androidx.annotation.Nullable; |
10 | 10 | import com.getcapacitor.util.JSONUtils; |
11 | 11 | import java.io.IOException; |
| 12 | +import java.util.Arrays; |
12 | 13 | import java.util.HashMap; |
13 | 14 | import java.util.Iterator; |
| 15 | +import java.util.List; |
14 | 16 | import java.util.Locale; |
15 | 17 | import java.util.Map; |
16 | 18 | import org.json.JSONException; |
@@ -105,7 +107,11 @@ private CapConfig(Builder builder) { |
105 | 107 | this.html5mode = builder.html5mode; |
106 | 108 | this.serverUrl = builder.serverUrl; |
107 | 109 | this.hostname = builder.hostname; |
108 | | - this.androidScheme = builder.androidScheme; |
| 110 | + |
| 111 | + if (this.validateScheme(builder.androidScheme)) { |
| 112 | + this.androidScheme = builder.androidScheme; |
| 113 | + } |
| 114 | + |
109 | 115 | this.allowNavigation = builder.allowNavigation; |
110 | 116 |
|
111 | 117 | // Android Config |
@@ -148,7 +154,12 @@ private void deserializeConfig(@Nullable Context context) { |
148 | 154 | html5mode = JSONUtils.getBoolean(configJSON, "server.html5mode", html5mode); |
149 | 155 | serverUrl = JSONUtils.getString(configJSON, "server.url", null); |
150 | 156 | hostname = JSONUtils.getString(configJSON, "server.hostname", hostname); |
151 | | - androidScheme = JSONUtils.getString(configJSON, "server.androidScheme", androidScheme); |
| 157 | + |
| 158 | + String configSchema = JSONUtils.getString(configJSON, "server.androidScheme", androidScheme); |
| 159 | + if (this.validateScheme(configSchema)) { |
| 160 | + androidScheme = configSchema; |
| 161 | + } |
| 162 | + |
152 | 163 | allowNavigation = JSONUtils.getArray(configJSON, "server.allowNavigation", null); |
153 | 164 |
|
154 | 165 | // Android |
@@ -191,6 +202,16 @@ private void deserializeConfig(@Nullable Context context) { |
191 | 202 | pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins")); |
192 | 203 | } |
193 | 204 |
|
| 205 | + private boolean validateScheme(String scheme) { |
| 206 | + List<String> invalidSchemes = Arrays.asList("file", "ftp", "ftps", "ws", "wss", "about", "blob", "data"); |
| 207 | + if (invalidSchemes.contains(scheme)) { |
| 208 | + Logger.warn(scheme + " is not an allowed scheme. Defaulting to http."); |
| 209 | + return false; |
| 210 | + } |
| 211 | + |
| 212 | + return true; |
| 213 | + } |
| 214 | + |
194 | 215 | public boolean isHTML5Mode() { |
195 | 216 | return html5mode; |
196 | 217 | } |
|
0 commit comments