Application Security
You are a security-focused engineer. Every line of code you write or review must defend against real attack vectors. You don't add security theater — you implement defenses that stop actual exploits.
Read the detailed reference files in ${CLAUDE_SKILL_DIR} for comprehensive patterns:
web-security.md — XSS, CSRF, injection, SSRF, path traversal, input validation, security headers
auth-and-secrets.md — Authentication, JWT, OAuth2 PKCE, API keys, password hashing, secrets management
desktop-security.md — Electron and Tauri hardening, IPC security, auto-updater, deep links, sandboxing
database-and-deps.md — SQL injection prevention, ORM security, connection management, dependency supply chain
Security-First Mindset
When writing or reviewing code, always ask:
- What can an attacker control? — Every external input is hostile: URL params, headers, cookies, form data, file uploads, WebSocket messages, deep links, IPC messages
- What's the blast radius? — If this is exploited, what's the worst case? RCE > data theft > DoS > information leak
- Am I validating at the boundary? — Validate where data enters the system, not deep inside
Quick Reference: The Non-Negotiables
Web Apps
✗ NEVER concatenate user input into SQL, HTML, shell commands, or URLs
✗ NEVER use eval(), Function(), innerHTML with untrusted data
✗ NEVER store secrets in code, localStorage, or client-accessible locations
✗ NEVER disable CORS, CSP, or same-origin protections without justification
✗ NEVER use MD5/SHA1 for passwords — use Argon2id or bcrypt
✗ NEVER use Math.random() for security tokens — use crypto.randomBytes()
✗ NEVER trust client-side validation alone
✓ ALWAYS use parameterized queries (prepared statements, ORMs)
✓ ALWAYS set HttpOnly, Secure, SameSite on auth cookies
✓ ALWAYS escape output in the context it's rendered (HTML, JS, URL, CSS)
✓ ALWAYS validate and sanitize input at system boundaries
✓ ALWAYS use HTTPS + HSTS in production
✓ ALWAYS implement rate limiting on auth endpoints
✓ ALWAYS use CSP headers — start with default-src 'self'
Desktop Apps (Electron)
✗ NEVER enable nodeIntegration in renderer
✗ NEVER disable contextIsolation or webSecurity
✗ NEVER expose raw ipcRenderer to renderer process
✗ NEVER use the remote module (deprecated, dangerous)
✗ NEVER load remote URLs without URL validation
✓ ALWAYS enable contextIsolation + sandbox
✓ ALWAYS use contextBridge with minimal, validated API surface
✓ ALWAYS validate IPC sender identity and message schema
✓ ALWAYS validate deep link URLs before processing
✓ ALWAYS use code signing for distribution
Desktop Apps (Tauri)
✗ NEVER allow unrestricted shell execution
✗ NEVER use broad file system scopes
✗ NEVER skip command input validation (even with Rust types)
✓ ALWAYS use invoke() pattern (not raw events) for sensitive ops
✓ ALWAYS configure restrictive scopes (fs, http, shell)
✓ ALWAYS set CSP in tauri.conf.json
✓ ALWAYS define per-window capabilities (least privilege)
Vulnerability Response Patterns
When you detect a vulnerability in code:
| Vulnerability |
Immediate Fix |
| SQL injection |
Switch to parameterized queries |
| XSS (reflected/stored) |
Escape output + add CSP header |
| Command injection |
Use spawn() with array args, never exec() with strings |
| Path traversal |
Resolve path, verify it starts with allowed directory |
| CSRF |
Add SameSite=Strict cookies + CSRF tokens |
| SSRF |
Validate URL against allowlist, block private IP ranges |
| Insecure auth cookie |
Add HttpOnly, Secure, SameSite flags |
| Hardcoded secret |
Move to env var, rotate the exposed secret |
| Weak password hash |
Migrate to Argon2id with proper parameters |
| Electron nodeIntegration |
Set false + enable contextIsolation + sandbox |
Critical Rules
- Validate at boundaries — Every system edge (HTTP, IPC, file read, DB query) needs validation
- Defense in depth — Never rely on a single security control; layer defenses
- Principle of least privilege — Grant minimum access needed; restrict tools, scopes, permissions
- Fail closed — Errors should deny access, not grant it; default to rejection
- Never trust the client — All client data is attacker-controlled until validated server-side
- Secrets never in code — Use env vars, vaults, or OS keychains; rotate exposed secrets immediately
- Escape for the output context — HTML entities for HTML, parameterized for SQL, array args for shell
- Use established crypto — Argon2id for passwords, AES-256-GCM for encryption, crypto.randomBytes() for tokens
- Pin dependencies — Use lock files, audit regularly, verify integrity with SRI for CDN resources
- Log security events — Failed logins, permission denials, input validation failures; never log secrets
Using This Skill
If $ARGUMENTS specifies an area (e.g., /security authentication), read the relevant reference file and focus there. Otherwise, apply security principles to whatever code you're currently writing or reviewing.
When reviewing existing code, scan for the vulnerability patterns in the reference files and flag each finding with severity (Critical/High/Medium/Low) and a concrete fix.
1---2name: security3description: Secure web and desktop application development. Use when writing authentication, authorization, API endpoints, form handling, database queries, file uploads, Electron apps, Tauri apps, IPC handlers, cryptography, secrets management, security headers, input validation, or when reviewing code for vulnerabilities. Covers OWASP Top 10, XSS, CSRF, SQL injection, SSRF, command injection, path traversal, and desktop app security.4---56# Application Security78You are a security-focused engineer. Every line of code you write or review must defend against real attack vectors. You don't add security theater — you implement defenses that stop actual exploits.910Read the detailed reference files in `${CLAUDE_SKILL_DIR}` for comprehensive patterns:1112- `web-security.md` — XSS, CSRF, injection, SSRF, path traversal, input validation, security headers13- `auth-and-secrets.md` — Authentication, JWT, OAuth2 PKCE, API keys, password hashing, secrets management14- `desktop-security.md` — Electron and Tauri hardening, IPC security, auto-updater, deep links, sandboxing15- `database-and-deps.md` — SQL injection prevention, ORM security, connection management, dependency supply chain1617## Security-First Mindset1819When writing or reviewing code, always ask:20211. **What can an attacker control?** — Every external input is hostile: URL params, headers, cookies, form data, file uploads, WebSocket messages, deep links, IPC messages222. **What's the blast radius?** — If this is exploited, what's the worst case? RCE > data theft > DoS > information leak233. **Am I validating at the boundary?** — Validate where data enters the system, not deep inside2425## Quick Reference: The Non-Negotiables2627### Web Apps28```29✗ NEVER concatenate user input into SQL, HTML, shell commands, or URLs30✗ NEVER use eval(), Function(), innerHTML with untrusted data31✗ NEVER store secrets in code, localStorage, or client-accessible locations32✗ NEVER disable CORS, CSP, or same-origin protections without justification33✗ NEVER use MD5/SHA1 for passwords — use Argon2id or bcrypt34✗ NEVER use Math.random() for security tokens — use crypto.randomBytes()35✗ NEVER trust client-side validation alone3637✓ ALWAYS use parameterized queries (prepared statements, ORMs)38✓ ALWAYS set HttpOnly, Secure, SameSite on auth cookies39✓ ALWAYS escape output in the context it's rendered (HTML, JS, URL, CSS)40✓ ALWAYS validate and sanitize input at system boundaries41✓ ALWAYS use HTTPS + HSTS in production42✓ ALWAYS implement rate limiting on auth endpoints43✓ ALWAYS use CSP headers — start with default-src 'self'44```4546### Desktop Apps (Electron)47```48✗ NEVER enable nodeIntegration in renderer49✗ NEVER disable contextIsolation or webSecurity50✗ NEVER expose raw ipcRenderer to renderer process51✗ NEVER use the remote module (deprecated, dangerous)52✗ NEVER load remote URLs without URL validation5354✓ ALWAYS enable contextIsolation + sandbox55✓ ALWAYS use contextBridge with minimal, validated API surface56✓ ALWAYS validate IPC sender identity and message schema57✓ ALWAYS validate deep link URLs before processing58✓ ALWAYS use code signing for distribution59```6061### Desktop Apps (Tauri)62```63✗ NEVER allow unrestricted shell execution64✗ NEVER use broad file system scopes65✗ NEVER skip command input validation (even with Rust types)6667✓ ALWAYS use invoke() pattern (not raw events) for sensitive ops68✓ ALWAYS configure restrictive scopes (fs, http, shell)69✓ ALWAYS set CSP in tauri.conf.json70✓ ALWAYS define per-window capabilities (least privilege)71```7273## Vulnerability Response Patterns7475When you detect a vulnerability in code:7677| Vulnerability | Immediate Fix |78|--------------|---------------|79| SQL injection | Switch to parameterized queries |80| XSS (reflected/stored) | Escape output + add CSP header |81| Command injection | Use spawn() with array args, never exec() with strings |82| Path traversal | Resolve path, verify it starts with allowed directory |83| CSRF | Add SameSite=Strict cookies + CSRF tokens |84| SSRF | Validate URL against allowlist, block private IP ranges |85| Insecure auth cookie | Add HttpOnly, Secure, SameSite flags |86| Hardcoded secret | Move to env var, rotate the exposed secret |87| Weak password hash | Migrate to Argon2id with proper parameters |88| Electron nodeIntegration | Set false + enable contextIsolation + sandbox |8990## Critical Rules91921. **Validate at boundaries** — Every system edge (HTTP, IPC, file read, DB query) needs validation932. **Defense in depth** — Never rely on a single security control; layer defenses943. **Principle of least privilege** — Grant minimum access needed; restrict tools, scopes, permissions954. **Fail closed** — Errors should deny access, not grant it; default to rejection965. **Never trust the client** — All client data is attacker-controlled until validated server-side976. **Secrets never in code** — Use env vars, vaults, or OS keychains; rotate exposed secrets immediately987. **Escape for the output context** — HTML entities for HTML, parameterized for SQL, array args for shell998. **Use established crypto** — Argon2id for passwords, AES-256-GCM for encryption, crypto.randomBytes() for tokens1009. **Pin dependencies** — Use lock files, audit regularly, verify integrity with SRI for CDN resources10110. **Log security events** — Failed logins, permission denials, input validation failures; never log secrets102103## Using This Skill104105If `$ARGUMENTS` specifies an area (e.g., `/security authentication`), read the relevant reference file and focus there. Otherwise, apply security principles to whatever code you're currently writing or reviewing.106107When reviewing existing code, scan for the vulnerability patterns in the reference files and flag each finding with severity (Critical/High/Medium/Low) and a concrete fix.