Published source
Download source ZIP
CH-J Server Manager
Browse directories and files for a specific application release.
Source is provided under the CH-J Proprietary Software License 1.14. Its availability does not change the license terms or grant additional rights.
1
"use strict";3
const path = require("node:path");4
const { BrowserWindow, session, shell } = require("electron");5
const { windowChromeOptions } = require("./windowChrome");7
function isAllowedExternalUrl(value) {8
try {9
const url = new URL(String(value || ""));10
return url.protocol === "https:" && ["ch-j.de"].includes(url.hostname);11
} catch {12
return false;13
}14
}16
function hardenSession(logger) {17
session.defaultSession.setPermissionRequestHandler((_webContents, _permission, callback) => callback(false));18
session.defaultSession.setPermissionCheckHandler(() => false);19
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {20
callback({21
responseHeaders: {22
...details.responseHeaders,23
"X-Content-Type-Options": ["nosniff"],24
"Referrer-Policy": ["no-referrer"],25
"Permissions-Policy": ["camera=(), microphone=(), geolocation=(), usb=(), serial=()"]26
}27
});28
});29
logger?.info("Default Electron session hardened.");30
}32
function createMainWindow(options = {}) {33
const preload = path.join(__dirname, "..", "..", "preload", "corePreload.js");34
const renderer = path.join(__dirname, "..", "..", "renderer", "index.html");35
const window = new BrowserWindow({36
title: "CH-J Server Manager",37
width: 1240,38
height: 780,39
minWidth: 960,40
minHeight: 640,41
backgroundColor: "#07111f",42
icon: options.icon || path.join(__dirname, "..", "..", "..", "build", "icon.png"),43
show: false,44
...windowChromeOptions(),45
webPreferences: {46
preload,47
contextIsolation: true,48
nodeIntegration: false,49
sandbox: true,50
webSecurity: true,51
allowRunningInsecureContent: false,52
spellcheck: false53
}54
});56
window.webContents.setWindowOpenHandler(({ url }) => {57
if (isAllowedExternalUrl(url)) void shell.openExternal(url);58
return { action: "deny" };59
});60
window.webContents.on("will-navigate", (event, url) => {61
if (url !== window.webContents.getURL()) event.preventDefault();62
});63
window.webContents.on("will-attach-webview", (event) => event.preventDefault());64
window.once("ready-to-show", () => window.show());65
window.loadFile(renderer);66
return window;67
}69
module.exports = {70
createMainWindow,71
hardenSession,72
isAllowedExternalUrl,73
windowChromeOptions74
};SHA-256: c994b144c801c3e1018abc83d4e4bee6cd9d4c127ae92c2c01874211e2e66f1d
Archive SHA-256: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0