Security Engineering
Threat-aware code review. Vulnerability detection. Risk-ranked remediation.
- Security audits and code reviews
- Authentication/authorization review
- Input validation and sanitization checks
- Cryptographic implementation review
- Dependency and supply chain security
- Threat modeling for new features
NOT for: performance optimization, general code review, feature implementation
Load the maintain-tasks skill for stage tracking. Each stage feeds the next.
| Stage |
Trigger |
activeForm |
| Threat Model |
Session start |
"Building threat model" |
| Attack Surface |
Model complete |
"Mapping attack surface" |
| Vulnerability Scan |
Surface mapped |
"Scanning for vulnerabilities" |
| Risk Assessment |
Vulns identified |
"Assessing risk levels" |
| Remediation Plan |
Risks assessed |
"Planning remediation" |
Critical findings: add urgent remediation task immediately.
CVSS-aligned severity for findings:
| Indicator |
Severity |
CVSS |
Examples |
| Critical |
9.0-10.0 |
RCE, auth bypass, mass data exposure, admin privesc |
|
| High |
7.0-8.9 |
SQLi, stored XSS, auth weakness, sensitive data leak |
|
| Medium |
4.0-6.9 |
CSRF, reflected XSS, info disclosure, weak crypto |
|
| Low |
0.1-3.9 |
Misconfig, missing headers, verbose errors |
|
Format: "Critical RCE via unsanitized shell command"
STRIDE Framework
Systematic threat identification by category:
| Threat |
Question |
Check |
| Spoofing |
Can attacker impersonate? |
Auth mechanisms, tokens, sessions, API keys |
| Tampering |
Can attacker modify data? |
Input validation, integrity checks, DB access |
| Repudiation |
Can actions be denied? |
Audit logs, signatures, timestamps |
| Info Disclosure |
Can attacker access secrets? |
Encryption, access control, logging |
| Denial of Service |
Can attacker disrupt? |
Rate limits, timeouts, input size |
| Elevation |
Can attacker gain access? |
Authz checks, RBAC, least privilege |
Attack Trees
Map paths from attacker goal to entry points:
Goal: Steal credentials
- Attack login
- SQLi in username
- Brute force (no rate limit)
- Session fixation
- Intercept traffic
- HTTPS downgrade
- MITM
- Exploit reset
- Predictable token
- No expiry
For each branch assess: feasibility, impact, detection, current defenses.
Trust Boundaries
Identify where data crosses trust levels:
- Browser to server
- Server to database
- Service to third-party API
- Internal service to service
Every boundary needs validation.
Entry Points
External:
- HTTP/API endpoints (REST, GraphQL, gRPC)
- WebSocket connections
- File uploads
- OAuth/SAML flows
- Webhooks
Data Inputs:
- User data (forms, query params, headers)
- File content (type, size, payload)
- API payloads (JSON, XML)
- Database queries
Auth Boundaries:
- Public (no auth)
- Authenticated
- Admin/privileged
- Service-to-service
Prioritize Review
- Unauthenticated external inputs
- Privileged operations
- Data persistence layers
- Third-party integrations
For each entry point document:
- Auth required? (none/user/admin)
- Input validated? (none/basic/strict)
- Rate limited?
- Logged?
- Encrypted?
Quick Reference
| Vulnerability |
Vulnerable |
Secure |
| SQL Injection |
String concat in query |
Parameterized queries |
| XSS |
innerHTML with user data |
textContent or DOMPurify |
| Command Injection |
exec() with user input |
execFile() with array |
| Path Traversal |
Direct path concat |
basename + prefix check |
| Weak Password |
MD5/SHA1/plain |
bcrypt (12+) or argon2 |
| Predictable Token |
Math.random/Date.now |
crypto.randomBytes(32) |
| Broken Auth |
Client-side role check |
Server-side every request |
| IDOR |
No ownership check |
Verify user owns resource |
| Hardcoded Secret |
API key in code |
Environment variable |
| Info Leak |
Stack trace to user |
Generic error, log detail |
Critical Checks
Authentication:
- Passwords: bcrypt/argon2, cost 12+
- Sessions: crypto.randomBytes(32), httpOnly, secure, sameSite
- JWT: verify signature, specify algorithm, short expiry
- Reset: random token, 1hr expiry, hash stored token
Authorization:
- Server-side on every request
- Verify ownership before resource access
- Explicit allowlist for mass assignment
- No role elevation from client input
Input Validation:
- Type, length, format on all inputs
- Parameterized queries (never concat)
- Escape/sanitize HTML output
- Validate file uploads (type, size, content)
Cryptography:
- AES-256-GCM, SHA-256+
- Never MD5, SHA1, DES, ECB
- Secrets from env, never hardcoded
- crypto.randomBytes for all tokens
See vulnerability-patterns.md for code examples.
2021 OWASP Top 10 categories. Check each during vulnerability scan.
| # |
Category |
Key CWEs |
Top Mitigations |
| A01 |
Broken Access Control |
200, 352, 639 |
Server-side checks, ownership validation |
| A02 |
Cryptographic Failures |
259, 327, 331 |
TLS, bcrypt, no hardcoded secrets |
| A03 |
Injection |
20, 79, 89 |
Parameterized queries, input validation |
| A04 |
Insecure Design |
209, 256, 434 |
Threat modeling, rate limiting |
| A05 |
Security Misconfiguration |
16, 611, 614 |
Security headers, disable debug |
| A06 |
Vulnerable Components |
1035, 1104 |
npm audit, Dependabot |
| A07 |
Auth Failures |
287, 307, 521 |
Strong passwords, MFA, rate limiting |
| A08 |
Integrity Failures |
502, 494 |
Verify signatures, schema validation |
| A09 |
Logging Failures |
117, 532, 778 |
Audit logs, redact sensitive data |
| A10 |
SSRF |
918 |
URL allowlist, block private IPs |
See owasp-top-10.md for detailed breakdowns with code examples.
Loop: Model Threats -> Map Surface -> Scan Vulnerabilities -> Assess Risk -> Plan Remediation
Threat Model
- STRIDE analysis for component
- Attack trees for critical paths
- Identify trust boundaries
- Document threat actors
Attack Surface
- Inventory all inputs
- Classify by auth level
- Map data flows across boundaries
- Prioritize high-risk entry points
Vulnerability Scan
- Check each entry against OWASP Top 10
- Review auth/authz
- Validate input handling
- Check crypto usage
- Scan deps:
npm audit, cargo audit
Risk Assessment
- Rate severity (Critical/High/Medium/Low)
- Consider exploitability
- Assess impact (CIA triad)
- Calculate risk score
Remediation Plan
- Critical: immediate action
- High: fix before release
- Medium: schedule in sprint
- Low: backlog or accept
Update todos as you progress. Use review-checklist.md for verification.
Finding Format
## {SEVERITY} {VULN_NAME}
**Category**: {OWASP} | **CWE**: {ID} | **File**: {PATH}:{LINES}
### Issue
{CLEAR_EXPLANATION}
### Impact
{WHAT_ATTACKER_COULD_DO}
### Fix
{SPECIFIC_REMEDIATION_WITH_CODE}
Summary Format
# Security Audit: {SCOPE}
| Severity | Count |
|----------|-------|
| Critical | N |
| High | N |
| Medium | N |
| Low | N |
## Key Findings
1. {TOP_CRITICAL}
2. {SECOND}
3. {THIRD}
## Recommendations
- Immediate: {CRITICAL_FIXES}
- Short-term: {HIGH_MEDIUM}
- Long-term: {HARDENING}
See report-templates.md for full templates.
ALWAYS:
- Start with threat modeling before code review
- Map complete attack surface
- Check against all OWASP Top 10 categories
- Use severity indicators consistently
- Provide specific remediation with code
- Verify fixes don't introduce new vulnerabilities
- Document security assumptions
- Update todos when transitioning stages
NEVER:
- Skip threat modeling for "simple" features
- Assume input is trustworthy
- Rely on client-side security
- Use deprecated crypto (MD5, SHA1, DES)
- Log sensitive data
- Disable security checks "temporarily"
- Mark complete without remediation plan
Deep dives:
- vulnerability-patterns.md - secure vs vulnerable code examples
- owasp-top-10.md - detailed OWASP categories with CWE mappings
- review-checklist.md - complete security review checklist
- report-templates.md - finding and audit report templates
Related skills:
- codebase-recon - evidence-based investigation foundation
- debugging - when security issues manifest as bugs
External:
1---2name: security3description: This skill should be used when auditing code for security issues, reviewing authentication/authorization, evaluating input validation, analyzing cryptographic usage, or reviewing dependency security. Provides OWASP patterns, CWE analysis, and threat modeling guidance.4---56# Security Engineering78Threat-aware code review. Vulnerability detection. Risk-ranked remediation.910<when_to_use>1112- Security audits and code reviews13- Authentication/authorization review14- Input validation and sanitization checks15- Cryptographic implementation review16- Dependency and supply chain security17- Threat modeling for new features1819NOT for: performance optimization, general code review, feature implementation2021</when_to_use>2223<stages>2425Load the **maintain-tasks** skill for stage tracking. Each stage feeds the next.2627| Stage | Trigger | activeForm |28|-------|---------|------------|29| Threat Model | Session start | "Building threat model" |30| Attack Surface | Model complete | "Mapping attack surface" |31| Vulnerability Scan | Surface mapped | "Scanning for vulnerabilities" |32| Risk Assessment | Vulns identified | "Assessing risk levels" |33| Remediation Plan | Risks assessed | "Planning remediation" |3435Critical findings: add urgent remediation task immediately.3637</stages>3839<severity_levels>4041CVSS-aligned severity for findings:4243| Indicator | Severity | CVSS | Examples |44|-----------|----------|------|----------|45| **Critical** | 9.0-10.0 | RCE, auth bypass, mass data exposure, admin privesc |46| **High** | 7.0-8.9 | SQLi, stored XSS, auth weakness, sensitive data leak |47| **Medium** | 4.0-6.9 | CSRF, reflected XSS, info disclosure, weak crypto |48| **Low** | 0.1-3.9 | Misconfig, missing headers, verbose errors |4950Format: "**Critical** RCE via unsanitized shell command"5152</severity_levels>5354<threat_modeling>5556## STRIDE Framework5758Systematic threat identification by category:5960| Threat | Question | Check |61|--------|----------|-------|62| **S**poofing | Can attacker impersonate? | Auth mechanisms, tokens, sessions, API keys |63| **T**ampering | Can attacker modify data? | Input validation, integrity checks, DB access |64| **R**epudiation | Can actions be denied? | Audit logs, signatures, timestamps |65| **I**nfo Disclosure | Can attacker access secrets? | Encryption, access control, logging |66| **D**enial of Service | Can attacker disrupt? | Rate limits, timeouts, input size |67| **E**levation | Can attacker gain access? | Authz checks, RBAC, least privilege |6869## Attack Trees7071Map paths from attacker goal to entry points:7273```74Goal: Steal credentials75- Attack login76 - SQLi in username77 - Brute force (no rate limit)78 - Session fixation79- Intercept traffic80 - HTTPS downgrade81 - MITM82- Exploit reset83 - Predictable token84 - No expiry85```8687For each branch assess: feasibility, impact, detection, current defenses.8889## Trust Boundaries9091Identify where data crosses trust levels:92- Browser to server93- Server to database94- Service to third-party API95- Internal service to service9697Every boundary needs validation.9899</threat_modeling>100101<attack_surface>102103## Entry Points104105**External**:106- HTTP/API endpoints (REST, GraphQL, gRPC)107- WebSocket connections108- File uploads109- OAuth/SAML flows110- Webhooks111112**Data Inputs**:113- User data (forms, query params, headers)114- File content (type, size, payload)115- API payloads (JSON, XML)116- Database queries117118**Auth Boundaries**:119- Public (no auth)120- Authenticated121- Admin/privileged122- Service-to-service123124## Prioritize Review1251261. Unauthenticated external inputs1272. Privileged operations1283. Data persistence layers1294. Third-party integrations130131For each entry point document:132- Auth required? (none/user/admin)133- Input validated? (none/basic/strict)134- Rate limited?135- Logged?136- Encrypted?137138</attack_surface>139140<vulnerability_patterns>141142## Quick Reference143144| Vulnerability | Vulnerable | Secure |145|--------------|------------|--------|146| SQL Injection | String concat in query | Parameterized queries |147| XSS | innerHTML with user data | textContent or DOMPurify |148| Command Injection | exec() with user input | execFile() with array |149| Path Traversal | Direct path concat | basename + prefix check |150| Weak Password | MD5/SHA1/plain | bcrypt (12+) or argon2 |151| Predictable Token | Math.random/Date.now | crypto.randomBytes(32) |152| Broken Auth | Client-side role check | Server-side every request |153| IDOR | No ownership check | Verify user owns resource |154| Hardcoded Secret | API key in code | Environment variable |155| Info Leak | Stack trace to user | Generic error, log detail |156157## Critical Checks158159**Authentication**:160- Passwords: bcrypt/argon2, cost 12+161- Sessions: crypto.randomBytes(32), httpOnly, secure, sameSite162- JWT: verify signature, specify algorithm, short expiry163- Reset: random token, 1hr expiry, hash stored token164165**Authorization**:166- Server-side on every request167- Verify ownership before resource access168- Explicit allowlist for mass assignment169- No role elevation from client input170171**Input Validation**:172- Type, length, format on all inputs173- Parameterized queries (never concat)174- Escape/sanitize HTML output175- Validate file uploads (type, size, content)176177**Cryptography**:178- AES-256-GCM, SHA-256+179- Never MD5, SHA1, DES, ECB180- Secrets from env, never hardcoded181- crypto.randomBytes for all tokens182183See [vulnerability-patterns.md](references/vulnerability-patterns.md) for code examples.184185</vulnerability_patterns>186187<owasp_top_10>1881892021 OWASP Top 10 categories. Check each during vulnerability scan.190191| # | Category | Key CWEs | Top Mitigations |192|---|----------|----------|-----------------|193| A01 | Broken Access Control | 200, 352, 639 | Server-side checks, ownership validation |194| A02 | Cryptographic Failures | 259, 327, 331 | TLS, bcrypt, no hardcoded secrets |195| A03 | Injection | 20, 79, 89 | Parameterized queries, input validation |196| A04 | Insecure Design | 209, 256, 434 | Threat modeling, rate limiting |197| A05 | Security Misconfiguration | 16, 611, 614 | Security headers, disable debug |198| A06 | Vulnerable Components | 1035, 1104 | npm audit, Dependabot |199| A07 | Auth Failures | 287, 307, 521 | Strong passwords, MFA, rate limiting |200| A08 | Integrity Failures | 502, 494 | Verify signatures, schema validation |201| A09 | Logging Failures | 117, 532, 778 | Audit logs, redact sensitive data |202| A10 | SSRF | 918 | URL allowlist, block private IPs |203204See [owasp-top-10.md](references/owasp-top-10.md) for detailed breakdowns with code examples.205206</owasp_top_10>207208<workflow>209210**Loop**: Model Threats -> Map Surface -> Scan Vulnerabilities -> Assess Risk -> Plan Remediation2112121. **Threat Model**213 - STRIDE analysis for component214 - Attack trees for critical paths215 - Identify trust boundaries216 - Document threat actors2172182. **Attack Surface**219 - Inventory all inputs220 - Classify by auth level221 - Map data flows across boundaries222 - Prioritize high-risk entry points2232243. **Vulnerability Scan**225 - Check each entry against OWASP Top 10226 - Review auth/authz227 - Validate input handling228 - Check crypto usage229 - Scan deps: `npm audit`, `cargo audit`2302314. **Risk Assessment**232 - Rate severity (Critical/High/Medium/Low)233 - Consider exploitability234 - Assess impact (CIA triad)235 - Calculate risk score2362375. **Remediation Plan**238 - **Critical**: immediate action239 - **High**: fix before release240 - **Medium**: schedule in sprint241 - **Low**: backlog or accept242243Update todos as you progress. Use [review-checklist.md](references/review-checklist.md) for verification.244245</workflow>246247<reporting>248249## Finding Format250251```markdown252## {SEVERITY} {VULN_NAME}253254**Category**: {OWASP} | **CWE**: {ID} | **File**: {PATH}:{LINES}255256### Issue257{CLEAR_EXPLANATION}258259### Impact260{WHAT_ATTACKER_COULD_DO}261262### Fix263{SPECIFIC_REMEDIATION_WITH_CODE}264```265266## Summary Format267268```markdown269# Security Audit: {SCOPE}270271| Severity | Count |272|----------|-------|273| Critical | N |274| High | N |275| Medium | N |276| Low | N |277278## Key Findings2791. {TOP_CRITICAL}2802. {SECOND}2813. {THIRD}282283## Recommendations284- Immediate: {CRITICAL_FIXES}285- Short-term: {HIGH_MEDIUM}286- Long-term: {HARDENING}287```288289See [report-templates.md](references/report-templates.md) for full templates.290291</reporting>292293<rules>294295ALWAYS:296- Start with threat modeling before code review297- Map complete attack surface298- Check against all OWASP Top 10 categories299- Use severity indicators consistently300- Provide specific remediation with code301- Verify fixes don't introduce new vulnerabilities302- Document security assumptions303- Update todos when transitioning stages304305NEVER:306- Skip threat modeling for "simple" features307- Assume input is trustworthy308- Rely on client-side security309- Use deprecated crypto (MD5, SHA1, DES)310- Log sensitive data311- Disable security checks "temporarily"312- Mark complete without remediation plan313314</rules>315316<references>317318**Deep dives**:319- [vulnerability-patterns.md](references/vulnerability-patterns.md) - secure vs vulnerable code examples320- [owasp-top-10.md](references/owasp-top-10.md) - detailed OWASP categories with CWE mappings321- [review-checklist.md](references/review-checklist.md) - complete security review checklist322- [report-templates.md](references/report-templates.md) - finding and audit report templates323324**Related skills**:325- codebase-recon - evidence-based investigation foundation326- debugging - when security issues manifest as bugs327328**External**:329- [OWASP Top 10](https://owasp.org/Top10/)330- [CWE Database](https://cwe.mitre.org/)331- [OWASP Cheat Sheets](https://cheatsheetseries.owasp.org/)332333</references>