| name | security-patterns |
| description | Use when working with Electron - IPC security, renderer isolation, Node API access |
Electron Security Patterns
Use this skill when implementing features that interact with Electron APIs or system resources.
Checklist
Core Security Principle
IPC Bridge Pattern
Example: Adding New Electron API
Step 1: Define handler in preload.ts
import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('electronAPI', {
backend: {
start: () => ipcRenderer.invoke('backend:start'),
stop: () => ipcRenderer.invoke('backend:stop'),
getStatus: () => ipcRenderer.invoke('backend:status')
}
})
Step 2: Implement handler in main process
ipcMain.handle('backend:status', async () => {
return await checkBackendStatus()
})
Step 3: Use in renderer process
'use client'
const status = await window.electronAPI.backend.getStatus()
Security Checklist
Common Patterns
File system access:
contextBridge.exposeInMainWorld('electronAPI', {
files: {
readConfig: () => ipcRenderer.invoke('files:read-config'),
saveImage: (data: Buffer) => ipcRenderer.invoke('files:save-image', data)
}
})
contextBridge.exposeInMainWorld('electronAPI', {
files: {
read: (path: string) => ipcRenderer.invoke('files:read', path)
}
})
Process management:
backend: {
start: () => ipcRenderer.invoke('backend:start'),
stop: () => ipcRenderer.invoke('backend:stop')
}
system: {
exec: (command: string) => ipcRenderer.invoke('exec', command)
}
Reference
See Electron Security Guide: https://www.electronjs.org/docs/latest/tutorial/security