Skip to content

Commit aa21fe9

Browse files
link_utils: exposing whitelisted protocols to user settings
Adding config option to set protocols in the config that are whitelisted to be opened directly. The behaviour is documented in docs\howto\customize-link-protocols.md.
1 parent d270d56 commit aa21fe9

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

app/common/config-schemata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const configSchemata = {
3636
useManualProxy: z.boolean(),
3737
useProxy: z.boolean(),
3838
useSystemProxy: z.boolean(),
39+
whitelistedProtocols: z.string().array(),
3940
};
4041

4142
export const enterpriseConfigSchemata = {

app/common/link-util.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ import fs from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
55

6-
import {html} from "./html.ts";
6+
import * as ConfigUtil from "./config-util.ts";
7+
import {Html, html} from "./html.ts";
8+
import * as t from "./translation-util.ts";
9+
10+
/* Fetches the current protocolLaunchers from settings.json */
11+
const whitelistedProtocols = ConfigUtil.getConfigItem("whitelistedProtocols", [
12+
"http:",
13+
"https:",
14+
"mailto:",
15+
"tel:",
16+
"sip:",
17+
]);
718

819
export async function openBrowser(url: URL): Promise<void> {
9-
if (["http:", "https:", "mailto:"].includes(url.protocol)) {
20+
if (whitelistedProtocols.includes(url.protocol)) {
1021
await shell.openExternal(url.href);
1122
} else {
1223
// For security, indirect links to non-whitelisted protocols
@@ -21,15 +32,21 @@ export async function openBrowser(url: URL): Promise<void> {
2132
<head>
2233
<meta charset="UTF-8" />
2334
<meta http-equiv="Refresh" content="0; url=${url.href}" />
24-
<title>Redirecting</title>
35+
<title>${t.__("Redirecting")}</title>
2536
<style>
2637
html {
2738
font-family: menu, "Helvetica Neue", sans-serif;
2839
}
2940
</style>
3041
</head>
3142
<body>
32-
<p>Opening <a href="${url.href}">${url.href}</a></p>
43+
<p>
44+
${new Html({
45+
html: t.__("Opening {{{link}}}…", {
46+
link: html`<a href="${url.href}">${url.href}</a>`.html,
47+
}),
48+
})}
49+
</p>
3350
</body>
3451
</html>
3552
`.html,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Customizing Link Protocols
2+
3+
The Zulip app supports opening certain link protocols directly in their associated system applications. These are known as **whitelisted protocols**.
4+
5+
## Default Whitelisted Protocols
6+
7+
By default, the following protocols are whitelisted:
8+
9+
```
10+
http https mailto tel sip
11+
```
12+
13+
Links using these protocols are opened directly by the system.
14+
15+
All other protocols are considered potentially unsafe and are therefore opened indirectly—through a local HTML file—in your default web browser.
16+
17+
## Extending the Whitelisted Protocols
18+
19+
It is possible to customize the list of whitelisted protocols by editing the `settings.json` file located at: `userdata/Zulip/config/settings.json`
20+
21+
To add or modify the list, the `whitelistedProtocols` key can be updated. For example:
22+
23+
```json
24+
{
25+
...
26+
"whitelistedProtocols": [
27+
"http:",
28+
"https:",
29+
"mailto:"
30+
]
31+
...
32+
}
33+
```
34+
35+
Note: Each protocol should include the trailing colon (:), e.g., "mailto:" instead of "mailto".

0 commit comments

Comments
 (0)