From 6016c99e7e5b404ea95cddc266722c7c20c0b393 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 25 Jan 2024 17:44:43 +0100 Subject: [PATCH] feat: allow connecting to http localhost nodes (#7799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: allow http localhost * fix: allow if !developerProfile * fix: condition * fix: add lowercase method * fix: allow localhost nodes using http --------- Co-authored-by: Begoña Álvarez de la Cruz --- .../shared/lib/core/network/utils/checkNodeUrlValidity.ts | 8 +++++--- packages/shared/locales/en.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/shared/lib/core/network/utils/checkNodeUrlValidity.ts b/packages/shared/lib/core/network/utils/checkNodeUrlValidity.ts index 3c7d178f4bf..9d3c7ba84db 100644 --- a/packages/shared/lib/core/network/utils/checkNodeUrlValidity.ts +++ b/packages/shared/lib/core/network/utils/checkNodeUrlValidity.ts @@ -15,16 +15,18 @@ export function checkNodeUrlValidity( newUrl: string, allowInsecure: boolean ): string | undefined { + const isHttpLocalhost = + newUrl.toLowerCase().startsWith('http://localhost') || newUrl.toLowerCase().startsWith('http://127.0.0.1') + if (!isValidUrl(newUrl)) { return 'error.node.invalid' } - - if (!allowInsecure && !isValidHttpsUrl(newUrl)) { + if (!allowInsecure && !isHttpLocalhost && !isValidHttpsUrl(newUrl)) { return 'error.node.https' } const hasDefaultHttpsPort = newUrl.endsWith(':443') - if (hasDefaultHttpsPort) { + if (hasDefaultHttpsPort && !isHttpLocalhost) { newUrl = newUrl.slice(0, -4) } diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index a38ed23ba77..49be0201060 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1979,7 +1979,7 @@ "refused": "The connection was refused.", "handshake": "Could not complete handshake with node.", "invalidCertificate": "Could not connect with invalid certificate.", - "https": "HTTPS is required; insecure connections over HTTP are not supported at this time.", + "https": "External connections must use HTTPS; localhost connections can be made using HTTP. Insecure external HTTP connections are not supported.", "duplicate": "This node has already been added.", "noSyncedNode": "No synced node is available.", "timeNotSynced": "Device time is incorrect, unable to sync node.",