aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-12-16 22:23:57 +0100
committerChristian Schneppe <christian@pix-art.de>2017-12-16 22:23:57 +0100
commit04e21792f075dff7c7e45bf2cf6374c383a57df1 (patch)
tree7200edc7a74bca7b0a56726b6d171d3c702868d8
parent0f415f6791270500f0f82224c1bdb5b6a6a5bf01 (diff)
ignore data uri after aesgcm uri
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java18
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java2
2 files changed, 13 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 8a59b4cf4..3277952bb 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -728,16 +728,22 @@ public class Message extends AbstractEntity {
public synchronized boolean treatAsDownloadable() {
if (treatAsDownloadable == null) {
- if (body.trim().contains(" ")) {
- treatAsDownloadable = false;
- }
try {
- final URL url = new URL(body);
+ final String[] lines = body.split("\n");
+ for (String line : lines) {
+ if (line.contains("\\s+")) {
+ treatAsDownloadable = false;
+ return treatAsDownloadable;
+ }
+ }
+ final URL url = new URL(lines[0]);
final String ref = url.getRef();
final String protocol = url.getProtocol();
final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches();
- treatAsDownloadable = (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted)
- || (("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted));
+ final boolean followedByDataUri = lines.length == 2 && lines[1].startsWith("data:");
+ final boolean validAesGcm = AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted && (lines.length == 1 || followedByDataUri);
+ final boolean validOob = ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted) && lines.length == 1;
+ treatAsDownloadable = validAesGcm || validOob;
} catch (MalformedURLException e) {
treatAsDownloadable = false;
}
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index 9f49ac218..d8fdfb79e 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -77,7 +77,7 @@ public class HttpDownloadConnection implements Transferable {
if (message.hasFileOnRemoteHost()) {
mUrl = CryptoHelper.toHttpsUrl(message.getFileParams().url);
} else {
- mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody()));
+ mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody().split("\n")[0]));
}
String[] parts = mUrl.getPath().toLowerCase().split("\\.");
String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;