From 276cc2502912dca9aed919c506bc8ada6eb1ad1d Mon Sep 17 00:00:00 2001 From: tacolopo Date: Wed, 28 Aug 2024 19:15:31 -0400 Subject: [PATCH] Add checks to prevent formatting hxxps 1) sanitizeUrl.ts: if the url starts with hxxps it will return the url 2) transformLinks.ts: checks to make sure the url does not start with hxxps 3) url.ts: if the input starts with hxxps it will return it I tried my best to dig through these files to solve this (https://protonmail.uservoice.com/forums/284483-proton-mail/suggestions/48747251-stop-hyperlinking-hxxps) instead of just complaining about it. --- applications/docs-editor/src/app/Utils/sanitizeUrl.ts | 4 ++++ .../mail/src/app/helpers/transforms/transformLinks.ts | 2 +- packages/shared/lib/helpers/url.ts | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/applications/docs-editor/src/app/Utils/sanitizeUrl.ts b/applications/docs-editor/src/app/Utils/sanitizeUrl.ts index 0f69c453ce0..d6a5148237e 100644 --- a/applications/docs-editor/src/app/Utils/sanitizeUrl.ts +++ b/applications/docs-editor/src/app/Utils/sanitizeUrl.ts @@ -3,6 +3,10 @@ export const sanitizeUrl = (url: string): string | undefined => { return undefined } + if (url.toLowerCase().startsWith('hxxps')) { + return url; + } + let parsedUrl: URL try { parsedUrl = new URL(url) diff --git a/applications/mail/src/app/helpers/transforms/transformLinks.ts b/applications/mail/src/app/helpers/transforms/transformLinks.ts index f94777f9cb3..a19b9f759dc 100644 --- a/applications/mail/src/app/helpers/transforms/transformLinks.ts +++ b/applications/mail/src/app/helpers/transforms/transformLinks.ts @@ -51,7 +51,7 @@ const sanitizeRelativeHttpLinks = (link: HTMLLinkElement) => { // link.href is the absolute value of the link: mail.proton.me is prepended, use getAttribute const url = link.getAttribute('href'); - if (url) { + if (url && !url.toLowerCase().startsWith('hxxps')) { link.setAttribute('href', `http://${url}`); } } diff --git a/packages/shared/lib/helpers/url.ts b/packages/shared/lib/helpers/url.ts index a2e44c87db0..6aecd81a8dd 100644 --- a/packages/shared/lib/helpers/url.ts +++ b/packages/shared/lib/helpers/url.ts @@ -229,6 +229,9 @@ export const getApiSubdomainUrl = (pathname: string, origin: string) => { }; export const getAppUrlFromApiUrl = (apiUrl: string, appName: APP_NAMES) => { + if (apiUrl.toLowerCase().startsWith('hxxps')) { + return new URL(apiUrl); + } const { subdomain } = APPS_CONFIGURATION[appName]; const url = new URL(apiUrl); const { hostname } = url;