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 43ab0de6a..d98fc25c4 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.ts"; import {html} from "./html.ts"; +/* 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 diff --git a/docs/howto/customize-link-protocols.md b/docs/howto/customize-link-protocols.md new file mode 100644 index 000000000..ebcd8a678 --- /dev/null +++ b/docs/howto/customize-link-protocols.md @@ -0,0 +1,35 @@ +# Customizing Link Protocols + +The Zulip app supports opening certain link protocols directly in their associated system applications. These are known as **whitelisted protocols**. + +## Default Whitelisted Protocols + +By default, the following protocols are whitelisted: + +``` +http https mailto tel sip +``` + +Links using these protocols are opened directly by the system. + +All other protocols are considered potentially unsafe and are therefore opened indirectly—through a local HTML file—in your default web browser. + +## Extending the Whitelisted Protocols + +It is possible to customize the list of whitelisted protocols by editing the `settings.json` file located at: `userdata/Zulip/config/settings.json` + +To add or modify the list, the `whitelistedProtocols` key can be updated. For example: + +```json +{ + ... + "whitelistedProtocols": [ + "http:", + "https:", + "mailto:" + ] + ... +} +``` + +Note: Each protocol should include the trailing colon (:), e.g., "mailto:" instead of "mailto".