From f2d930d6e2e046baf14b3825af03e4db6e0299da Mon Sep 17 00:00:00 2001 From: NguyenTranHoangSym Date: Mon, 31 Jul 2023 15:57:24 +0700 Subject: [PATCH] SDA-4234: Support Tel Protocol on loading _blank --- src/app/child-window-handler.ts | 28 ++-------------------------- src/app/protocol-handler.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/child-window-handler.ts b/src/app/child-window-handler.ts index fb949e7d..5a1f613d 100644 --- a/src/app/child-window-handler.ts +++ b/src/app/child-window-handler.ts @@ -18,6 +18,7 @@ import { whitelistHandler } from '../common/whitelist-handler'; import { CloudConfigDataTypes, config } from './config-handler'; import crashHandler from './crash-handler'; import { mainEvents } from './main-event-handler'; +import { verifyProtocolForNewUrl } from './protocol-handler'; import { handlePermissionRequests, monitorWindowActions, @@ -44,31 +45,6 @@ const MIN_HEIGHT = 300; const CHILD_WINDOW_EVENTS = ['enter-full-screen', 'leave-full-screen']; -/** - * Verifies protocol for a new url to check if it is http or https - * @param url URL to be verified - */ -const verifyProtocolForNewUrl = (url: string): boolean => { - const parsedUrl = parse(url); - if (!parsedUrl || !parsedUrl.protocol) { - logger.info( - `child-window-handler: The url ${url} doesn't have a protocol. Returning false for verification!`, - ); - return false; - } - - const allowedProtocols = ['http:', 'https:', 'mailto:', 'symphony:', 'sms:']; - // url parse returns protocol with : - if (allowedProtocols.includes(parsedUrl.protocol)) { - logger.info( - `child-window-handler: Protocol of the url ${url} is whitelisted! Returning true for verification!`, - ); - return true; - } - - return false; -}; - /** * Verifies if the url is valid and forcefully appends https if not present * This happens mainly for urls from the same domain @@ -133,7 +109,7 @@ export const handleChildWindow = (webContents: WebContents): void => { const mainWinDomainName = `${mainWinUrlData.domain}${mainWinUrlData.tld}`; logger.info( - `child-window-handler: main window url: ${mainWinUrlData.subdomain}.${mainWinUrlData.domain}.${mainWinUrlData.tld}`, + `child-window-handler: main window url: ${mainWinUrlData.subdomain}.${mainWinUrlData.domain}${mainWinUrlData.tld}`, ); const emptyUrlString = ['about:blank', 'about:blank#blocked']; diff --git a/src/app/protocol-handler.ts b/src/app/protocol-handler.ts index e4c5fbd1..b7fc1ff4 100644 --- a/src/app/protocol-handler.ts +++ b/src/app/protocol-handler.ts @@ -1,4 +1,5 @@ import { CookiesSetDetails, session, WebContents } from 'electron'; +import { parse } from 'url'; import { apiName } from '../common/api-interface'; import { isMac } from '../common/env'; import { logger } from '../common/logger'; @@ -14,6 +15,38 @@ enum protocol { SmsProtocol = 'sms:', } +/** + * Verifies protocol for a new url to check if it is http or https + * @param url URL to be verified + */ +export const verifyProtocolForNewUrl = (url: string): boolean => { + const parsedUrl = parse(url); + if (!parsedUrl || !parsedUrl.protocol) { + logger.info( + `child-window-handler: The url ${url} doesn't have a protocol. Returning false for verification!`, + ); + return false; + } + + const allowedProtocols = [ + 'http:', + 'https:', + 'mailto:', + 'symphony:', + 'sms:', + 'tel:', + ]; + // url parse returns protocol with : + if (allowedProtocols.includes(parsedUrl.protocol)) { + logger.info( + `child-window-handler: Protocol of the url ${url} is whitelisted! Returning true for verification!`, + ); + return true; + } + + return false; +}; + class ProtocolHandler { private static isValidProtocolUri = (uri: string): boolean => !!(uri && uri.startsWith(protocol.SymphonyProtocol));