aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-10-20 22:01:04 +0200
committerChristian Schneppe <christian@pix-art.de>2018-10-20 22:01:04 +0200
commitb6d64f1f4338c6c8e0c3ed91983da6aa16024fe0 (patch)
tree7ef465be27da6f892262a716b59c49b8d25e14d5 /src/main
parentb2d98cbd131ca4b926a27886b3c911a992a17d3f (diff)
Do not insert text shared over XMPP uri when already drafting message
XMPP uris in the style of `xmpp:test@domain.tld?body=Something` can be used to directly share a message with a specific contact. Previously the text was always appended to the message currently in draft. The message was never send automatically. Essentially those links where treated like normal text share intents (for example when sharing a URL from the browser) but without the contact selection. There is a concern (CVE-2018-18467) that when this URI is invoked automatically and the user is currently drafting a long message to that particular contact the text could be inserted in the draft field (input box) without the user noticing. To circumvent that the text shared over XMPP uris that contain a particular contact is now appended only if the draft box is currently empty. Sharing text normally (**with** manual contact selection) is still treated the same; meaning the shared text will be appended to the current draft. This is intended behaviour to make the 'Hey I have this cool link here;' *open browser*, *share link* - secenario work.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java13
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java19
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java17
-rw-r--r--src/main/res/values/strings.xml1
5 files changed, 36 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 295345855..f1df07e0b 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -32,6 +32,7 @@ import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuPopupHelper;
import android.support.v7.widget.PopupMenu;
import android.text.Editable;
+import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -2251,6 +2252,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final String nick = extras.getString(ConversationsActivity.EXTRA_NICK);
final boolean asQuote = extras.getBoolean(ConversationsActivity.EXTRA_AS_QUOTE);
final boolean pm = extras.getBoolean(ConversationsActivity.EXTRA_IS_PRIVATE_MESSAGE, false);
+ final boolean doNotAppend = extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false);
final List<Uri> uris = extractUris(extras);
if (uris != null && uris.size() > 0) {
final List<Uri> cleanedUris = cleanUris(new ArrayList<>(uris));
@@ -2277,7 +2279,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (text != null && asQuote) {
quoteText(text);
} else {
- appendText(text);
+ appendText(text, doNotAppend);
}
}
final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid);
@@ -2821,11 +2823,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
});
}
- public void appendText(String text) {
+ public void appendText(String text, final boolean doNotAppend) {
if (text == null) {
return;
}
- String previous = this.binding.textinput.getText().toString();
+ final Editable editable = this.binding.textinput.getText();
+ String previous = editable == null ? "" : editable.toString();
+ if (doNotAppend && !TextUtils.isEmpty(previous)) {
+ Toast.makeText(getActivity(), R.string.already_drafting_message, Toast.LENGTH_LONG).show();
+ return;
+ }
if (UIHelper.isLastLineQuote(previous)) {
text = '\n' + text;
} else if (previous.length() != 0 && !Character.isWhitespace(previous.charAt(previous.length() - 1))) {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
index 2d07be344..1f2c68159 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
@@ -108,6 +108,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
public static final String EXTRA_AS_QUOTE = "as_quote";
public static final String EXTRA_NICK = "nick";
public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
+ public static final String EXTRA_DO_NOT_APPEND = "do_not_append";
public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC";
public static final int REQUEST_OPEN_MESSAGE = 0x9876;
public static final int REQUEST_PLAY_PAUSE = 0x5432;
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index 7be62165b..5b337abb6 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -493,7 +493,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
contact.setServerName(invite.getName());
}
if (contact.isSelf()) {
- switchToConversation(contact, null);
+ switchToConversation(contact);
return true;
} else if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
@@ -502,7 +502,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
}
- switchToConversation(contact, invite == null ? null : invite.getBody());
+ switchToConversationDoNotAppend(contact, invite == null ? null : invite.getBody());
return true;
}
});
@@ -550,9 +550,14 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
return xmppConnectionService.findAccountByJid(jid);
}
- protected void switchToConversation(Contact contact, String body) {
+ protected void switchToConversation(Contact contact) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
- switchToConversation(conversation, body);
+ switchToConversation(conversation);
+ }
+
+ protected void switchToConversationDoNotAppend(Contact contact, String body) {
+ Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
+ switchToConversationDoNotAppend(conversation, body);
}
@Override
@@ -788,7 +793,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (invite.isAction(XmppUri.ACTION_JOIN)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) {
- switchToConversation(muc, invite.getBody());
+ switchToConversationDoNotAppend(muc, invite.getBody());
return true;
} else {
showJoinConferenceDialog(invite.getJid().asBareJid().toString());
@@ -810,7 +815,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (invite.account != null) {
xmppConnectionService.getShortcutService().report(contact);
}
- switchToConversation(contact, invite.getBody());
+ switchToConversationDoNotAppend(contact, invite.getBody());
}
return true;
} else {
@@ -838,7 +843,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (isTrustedSource.isChecked() && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
}
- switchToConversation(contact, invite.getBody());
+ switchToConversationDoNotAppend(contact, invite.getBody());
});
builder.setNegativeButton(R.string.cancel, (dialog, which) -> StartConversationActivity.this.finish());
AlertDialog dialog = builder.create();
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 929d1566b..dcf3afed4 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -451,22 +451,26 @@ public abstract class XmppActivity extends ActionBarActivity {
}
public void switchToConversationAndQuote(Conversation conversation, String text) {
- switchToConversation(conversation, text, true, null, false);
+ switchToConversation(conversation, text, true, null, false, false);
}
public void switchToConversation(Conversation conversation, String text) {
- switchToConversation(conversation, text, false, null, false);
+ switchToConversation(conversation, text, false, null, false, false);
+ }
+
+ public void switchToConversationDoNotAppend(Conversation conversation, String text) {
+ switchToConversation(conversation, text, false, null, false, true);
}
public void highlightInMuc(Conversation conversation, String nick) {
- switchToConversation(conversation, null, false, nick, false);
+ switchToConversation(conversation, null, false, nick, false, false);
}
public void privateMsgInMuc(Conversation conversation, String nick) {
- switchToConversation(conversation, null, false, nick, true);
+ switchToConversation(conversation, null, false, nick, true, false);
}
- private void switchToConversation(Conversation conversation, String text, boolean asQuote, String nick, boolean pm) {
+ private void switchToConversation(Conversation conversation, String text, boolean asQuote, String nick, boolean pm, boolean doNotAppend) {
Intent intent = new Intent(this, ConversationsActivity.class);
intent.setAction(ConversationsActivity.ACTION_VIEW_CONVERSATION);
intent.putExtra(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
@@ -480,6 +484,9 @@ public abstract class XmppActivity extends ActionBarActivity {
intent.putExtra(ConversationsActivity.EXTRA_NICK, nick);
intent.putExtra(ConversationsActivity.EXTRA_IS_PRIVATE_MESSAGE, pm);
}
+ if (doNotAppend) {
+ intent.putExtra(ConversationsActivity.EXTRA_DO_NOT_APPEND, true);
+ }
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 0016bb5d5..34c227331 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -834,5 +834,6 @@
<string name="delete_file_dialog_msg">Are you sure you want to delete this file?\n\n<b>Warning:</b> This will not delete copies of this file that are stored on other devices or servers. </string>
<string name="cancelled">cancelled</string>
<string name="remote_server_timeout">Remote server timeout</string>
+ <string name="already_drafting_message">You are already drafting a message.</string>
</resources>