mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-20 13:40:11 +08:00
fix(security): PR 审查整改 - setWindowOpenHandler 域名白名单 / openWebsite 协议校验 / 批量云端安装并发控制
- electron/main/index.ts: setWindowOpenHandler 增加 ALLOWED_EXTERNAL_HOSTS 域名后缀白名单,仅可信 https 域名可 shell.openExternal(阻断项2) - AppDetailModal.vue: openWebsite 增加 http/https 协议校验 + noopener,noreferrer(改进项5) - useAccountSync.ts: installCloudItems 改为分批(BATCH_SIZE=3) + Promise.allSettled 错误收集(改进项2) - 审查误报/未改动项已贴代码实证:阻断1 v-html 已用 textContent 转义;改进3 resolveCloudInstallCandidate 已有降级匹配链;改进4 单窗口无 HMR 不重复注册;改进1 暂停/恢复主进程无 handler 维持 TODO
This commit is contained in:
+19
-2
@@ -473,9 +473,26 @@ async function createWindow() {
|
||||
logger.info("Renderer process is ready.");
|
||||
});
|
||||
|
||||
// Make all links open with the browser, not with the application
|
||||
// 仅允许可信域名的 https 链接通过浏览器打开,避免钓鱼/恶意站。
|
||||
// 协议前缀 + 域名后缀白名单双重校验;非法/无效 URL 一律拒绝。
|
||||
const ALLOWED_EXTERNAL_HOSTS = [
|
||||
"spark-app.store",
|
||||
"gitee.com",
|
||||
"bbs.spark-app.store",
|
||||
"spark-app.cn",
|
||||
];
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith("https:")) shell.openExternal(url);
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (
|
||||
parsed.protocol === "https:" &&
|
||||
ALLOWED_EXTERNAL_HOSTS.some((h) => parsed.hostname === h || parsed.hostname.endsWith(`.${h}`))
|
||||
) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
} catch {
|
||||
// 无效 URL,拒绝打开
|
||||
}
|
||||
return { action: "deny" };
|
||||
});
|
||||
// win.webContents.on('will-navigate', (event, url) => { }) #344
|
||||
|
||||
Reference in New Issue
Block a user