mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 12:53:40 +00:00
fix: validate terminal link URLs before opening in external browser
This commit is contained in:
+8
-1
@@ -953,7 +953,14 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
shell.openExternal(url);
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
||||||
|
shell.openExternal(url);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// invalid URL, ignore
|
||||||
|
}
|
||||||
return { action: "deny" };
|
return { action: "deny" };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1938,7 +1938,12 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
|
|||||||
const clipboardProvider = new RobustClipboardProvider();
|
const clipboardProvider = new RobustClipboardProvider();
|
||||||
const clipboardAddon = new ClipboardAddon(undefined, clipboardProvider);
|
const clipboardAddon = new ClipboardAddon(undefined, clipboardProvider);
|
||||||
const unicode11Addon = new Unicode11Addon();
|
const unicode11Addon = new Unicode11Addon();
|
||||||
const webLinksAddon = new WebLinksAddon();
|
const webLinksAddon = new WebLinksAddon((_event, uri) => {
|
||||||
|
const url = uri.startsWith("http://") || uri.startsWith("https://")
|
||||||
|
? uri
|
||||||
|
: `https://${uri}`;
|
||||||
|
window.open(url, "_blank");
|
||||||
|
});
|
||||||
|
|
||||||
fitAddonRef.current = fitAddon;
|
fitAddonRef.current = fitAddon;
|
||||||
terminal.loadAddon(fitAddon);
|
terminal.loadAddon(fitAddon);
|
||||||
|
|||||||
Reference in New Issue
Block a user