Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ function formatErrorMessage(error: unknown): string {
return String(error);
}

function getSafeExternalUrl(rawUrl: unknown): string | null {
if (typeof rawUrl !== "string" || rawUrl.length === 0) {
return null;
}

let parsedUrl: URL;
try {
parsedUrl = new URL(rawUrl);
} catch {
return null;
}

if (parsedUrl.protocol !== "https:" && parsedUrl.protocol !== "http:") {
return null;
}
Comment on lines +127 to +129
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about deep-linking into other apps etc?

Copy link
Copy Markdown
Contributor Author

@Noojuno Noojuno Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project uses react-markdown, which has a default URL transform that wouldn't allow deep-linking into other apps: https://github.com/remarkjs/react-markdown?tab=readme-ov-file#defaulturltransformurl

It's probably a change worth making, but it is a larger change than I would like to PR in this project as-is (especially since they aren't really even accepting PR's in the first place)


return parsedUrl.toString();
}

function writeDesktopStreamChunk(
streamName: "stdout" | "stderr",
chunk: unknown,
Expand Down Expand Up @@ -1033,23 +1052,13 @@ function registerIpcHandlers(): void {

ipcMain.removeHandler(OPEN_EXTERNAL_CHANNEL);
ipcMain.handle(OPEN_EXTERNAL_CHANNEL, async (_event, rawUrl: unknown) => {
if (typeof rawUrl !== "string" || rawUrl.length === 0) {
return false;
}

let parsedUrl: URL;
try {
parsedUrl = new URL(rawUrl);
} catch {
return false;
}

if (parsedUrl.protocol !== "https:" && parsedUrl.protocol !== "http:") {
const externalUrl = getSafeExternalUrl(rawUrl);
if (!externalUrl) {
return false;
}

try {
await shell.openExternal(parsedUrl.toString());
await shell.openExternal(externalUrl);
return true;
} catch {
return false;
Expand Down Expand Up @@ -1142,7 +1151,14 @@ function createWindow(): BrowserWindow {
Menu.buildFromTemplate(menuTemplate).popup({ window });
});

window.webContents.setWindowOpenHandler(() => ({ action: "deny" }));
window.webContents.setWindowOpenHandler(({ url }) => {
const externalUrl = getSafeExternalUrl(url);
if (externalUrl) {
void shell.openExternal(externalUrl);
}
return { action: "deny" };
});

window.on("page-title-updated", (event) => {
event.preventDefault();
window.setTitle(APP_DISPLAY_NAME);
Expand Down