mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 21:03:47 +00:00
Merge pull request #769 from ZacharyZcR/fix/electron-url-handler
fix: validate terminal link URLs before opening in external browser
This commit is contained in:
@@ -955,7 +955,14 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// invalid URL, ignore
|
||||||
|
}
|
||||||
return { action: "deny" };
|
return { action: "deny" };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1970,7 +1970,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