mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-29 02:11:28 -06:00
Merge pull request #1921 from NguyenTranHoangSym/SDA-4234
SDA-4234: Support Tel Protocol on loading _blank
This commit is contained in:
commit
0754bca41f
@ -18,6 +18,7 @@ import { whitelistHandler } from '../common/whitelist-handler';
|
|||||||
import { CloudConfigDataTypes, config } from './config-handler';
|
import { CloudConfigDataTypes, config } from './config-handler';
|
||||||
import crashHandler from './crash-handler';
|
import crashHandler from './crash-handler';
|
||||||
import { mainEvents } from './main-event-handler';
|
import { mainEvents } from './main-event-handler';
|
||||||
|
import { verifyProtocolForNewUrl } from './protocol-handler';
|
||||||
import {
|
import {
|
||||||
handlePermissionRequests,
|
handlePermissionRequests,
|
||||||
monitorWindowActions,
|
monitorWindowActions,
|
||||||
@ -44,31 +45,6 @@ const MIN_HEIGHT = 300;
|
|||||||
|
|
||||||
const CHILD_WINDOW_EVENTS = ['enter-full-screen', 'leave-full-screen'];
|
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
|
* Verifies if the url is valid and forcefully appends https if not present
|
||||||
* This happens mainly for urls from the same domain
|
* 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}`;
|
const mainWinDomainName = `${mainWinUrlData.domain}${mainWinUrlData.tld}`;
|
||||||
|
|
||||||
logger.info(
|
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'];
|
const emptyUrlString = ['about:blank', 'about:blank#blocked'];
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { CookiesSetDetails, session, WebContents } from 'electron';
|
import { CookiesSetDetails, session, WebContents } from 'electron';
|
||||||
|
import { parse } from 'url';
|
||||||
import { apiName } from '../common/api-interface';
|
import { apiName } from '../common/api-interface';
|
||||||
import { isMac } from '../common/env';
|
import { isMac } from '../common/env';
|
||||||
import { logger } from '../common/logger';
|
import { logger } from '../common/logger';
|
||||||
@ -14,6 +15,38 @@ enum protocol {
|
|||||||
SmsProtocol = 'sms:',
|
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 {
|
class ProtocolHandler {
|
||||||
private static isValidProtocolUri = (uri: string): boolean =>
|
private static isValidProtocolUri = (uri: string): boolean =>
|
||||||
!!(uri && uri.startsWith(protocol.SymphonyProtocol));
|
!!(uri && uri.startsWith(protocol.SymphonyProtocol));
|
||||||
|
Loading…
Reference in New Issue
Block a user