From 89e42a245d265ff212b4aa0743635b5c8c965fb3 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 26 Nov 2022 08:40:32 +0100 Subject: [PATCH] Link sanitize: try base64 last path segment --- .../java/eu/faircode/email/UriHelper.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/UriHelper.java b/app/src/main/java/eu/faircode/email/UriHelper.java index 266a0d5f12..e8c7b98eaf 100644 --- a/app/src/main/java/eu/faircode/email/UriHelper.java +++ b/app/src/main/java/eu/faircode/email/UriHelper.java @@ -330,18 +330,6 @@ public class UriHelper { Uri result = (s > 0 ? Uri.parse(path.substring(s + 1)) : null); changed = (result != null); url = (result == null ? uri : result); - } else if ("go.dhlparcel.nl".equals(uri.getHost())) { - try { - String path = uri.getPath(); - int s = path.lastIndexOf('/'); - String b = (s > 0 ? new String(Base64.decode(path.substring(s + 1), Base64.URL_SAFE)) : null); - Uri result = (b == null ? null : Uri.parse(b)); - changed = (result != null); - url = (result == null ? uri : result); - } catch (Throwable ex) { - Log.i(ex); - url = uri; - } } else if (uri.getQueryParameterNames().size() == 1) { // Sophos Email Appliance Uri result = null; @@ -372,8 +360,21 @@ public class UriHelper { Log.i(ex); url = uri; } - } else - url = uri; + } else { + // Try base64 last path segment + // go.dhlparcel.nl and others + try { + String path = uri.getPath(); + int s = path.lastIndexOf('/'); + String b = (s > 0 ? new String(Base64.decode(path.substring(s + 1), Base64.URL_SAFE)) : null); + Uri result = (b == null ? null : Uri.parse(b)); + changed = (result != null && result.getScheme() != null); + url = (result == null ? uri : result); + } catch (Throwable ex) { + Log.i(ex); + url = uri; + } + } if (url.isOpaque() || !isHyperLink(url)) return uri;