[P1/高] WindowManager sandbox: false 削弱渲染进程隔离 #37

Open
opened 2026-07-21 21:56:02 +08:00 by thzxx · 0 comments
Owner

问题类型

安全漏洞 / 高 / 后端服务

文件位置

electron/services/window-manager.service.ts

问题描述

WindowManager 创建 BrowserWindow 时配置:

new BrowserWindow({
  webPreferences: {
    sandbox: false, // 削弱了沙箱
    nodeIntegration: false,
    contextIsolation: true,
  },
});

sandbox: false 允许渲染进程访问 Node.js API(即使 contextIsolation: true):

  1. preload 脚本可使用完整 Node API
  2. 恶意网页通过 preload 漏洞访问 fs / child_process
  3. 违反 Electron 安全最佳实践

影响

  • 渲染进程隔离削弱
  • 安全攻击面扩大

建议修复

new BrowserWindow({
  webPreferences: {
    sandbox: true, // 启用沙箱
    nodeIntegration: false,
    contextIsolation: true,
    preload: join(__dirname, 'preload.js'),
  },
});

启用 sandbox 后:

  1. preload 中只能使用 electron 模块的子集(contextBridge、ipcRenderer 等)
  2. 不能使用 fs / child_process 等 Node API
  3. 需要将所有 Node 操作移至主进程并通过 IPC 调用

可能需要重构部分 preload 代码,建议分阶段实施。

## 问题类型 安全漏洞 / 高 / 后端服务 ## 文件位置 `electron/services/window-manager.service.ts` ## 问题描述 WindowManager 创建 BrowserWindow 时配置: ```ts new BrowserWindow({ webPreferences: { sandbox: false, // 削弱了沙箱 nodeIntegration: false, contextIsolation: true, }, }); ``` `sandbox: false` 允许渲染进程访问 Node.js API(即使 contextIsolation: true): 1. preload 脚本可使用完整 Node API 2. 恶意网页通过 preload 漏洞访问 fs / child_process 3. 违反 Electron 安全最佳实践 ## 影响 - 渲染进程隔离削弱 - 安全攻击面扩大 ## 建议修复 ```ts new BrowserWindow({ webPreferences: { sandbox: true, // 启用沙箱 nodeIntegration: false, contextIsolation: true, preload: join(__dirname, 'preload.js'), }, }); ``` 启用 sandbox 后: 1. preload 中只能使用 `electron` 模块的子集(contextBridge、ipcRenderer 等) 2. 不能使用 fs / child_process 等 Node API 3. 需要将所有 Node 操作移至主进程并通过 IPC 调用 可能需要重构部分 preload 代码,建议分阶段实施。
thzxx added the ??????????? labels 2026-07-21 21:56:02 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#37