Babysitter electron-ipc-security-audit
Analyze Electron IPC implementations for security vulnerabilities including contextIsolation, nodeIntegration, preload scripts, and channel validation
install
source · Clone the upstream repo
git clone https://github.com/a5c-ai/babysitter
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/a5c-ai/babysitter "$T" && mkdir -p ~/.claude/skills && cp -r "$T/library/specializations/desktop-development/skills/electron-ipc-security-audit" ~/.claude/skills/a5c-ai-babysitter-electron-ipc-security-audit && rm -rf "$T"
manifest:
library/specializations/desktop-development/skills/electron-ipc-security-audit/SKILL.mdsource content
electron-ipc-security-audit
Analyze Electron IPC implementations for security vulnerabilities. This skill performs comprehensive security audits of inter-process communication patterns, checking for contextIsolation issues, nodeIntegration risks, preload script security, and IPC channel validation.
Capabilities
- Audit IPC channel implementations for security vulnerabilities
- Check contextIsolation and nodeIntegration configuration
- Analyze preload scripts for unsafe patterns
- Validate IPC message handling and sanitization
- Detect prototype pollution risks
- Check for remote code execution vulnerabilities
- Review Content Security Policy headers
- Identify exposed APIs through contextBridge
Input Schema
{ "type": "object", "properties": { "projectPath": { "type": "string", "description": "Path to the Electron project root" }, "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": "Minimum severity level to report" }, "includeRecommendations": { "type": "boolean", "default": true } }, "required": ["projectPath"] }
Output Schema
{ "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": "Security score 0-100" } }, "required": ["success", "findings"] }
Security Checks
Critical Checks
- nodeIntegration enabled: Check for
in BrowserWindownodeIntegration: true - contextIsolation disabled: Check for
contextIsolation: false - sandbox disabled: Check for
sandbox: false - Direct ipcRenderer exposure: Check for exposing ipcRenderer without contextBridge
- Remote module usage: Check for deprecated remote module
- eval/Function execution: Check for dynamic code execution in IPC handlers
High Severity Checks
- Unrestricted IPC channels: Check for
patternsipcMain.on('*') - Missing input validation: Check for unsanitized IPC arguments
- webSecurity disabled: Check for
webSecurity: false - Unsafe protocol registration: Check for custom protocol handlers
- Missing CSP headers: Check for Content Security Policy
Medium Severity Checks
- Overly permissive file access: Check for broad file system access
- Insecure web preferences: Check deprecated options
- Missing channel whitelisting: Check preload script exposure
- Navigation to untrusted URLs: Check navigation handlers
Usage Instructions
- Scan project structure: Identify main process, preload, and renderer files
- Check BrowserWindow configurations: Audit webPreferences settings
- Analyze IPC implementations: Review ipcMain/ipcRenderer usage
- Review preload scripts: Check contextBridge API exposure
- Validate CSP headers: Ensure proper Content Security Policy
- Generate report: Compile findings with severity and recommendations
Vulnerability Patterns
Critical: Direct ipcRenderer Exposure
// BAD: Exposing ipcRenderer directly contextBridge.exposeInMainWorld('electron', { ipcRenderer: ipcRenderer // CRITICAL VULNERABILITY }); // GOOD: Expose only specific channels contextBridge.exposeInMainWorld('electron', { send: (channel, data) => { const validChannels = ['file:read', 'file:write']; if (validChannels.includes(channel)) { ipcRenderer.send(channel, data); } } });
Critical: Missing Context Isolation
// BAD: Context isolation disabled new BrowserWindow({ webPreferences: { contextIsolation: false, // CRITICAL preload: path.join(__dirname, 'preload.js') } }); // GOOD: Context isolation enabled new BrowserWindow({ webPreferences: { contextIsolation: true, sandbox: true, preload: path.join(__dirname, 'preload.js') } });
High: Unrestricted IPC Handler
// BAD: Executing arbitrary commands ipcMain.handle('execute', async (event, cmd) => { return exec(cmd); // HIGH RISK }); // GOOD: Whitelisted commands only 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); });
Best Practices
- Always enable contextIsolation: Prevents prototype pollution
- Use sandbox mode: Restricts renderer process capabilities
- Whitelist IPC channels: Only expose necessary channels
- Validate all IPC inputs: Never trust renderer input
- Avoid dynamic code execution: No eval/Function in IPC handlers
- Implement CSP headers: Restrict script sources
- Use invoke/handle pattern: Prefer over send/on for request-response
Related Skills
- Generate secure boilerplateelectron-main-preload-generator
- Build configurationelectron-builder-config
agent - Comprehensive security reviewdesktop-security-auditor
Related Agents
- Architecture guidanceelectron-architect
- Security expertisedesktop-security-auditor