Electron-IPC安全审计工具Skill electron-ipc-security-audit

Electron-IPC安全审计工具是一款专业的桌面应用安全分析技能,专门用于检测和评估Electron框架中进程间通信(IPC)的安全漏洞。该工具能够全面审计contextIsolation配置、nodeIntegration风险、preload脚本安全性、IPC通道验证等关键安全指标,帮助开发者识别原型污染、远程代码执行等高风险漏洞。适用于Electron应用安全审计、桌面应用安全测试、IPC安全分析等场景。关键词:Electron安全审计、IPC漏洞检测、桌面应用安全、contextIsolation检查、nodeIntegration风险分析、preload脚本安全、进程间通信安全、安全漏洞扫描、Electron安全最佳实践、桌面应用渗透测试。

安全审计 0 次安装 0 次浏览 更新于 2/25/2026

name: electron-ipc-security-audit description: 分析Electron IPC实现中的安全漏洞,包括contextIsolation、nodeIntegration、preload脚本和通道验证 allowed-tools: Read, Grep, Glob, Bash tags: [electron, 安全, ipc, 审计, 桌面应用]

electron-ipc-security-audit

分析Electron IPC实现中的安全漏洞。此技能执行进程间通信模式的全面安全审计,检查contextIsolation问题、nodeIntegration风险、preload脚本安全性和IPC通道验证。

能力

  • 审计IPC通道实现中的安全漏洞
  • 检查contextIsolation和nodeIntegration配置
  • 分析preload脚本中的不安全模式
  • 验证IPC消息处理和清理
  • 检测原型污染风险
  • 检查远程代码执行漏洞
  • 审查内容安全策略头
  • 识别通过contextBridge暴露的API

输入模式

{
  "type": "object",
  "properties": {
    "projectPath": {
      "type": "string",
      "description": "Electron项目根目录路径"
    },
    "auditScope": {
      "type": "array",
      "items": {
        "enum": ["ipc-channels", "preload-scripts", "main-process", "renderer-security", "csp", "all"]
      },
      "default": ["all"]
    },
    "severity": {
      "enum": ["all", "critical", "high", "medium"],
      "default": "all",
      "description": "报告的最低严重级别"
    },
    "includeRecommendations": {
      "type": "boolean",
      "default": true
    }
  },
  "required": ["projectPath"]
}

输出模式

{
  "type": "object",
  "properties": {
    "success": { "type": "boolean" },
    "summary": {
      "type": "object",
      "properties": {
        "totalIssues": { "type": "number" },
        "critical": { "type": "number" },
        "high": { "type": "number" },
        "medium": { "type": "number" },
        "low": { "type": "number" }
      }
    },
    "findings": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "severity": { "enum": ["critical", "high", "medium", "low"] },
          "category": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "file": { "type": "string" },
          "line": { "type": "number" },
          "recommendation": { "type": "string" },
          "codeExample": { "type": "string" }
        }
      }
    },
    "securityScore": {
      "type": "number",
      "description": "安全评分0-100"
    }
  },
  "required": ["success", "findings"]
}

安全检查

关键检查

  1. nodeIntegration启用: 检查BrowserWindow中的nodeIntegration: true
  2. contextIsolation禁用: 检查contextIsolation: false
  3. 沙箱禁用: 检查sandbox: false
  4. 直接ipcRenderer暴露: 检查未通过contextBridge暴露ipcRenderer
  5. 远程模块使用: 检查已弃用的远程模块
  6. eval/Function执行: 检查IPC处理器中的动态代码执行

高严重性检查

  1. 无限制IPC通道: 检查ipcMain.on('*')模式
  2. 缺少输入验证: 检查未清理的IPC参数
  3. webSecurity禁用: 检查webSecurity: false
  4. 不安全协议注册: 检查自定义协议处理器
  5. 缺少CSP头: 检查内容安全策略

中严重性检查

  1. 过度宽松的文件访问: 检查广泛的文件系统访问
  2. 不安全的web偏好设置: 检查已弃用的选项
  3. 缺少通道白名单: 检查preload脚本暴露
  4. 导航到不受信任的URL: 检查导航处理器

使用说明

  1. 扫描项目结构: 识别主进程、preload和渲染器文件
  2. 检查BrowserWindow配置: 审计webPreferences设置
  3. 分析IPC实现: 审查ipcMain/ipcRenderer使用
  4. 审查preload脚本: 检查contextBridge API暴露
  5. 验证CSP头: 确保正确的内容安全策略
  6. 生成报告: 编译包含严重性和建议的发现

漏洞模式

关键: 直接ipcRenderer暴露

// 错误: 直接暴露ipcRenderer
contextBridge.exposeInMainWorld('electron', {
  ipcRenderer: ipcRenderer // 关键漏洞
});

// 正确: 仅暴露特定通道
contextBridge.exposeInMainWorld('electron', {
  send: (channel, data) => {
    const validChannels = ['file:read', 'file:write'];
    if (validChannels.includes(channel)) {
      ipcRenderer.send(channel, data);
    }
  }
});

关键: 缺少上下文隔离

// 错误: 上下文隔离禁用
new BrowserWindow({
  webPreferences: {
    contextIsolation: false, // 关键
    preload: path.join(__dirname, 'preload.js')
  }
});

// 正确: 上下文隔离启用
new BrowserWindow({
  webPreferences: {
    contextIsolation: true,
    sandbox: true,
    preload: path.join(__dirname, 'preload.js')
  }
});

高: 无限制IPC处理器

// 错误: 执行任意命令
ipcMain.handle('execute', async (event, cmd) => {
  return exec(cmd); // 高风险
});

// 正确: 仅允许白名单命令
const ALLOWED_COMMANDS = ['list-files', 'get-info'];
ipcMain.handle('execute', async (event, cmd, args) => {
  if (!ALLOWED_COMMANDS.includes(cmd)) {
    throw new Error('Command not allowed');
  }
  return executeWhitelistedCommand(cmd, args);
});

最佳实践

  1. 始终启用contextIsolation: 防止原型污染
  2. 使用沙箱模式: 限制渲染器进程能力
  3. 白名单IPC通道: 仅暴露必要的通道
  4. 验证所有IPC输入: 永远不要信任渲染器输入
  5. 避免动态代码执行: IPC处理器中不使用eval/Function
  6. 实现CSP头: 限制脚本源
  7. 使用invoke/handle模式: 对于请求-响应优先于send/on

相关技能

  • electron-main-preload-generator - 生成安全样板代码
  • electron-builder-config - 构建配置
  • desktop-security-auditor agent - 全面安全审查

相关代理

  • electron-architect - 架构指导
  • desktop-security-auditor - 安全专业知识

参考资料