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-analysis - evidence-based investigation foundation
- debugging - when security issues manifest as bugs
External:
1---2name: security-23description: 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:9293- Browser to server94- Server to database95- Service to third-party API96- Internal service to service9798Every boundary needs validation.99100</threat_modeling>101102<attack_surface>103104## Entry Points105106**External**:107108- HTTP/API endpoints (REST, GraphQL, gRPC)109- WebSocket connections110- File uploads111- OAuth/SAML flows112- Webhooks113114**Data Inputs**:115116- User data (forms, query params, headers)117- File content (type, size, payload)118- API payloads (JSON, XML)119- Database queries120121**Auth Boundaries**:122123- Public (no auth)124- Authenticated125- Admin/privileged126- Service-to-service127128## Prioritize Review1291301. Unauthenticated external inputs1312. Privileged operations1323. Data persistence layers1334. Third-party integrations134135For each entry point document:136137- Auth required? (none/user/admin)138- Input validated? (none/basic/strict)139- Rate limited?140- Logged?141- Encrypted?142143</attack_surface>144145<vulnerability_patterns>146147## Quick Reference148149| Vulnerability | Vulnerable | Secure |150| ----------------- | ------------------------ | ------------------------- |151| SQL Injection | String concat in query | Parameterized queries |152| XSS | innerHTML with user data | textContent or DOMPurify |153| Command Injection | exec() with user input | execFile() with array |154| Path Traversal | Direct path concat | basename + prefix check |155| Weak Password | MD5/SHA1/plain | bcrypt (12+) or argon2 |156| Predictable Token | Math.random/Date.now | crypto.randomBytes(32) |157| Broken Auth | Client-side role check | Server-side every request |158| IDOR | No ownership check | Verify user owns resource |159| Hardcoded Secret | API key in code | Environment variable |160| Info Leak | Stack trace to user | Generic error, log detail |161162## Critical Checks163164**Authentication**:165166- Passwords: bcrypt/argon2, cost 12+167- Sessions: crypto.randomBytes(32), httpOnly, secure, sameSite168- JWT: verify signature, specify algorithm, short expiry169- Reset: random token, 1hr expiry, hash stored token170171**Authorization**:172173- Server-side on every request174- Verify ownership before resource access175- Explicit allowlist for mass assignment176- No role elevation from client input177178**Input Validation**:179180- Type, length, format on all inputs181- Parameterized queries (never concat)182- Escape/sanitize HTML output183- Validate file uploads (type, size, content)184185**Cryptography**:186187- AES-256-GCM, SHA-256+188- Never MD5, SHA1, DES, ECB189- Secrets from env, never hardcoded190- crypto.randomBytes for all tokens191192See [vulnerability-patterns.md](references/vulnerability-patterns.md) for code examples.193194</vulnerability_patterns>195196<owasp_top_10>1971982021 OWASP Top 10 categories. Check each during vulnerability scan.199200| # | Category | Key CWEs | Top Mitigations |201| --- | ------------------------- | ------------- | ---------------------------------------- |202| A01 | Broken Access Control | 200, 352, 639 | Server-side checks, ownership validation |203| A02 | Cryptographic Failures | 259, 327, 331 | TLS, bcrypt, no hardcoded secrets |204| A03 | Injection | 20, 79, 89 | Parameterized queries, input validation |205| A04 | Insecure Design | 209, 256, 434 | Threat modeling, rate limiting |206| A05 | Security Misconfiguration | 16, 611, 614 | Security headers, disable debug |207| A06 | Vulnerable Components | 1035, 1104 | npm audit, Dependabot |208| A07 | Auth Failures | 287, 307, 521 | Strong passwords, MFA, rate limiting |209| A08 | Integrity Failures | 502, 494 | Verify signatures, schema validation |210| A09 | Logging Failures | 117, 532, 778 | Audit logs, redact sensitive data |211| A10 | SSRF | 918 | URL allowlist, block private IPs |212213See [owasp-top-10.md](references/owasp-top-10.md) for detailed breakdowns with code examples.214215</owasp_top_10>216217<workflow>218219**Loop**: Model Threats -> Map Surface -> Scan Vulnerabilities -> Assess Risk -> Plan Remediation2202211. **Threat Model**222 - STRIDE analysis for component223 - Attack trees for critical paths224 - Identify trust boundaries225 - Document threat actors2262272. **Attack Surface**228 - Inventory all inputs229 - Classify by auth level230 - Map data flows across boundaries231 - Prioritize high-risk entry points2322333. **Vulnerability Scan**234 - Check each entry against OWASP Top 10235 - Review auth/authz236 - Validate input handling237 - Check crypto usage238 - Scan deps: `npm audit`, `cargo audit`2392404. **Risk Assessment**241 - Rate severity (Critical/High/Medium/Low)242 - Consider exploitability243 - Assess impact (CIA triad)244 - Calculate risk score2452465. **Remediation Plan**247 - **Critical**: immediate action248 - **High**: fix before release249 - **Medium**: schedule in sprint250 - **Low**: backlog or accept251252Update todos as you progress. Use [review-checklist.md](references/review-checklist.md) for verification.253254</workflow>255256<reporting>257258## Finding Format259260```markdown261## {SEVERITY} {VULN_NAME}262263**Category**: {OWASP} | **CWE**: {ID} | **File**: {PATH}:{LINES}264265### Issue266267{CLEAR_EXPLANATION}268269### Impact270271{WHAT_ATTACKER_COULD_DO}272273### Fix274275{SPECIFIC_REMEDIATION_WITH_CODE}276```277278## Summary Format279280```markdown281# Security Audit: {SCOPE}282283| Severity | Count |284| -------- | ----- |285| Critical | N |286| High | N |287| Medium | N |288| Low | N |289290## Key Findings2912921. {TOP_CRITICAL}2932. {SECOND}2943. {THIRD}295296## Recommendations297298- Immediate: {CRITICAL_FIXES}299- Short-term: {HIGH_MEDIUM}300- Long-term: {HARDENING}301```302303See [report-templates.md](references/report-templates.md) for full templates.304305</reporting>306307<rules>308309ALWAYS:310311- Start with threat modeling before code review312- Map complete attack surface313- Check against all OWASP Top 10 categories314- Use severity indicators consistently315- Provide specific remediation with code316- Verify fixes don't introduce new vulnerabilities317- Document security assumptions318- Update todos when transitioning stages319320NEVER:321322- Skip threat modeling for "simple" features323- Assume input is trustworthy324- Rely on client-side security325- Use deprecated crypto (MD5, SHA1, DES)326- Log sensitive data327- Disable security checks "temporarily"328- Mark complete without remediation plan329330</rules>331332<references>333334**Deep dives**:335336- [vulnerability-patterns.md](references/vulnerability-patterns.md) - secure vs vulnerable code examples337- [owasp-top-10.md](references/owasp-top-10.md) - detailed OWASP categories with CWE mappings338- [review-checklist.md](references/review-checklist.md) - complete security review checklist339- [report-templates.md](references/report-templates.md) - finding and audit report templates340341**Related skills**:342343- codebase-analysis - evidence-based investigation foundation344- debugging - when security issues manifest as bugs345346**External**:347348- [OWASP Top 10](https://owasp.org/Top10/)349- [CWE Database](https://cwe.mitre.org/)350- [OWASP Cheat Sheets](https://cheatsheetseries.owasp.org/)351352</references>