mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-08-29 10:21:34 +00:00
fix: harden application trust boundaries (#1317)
This commit is contained in:
+12
-4
@@ -21,7 +21,7 @@ const net = require("net");
|
||||
const tls = require("tls");
|
||||
const zlib = require("zlib");
|
||||
const crypto = require("crypto");
|
||||
const { URL } = require("url");
|
||||
const { URL, pathToFileURL } = require("url");
|
||||
const { fork, spawn } = require("child_process");
|
||||
const pty = require("node-pty");
|
||||
const WebSocket = require("ws");
|
||||
@@ -1193,11 +1193,12 @@ function createWindow() {
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
webSecurity: false,
|
||||
sandbox: true,
|
||||
webSecurity: true,
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
partition: termixSessionPartition,
|
||||
allowRunningInsecureContent: true,
|
||||
webviewTag: true,
|
||||
allowRunningInsecureContent: false,
|
||||
webviewTag: false,
|
||||
offscreen: false,
|
||||
},
|
||||
show: true,
|
||||
@@ -1377,6 +1378,13 @@ function createWindow() {
|
||||
}
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
mainWindow.webContents.on("will-navigate", (event, url) => {
|
||||
const allowedUrl = isDev
|
||||
? url.startsWith("http://localhost:5173/")
|
||||
: url === pathToFileURL(path.join(appRoot, "dist", "index.html")).href;
|
||||
if (!allowedUrl) event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.handle("get-app-version", () => {
|
||||
|
||||
+24
-1
@@ -1,5 +1,28 @@
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
|
||||
const ALLOWED_INVOKE_CHANNELS = new Set([
|
||||
"check-electron-update",
|
||||
"clear-remote-sync-config",
|
||||
"get-desktop-settings",
|
||||
"get-legacy-server-config",
|
||||
"get-remote-sync-config",
|
||||
"get-remote-sync-jwt",
|
||||
"get-remote-sync-status",
|
||||
"get-remote-sync-user-info",
|
||||
"remote-sync-now",
|
||||
"save-desktop-settings",
|
||||
"save-remote-sync-config",
|
||||
"save-remote-sync-jwt",
|
||||
"test-server-connection",
|
||||
]);
|
||||
|
||||
function invokeAllowed(channel, ...args) {
|
||||
if (!ALLOWED_INVOKE_CHANNELS.has(channel)) {
|
||||
return Promise.reject(new Error(`IPC channel is not allowed: ${channel}`));
|
||||
}
|
||||
return ipcRenderer.invoke(channel, ...args);
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld("electronAPI", {
|
||||
getAppVersion: () => ipcRenderer.invoke("get-app-version"),
|
||||
getPlatform: () => ipcRenderer.invoke("get-platform"),
|
||||
@@ -103,7 +126,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
||||
return () => ipcRenderer.removeListener(channel, listener);
|
||||
},
|
||||
|
||||
invoke: (channel, ...args) => ipcRenderer.invoke(channel, ...args),
|
||||
invoke: invokeAllowed,
|
||||
});
|
||||
|
||||
contextBridge.exposeInMainWorld("electronClipboard", {
|
||||
|
||||
Reference in New Issue
Block a user