allow any path in incoming add repo Intent, filters check the paths

If anything wants to craft an Intent to send directly to F-Droid with an
arbitrary but valid path, that seems like a fine thing to support.  The
IntentFilters will still only match on the well known paths, so that the
user doesn't see F-Droid claiming all HTTP URLs.
This commit is contained in:
Hans-Christoph Steiner 2018-03-28 23:56:19 +02:00
parent dd48103516
commit b3d90cd1b6

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.localrepo.peers.WifiPeer; import org.fdroid.fdroid.localrepo.peers.WifiPeer;
@ -82,17 +81,12 @@ public class NewRepoConfig {
scheme = scheme.toLowerCase(Locale.ENGLISH); scheme = scheme.toLowerCase(Locale.ENGLISH);
host = host.toLowerCase(Locale.ENGLISH); host = host.toLowerCase(Locale.ENGLISH);
// We only listen for /fdroid/archive or /fdroid/repo paths when receiving a HTTP(S) intent. if (uri.getPath() == null
// For fdroidrepo(s) intents, we are less picky and will accept any path. || !Arrays.asList("https", "http", "fdroidrepos", "fdroidrepo").contains(scheme)) {
boolean isHttpScheme = TextUtils.equals("http", scheme) || TextUtils.equals("https", scheme);
String path = uri.getPath();
if (path == null || isHttpScheme && !(path.contains("/fdroid/archive") || path.contains("/fdroid/repo"))) {
isValidRepo = false; isValidRepo = false;
return; return;
} }
boolean isFdroidScheme = TextUtils.equals("fdroidrepo", scheme) || TextUtils.equals("fdroidrepos", scheme);
String userInfo = uri.getUserInfo(); String userInfo = uri.getUserInfo();
if (userInfo != null) { if (userInfo != null) {
String[] userInfoTokens = userInfo.split(":"); String[] userInfoTokens = userInfo.split(":");
@ -109,15 +103,8 @@ public class NewRepoConfig {
bssid = uri.getQueryParameter("bssid"); bssid = uri.getQueryParameter("bssid");
ssid = uri.getQueryParameter("ssid"); ssid = uri.getQueryParameter("ssid");
fromSwap = uri.getQueryParameter("swap") != null; fromSwap = uri.getQueryParameter("swap") != null;
if (!isFdroidScheme && !isHttpScheme) {
isValidRepo = false;
return;
}
uriString = sanitizeRepoUri(uri); uriString = sanitizeRepoUri(uri);
isValidRepo = true; isValidRepo = true;
} }
public String getBssid() { public String getBssid() {
@ -175,7 +162,9 @@ public class NewRepoConfig {
return errorMessage; return errorMessage;
} }
/** Sanitize and format an incoming repo URI for function and readability */ /**
* Sanitize and format an incoming repo URI for function and readability
*/
public static String sanitizeRepoUri(Uri uri) { public static String sanitizeRepoUri(Uri uri) {
String scheme = uri.getScheme(); String scheme = uri.getScheme();
String host = uri.getHost(); String host = uri.getHost();