From fe68aff23cf56554f564f02505d63492086ef68d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 18 Jun 2020 10:15:51 +0200 Subject: [PATCH] validate install referrer beforing accepting it as xmpp uri --- .../conversations/ui/WelcomeActivity.java | 47 ++++++++++--------- .../utils/InstallReferrerUtils.java | 9 +++- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java index d2b2e58a1..142bda09a 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; +import android.net.Uri; import android.os.Bundle; import android.security.KeyChain; import android.security.KeyChainAliasCallback; @@ -46,35 +47,37 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi activity.overridePendingTransition(0, 0); } - public void onInstallReferrerDiscovered(final String referrer) { + public void onInstallReferrerDiscovered(final Uri referrer) { Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer); - if (referrer != null) { + if ("xmpp".equalsIgnoreCase(referrer.getScheme())) { final XmppUri xmppUri = new XmppUri(referrer); runOnUiThread(() -> processXmppUri(xmppUri)); + } else { + Log.i(Config.LOGTAG, "install referrer was not an XMPP uri"); } } - private boolean processXmppUri(final XmppUri xmppUri) { - if (xmppUri.isValidJid()) { - final String preauth = xmppUri.getParameter("preauth"); - final Jid jid = xmppUri.getJid(); - final Intent intent; - if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) { - intent = SignupUtils.getTokenRegistrationIntent(this, jid, preauth); - } else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) { - intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth); - intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString()); - } else { - intent = null; - } - if (intent != null) { - startActivity(intent); - finish(); - return true; - } - this.inviteUri = xmppUri; + private void processXmppUri(final XmppUri xmppUri) { + if (!xmppUri.isValidJid()) { + return; } - return false; + final String preAuth = xmppUri.getParameter("preauth"); + final Jid jid = xmppUri.getJid(); + final Intent intent; + if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) { + intent = SignupUtils.getTokenRegistrationIntent(this, jid, preAuth); + } else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) { + intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth); + intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString()); + } else { + intent = null; + } + if (intent != null) { + startActivity(intent); + finish(); + return; + } + this.inviteUri = xmppUri; } @Override diff --git a/src/conversationsPlaystore/java/eu/siacs/conversations/utils/InstallReferrerUtils.java b/src/conversationsPlaystore/java/eu/siacs/conversations/utils/InstallReferrerUtils.java index aac9b9f4a..360011bea 100644 --- a/src/conversationsPlaystore/java/eu/siacs/conversations/utils/InstallReferrerUtils.java +++ b/src/conversationsPlaystore/java/eu/siacs/conversations/utils/InstallReferrerUtils.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.utils; import android.app.Activity; import android.content.SharedPreferences; +import android.net.Uri; import android.os.RemoteException; import android.preference.PreferenceManager; import android.util.Log; @@ -9,6 +10,7 @@ import android.util.Log; import com.android.installreferrer.api.InstallReferrerClient; import com.android.installreferrer.api.InstallReferrerStateListener; import com.android.installreferrer.api.ReferrerDetails; +import com.google.common.base.Strings; import eu.siacs.conversations.Config; import eu.siacs.conversations.ui.WelcomeActivity; @@ -49,8 +51,11 @@ public class InstallReferrerUtils implements InstallReferrerStateListener { try { final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer(); final String referrer = referrerDetails.getInstallReferrer(); - welcomeActivity.onInstallReferrerDiscovered(referrer); - } catch (final RemoteException e) { + if (Strings.isNullOrEmpty(referrer)) { + return; + } + welcomeActivity.onInstallReferrerDiscovered(Uri.parse(referrer)); + } catch (final RemoteException | IllegalArgumentException e) { Log.d(Config.LOGTAG, "unable to get install referrer", e); } } else {