Skip to content

Commit

Permalink
link_utils: exposing whitelisted protocols to user settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonassorgenfrei committed Dec 28, 2024
1 parent 13f3818 commit 084620f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/common/config-schemata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const configSchemata = {
useManualProxy: z.boolean(),
useProxy: z.boolean(),
useSystemProxy: z.boolean(),
whitelistedProtocols: z.string().array(),
};

export const enterpriseConfigSchemata = {
Expand Down
12 changes: 11 additions & 1 deletion app/common/link-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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
Expand Down

0 comments on commit 084620f

Please sign in to comment.