secure-code-review
Systematic security code review methodology. Use this skill when reviewing pull requests for security issues, auditing critical code paths, or performing security assessments. Activate when: security review, code audit, secure code, review PR for security, find vulnerabilities, security assessment.
What this skill does
# Secure Code Review
**A systematic approach to finding security vulnerabilities in code.**
## When to Use
- Reviewing pull requests
- Auditing security-critical code
- Before production deployments
- Compliance requirements
- After security incidents
## Review Methodology
### 1. Understand Context
```markdown
## Pre-Review Questions
- [ ] What does this code do?
- [ ] What data does it handle? (PII, financial, auth)
- [ ] Who can access this functionality?
- [ ] What are the trust boundaries?
- [ ] What could go wrong?
```
### 2. Security Review Checklist
```markdown
## Input Handling
- [ ] All user input validated
- [ ] Input length limits enforced
- [ ] Type checking performed
- [ ] Whitelisting over blacklisting
## Authentication
- [ ] Authentication required where needed
- [ ] Passwords hashed properly (bcrypt/argon2)
- [ ] Session management secure
- [ ] MFA considered for sensitive actions
## Authorization
- [ ] Authorization checks on all endpoints
- [ ] Resource ownership verified
- [ ] No privilege escalation paths
- [ ] Default deny policy
## Data Protection
- [ ] Sensitive data encrypted at rest
- [ ] TLS for data in transit
- [ ] No sensitive data in logs
- [ ] Proper data masking
## Injection Prevention
- [ ] Parameterized queries used
- [ ] No eval() with user data
- [ ] Command injection prevented
- [ ] XSS prevention (encoding/CSP)
## Error Handling
- [ ] No stack traces to users
- [ ] No sensitive data in errors
- [ ] Proper logging of security events
## Dependencies
- [ ] No known vulnerabilities
- [ ] Packages from trusted sources
- [ ] Lock files up to date
```
### 3. High-Risk Areas
Focus extra attention on:
```javascript
// File uploads
app.post('/upload', (req, res) => {
// Check: file type validation, size limits, storage location
});
// Authentication
app.post('/login', (req, res) => {
// Check: rate limiting, timing attacks, error messages
});
// Authorization
app.get('/admin/*', (req, res) => {
// Check: role verification, access control
});
// Data queries
db.query(sql, params);
// Check: parameterized queries, access control
// External API calls
fetch(url);
// Check: SSRF prevention, URL validation
// Serialization
JSON.parse(input);
pickle.loads(input);
// Check: deserialization safety
// Crypto operations
crypto.createCipher();
// Check: algorithm strength, key management
```
## Vulnerability Patterns by Language
### JavaScript/TypeScript
```javascript
// VULNERABLE: Prototype pollution
Object.assign(target, userInput);
target[userKey] = userValue;
// SAFE: Use Map or validate keys
const safeObj = Object.create(null);
if (!['__proto__', 'constructor'].includes(key)) {
safeObj[key] = value;
}
// VULNERABLE: ReDoS
const regex = /^(a+)+$/; // Catastrophic backtracking
// SAFE: Use bounded quantifiers
const regex = /^a{1,100}$/;
// VULNERABLE: Path traversal
const file = path.join(uploadDir, userFilename);
// SAFE: Validate and normalize
const safeName = path.basename(userFilename);
const file = path.join(uploadDir, safeName);
```
### Python
```python
# VULNERABLE: Format string injection
query = "SELECT * FROM users WHERE id = %s" % user_id
eval(f"config['{user_input}']")
# SAFE: Parameterized queries
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
# VULNERABLE: Arbitrary file read
with open(user_path) as f:
return f.read()
# SAFE: Validate path
if not user_path.startswith(ALLOWED_DIR):
raise ValueError("Invalid path")
```
### Java
```java
// VULNERABLE: XML External Entities
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(userInput);
// SAFE: Disable XXE
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// VULNERABLE: Unsafe reflection
Class.forName(userInput).newInstance();
// SAFE: Whitelist allowed classes
if (ALLOWED_CLASSES.contains(className)) {
Class.forName(className).newInstance();
}
```
## Review Comments Template
```markdown
### ๐ด Critical Security Issue
**Location:** `src/auth/login.js:45`
**Issue:** SQL injection vulnerability
**Impact:** Database compromise, data exfiltration
**Fix:**
```javascript
// Before (vulnerable)
const query = `SELECT * FROM users WHERE email = '${email}'`;
// After (safe)
const query = 'SELECT * FROM users WHERE email = $1';
const result = await db.query(query, [email]);
```
---
### ๐ก Security Concern
**Location:** `src/api/users.js:23`
**Issue:** Missing rate limiting on authentication endpoint
**Risk:** Brute force attacks
**Recommendation:** Add rate limiting (see example in `/middleware/rateLimit.js`)
---
### ๐ข Security Suggestion
**Location:** `src/utils/crypto.js:12`
**Suggestion:** Consider using Argon2 instead of bcrypt for password hashing
**Reason:** Better resistance to GPU attacks
```
## Automated Security Scanning
```bash
# Static Analysis (SAST)
# JavaScript
npx eslint --plugin security .
npx njsscan .
# Python
pip install bandit
bandit -r .
# Java
# Use SpotBugs with FindSecBugs plugin
# Multi-language
# Semgrep
semgrep --config auto .
# CodeQL (GitHub)
# Configure in .github/workflows/codeql.yml
```
## Security Review Report Template
```markdown
# Security Review Report
**Project:** [Name]
**Reviewer:** [Name]
**Date:** [Date]
**Scope:** [Files/Features reviewed]
## Executive Summary
[1-2 paragraph summary of findings]
## Risk Rating
- Critical: X
- High: X
- Medium: X
- Low: X
## Findings
### Critical Findings
1. [Finding title]
- Location: [file:line]
- Description: [Details]
- Impact: [What could happen]
- Remediation: [How to fix]
### High Findings
[...]
## Recommendations
1. [Priority recommendation]
2. [...]
## Appendix
- Tools used
- Time spent
- Out of scope items
```
## Best Practices
1. **Review in Layers**: Input โ Processing โ Output
2. **Think Like an Attacker**: How would you exploit this?
3. **Follow Data Flow**: Track untrusted data through the code
4. **Check Trust Boundaries**: Where does trust change?
5. **Use Checklists**: Don't rely on memory
6. **Automate What You Can**: SAST tools catch low-hanging fruit
7. **Document Findings**: Clear, actionable reports
8. **Verify Fixes**: Re-review remediated issues
Related in Security
mac-ops
IncludedComprehensive macOS workstation operations โ diagnose kernel panics, identify failing drives, audit launchd startup items, decode wake reasons, triage TCC permission denials, manage APFS snapshots, recover from no-boot. Use for: Mac is slow, slow bootup, won't boot, kernel panic, kernel_task hot, mds_stores CPU, photoanalysisd, cloudd, login loop, gray screen, sleep wake failure, drive failing, IO errors, APFS snapshots eating space, Time Machine local snapshots, Spotlight indexing, launchd, LaunchAgent, LaunchDaemon, login items, TCC permissions, Full Disk Access, Screen Recording denied, Gatekeeper, quarantine, com.apple.quarantine, app is damaged, helper tool, /Library/PrivilegedHelperTools, pmset, wake reasons, dark wake, sysdiagnose, panic.ips, DiagnosticReports, configuration profile, MDM profile, remote diagnostics over SSH.
a11y-audit
IncludedRun accessibility audits on web projects combining automated scanning (axe-core, Lighthouse) with WCAG 2.1 AA compliance mapping, manual check guidance, and structured reporting. Output is configurable: markdown report only, markdown plus machine-readable JSON, or markdown plus issue tracker integration. Use this skill whenever the user mentions "accessibility audit", "a11y audit", "WCAG audit", "accessibility check", "compliance scan", or asks to check a web project for accessibility issues. Also trigger when the user wants to verify WCAG conformance or map findings to a specific standard (CAN-ASC-6.2, EN 301 549, ADA/AODA).
erpclaw
IncludedAI-native ERP system with self-extending OS. Full accounting, invoicing, inventory, purchasing, tax, billing, HR, payroll, advanced accounting (ASC 606/842, intercompany, consolidation), and financial reporting. 413 actions across 14 domains, 43 expansion modules. Constitutional guardrails, adversarial audit, schema migration. Double-entry GL, immutable audit trail, US GAAP.
assess
IncludedAssesses and rates quality 0-10 across multiple dimensions (correctness, maintainability, security, performance, testability, simplicity) with pros/cons analysis. Compares against project conventions and prior decisions from memory. Produces structured evaluation reports with actionable improvement suggestions. Use when evaluating code, designs, architectures, or comparing alternative approaches.
spring-boot-security-jwt
IncludedProvides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based access control using Spring Security 6.x. Use when implementing authentication or authorization in Spring Boot applications.
code-hardcode-audit
IncludedDetect hardcoded values, magic numbers, and leaked secrets. TRIGGERS - hardcode audit, magic numbers, PLR2004, secret scanning.