From 084620f56419605e704e5fe2448e565633ea94c0 Mon Sep 17 00:00:00 2001 From: "Jonas_sorgenfrei@yahoo.de" Date: Fri, 27 Dec 2024 14:19:33 +0100 Subject: [PATCH] link_utils: exposing whitelisted protocols to user settings This commit exposes the whitelisted protocol list to the user settings.json file. This allows user to extend or modify the list of linkifiers that are directly opened by the os instead of being opened via the redirect html method. --- app/common/config-schemata.ts | 1 + app/common/link-util.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/common/config-schemata.ts b/app/common/config-schemata.ts index e2db7b80f..5cab99305 100644 --- a/app/common/config-schemata.ts +++ b/app/common/config-schemata.ts @@ -36,6 +36,7 @@ export const configSchemata = { useManualProxy: z.boolean(), useProxy: z.boolean(), useSystemProxy: z.boolean(), + whitelistedProtocols: z.string().array(), }; export const enterpriseConfigSchemata = { diff --git a/app/common/link-util.ts b/app/common/link-util.ts index bfd2157fa..87305e5e7 100644 --- a/app/common/link-util.ts +++ b/app/common/link-util.ts @@ -3,10 +3,20 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import * as ConfigUtil from "./config-util.js"; import {html} from "./html.js"; +/* Fetches the current protocolLaunchers from settings.json */ +const whitelistedProtocols = ConfigUtil.getConfigItem("whitelistedProtocols", [ + "http:", + "https:", + "mailto:", + "tel:", + "sip:", +]); + export async function openBrowser(url: URL): Promise { - if (["http:", "https:", "mailto:"].includes(url.protocol)) { + if (whitelistedProtocols.includes(url.protocol)) { await shell.openExternal(url.href); } else { // For security, indirect links to non-whitelisted protocols