security-patterns
Use when working with Electron - IPC security, renderer isolation, Node API access
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Use when working with Electron - IPC security, renderer isolation, Node API access
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Use when refactoring or implementing features - validation, component design, API research
Use when starting work - guidelines for asking questions and commit policies
Use always - non-negotiable rules for TypeScript safety, socket events, and React patterns
Use when writing tests - test structure, verification steps, coverage goals
استنادا إلى تصنيف SOC المهني
| name | security-patterns |
| description | Use when working with Electron - IPC security, renderer isolation, Node API access |
Use this skill when implementing features that interact with Electron APIs or system resources.
electron/preload.ts
contextBridge.exposeInMainWorld() to expose APIswindow.electronAPI namespace conventionStep 1: Define handler in preload.ts
// electron/preload.ts
import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('electronAPI', {
backend: {
start: () => ipcRenderer.invoke('backend:start'),
stop: () => ipcRenderer.invoke('backend:stop'),
// Add new method here
getStatus: () => ipcRenderer.invoke('backend:status')
}
})
Step 2: Implement handler in main process
// electron/main.ts
ipcMain.handle('backend:status', async () => {
// Access Node.js APIs safely here
return await checkBackendStatus()
})
Step 3: Use in renderer process
// src/components/MyComponent.tsx
'use client'
const status = await window.electronAPI.backend.getStatus()
ipcRenderer.send() or ipcRenderer.invoke() directlytypes/ directoryFile system access:
// ✅ Good - specific, validated
contextBridge.exposeInMainWorld('electronAPI', {
files: {
readConfig: () => ipcRenderer.invoke('files:read-config'),
saveImage: (data: Buffer) => ipcRenderer.invoke('files:save-image', data)
}
})
// ❌ Bad - too generic, security risk
contextBridge.exposeInMainWorld('electronAPI', {
files: {
read: (path: string) => ipcRenderer.invoke('files:read', path) // Unsafe!
}
})
Process management:
// ✅ Good - scoped to backend process
backend: {
start: () => ipcRenderer.invoke('backend:start'),
stop: () => ipcRenderer.invoke('backend:stop')
}
// ❌ Bad - can execute arbitrary commands
system: {
exec: (command: string) => ipcRenderer.invoke('exec', command) // Very unsafe!
}
See Electron Security Guide: https://www.electronjs.org/docs/latest/tutorial/security