Code Quality & Security Review
Guidelines for comprehensive code review covering quality, security, and best practices.
When to Use
- Code review before merge
- Security assessment of changes
- After implementing authentication/authorization
- When handling sensitive data
- Dependency updates
Review Methodology
- Identify questionable or improvable areas
- Dig deeper - Examine ripple effects, dependencies, related code
- Play devil's advocate - Consider invalidating evidence
- Document reasoning before conclusions
- Surface only high-confidence suggestions
Quality Checklist
Code Quality
Security Review
Performance
Design
Security Principles
- Defense in Depth - Multiple redundant controls
- Least Privilege - Minimum necessary access
- Never Trust Input - Validate all external input
- Fail Securely - Default to secure state on error
- Secure Error Handling - No sensitive info in errors
Common Vulnerabilities
Injection
- SQL: Use parameterized queries
- XSS: Sanitize output, use CSP
- Command: Avoid shell; use safe APIs
Authentication
- Session fixation: Regenerate on login
- Credential storage: Use bcrypt/argon2
- Token handling: Validate expiry, signature
Data Exposure
- Encrypt at rest and in transit
- Mask sensitive data in logs
- Implement proper access controls
Output Format
Number all suggestions. Each entry:
- Reasoning: Step-by-step exploration with references to files/functions, including counterarguments considered
- Conclusion: If justified, state the actionable recommendation
Example
1.
- Reasoning: Examined calculateTotal() null-safety. Traced usages
in services/baz.ts. Constructor always sets value.
- Conclusion: No change needed; code is safe.
2.
- Reasoning: Observed duplicate logic in calculateTotal() and
sumOrderAmounts(). Confirmed identical logic, abstraction viable.
- Conclusion: Refactor into shared helper function.
Severity Levels
| Level |
Description |
Action |
| Critical |
Exploitable vulnerability, data loss risk |
Block merge |
| High |
Significant security/quality issue |
Must fix |
| Medium |
Should be addressed |
Fix recommended |
| Low |
Improvement opportunity |
Optional |
Language-Specific Checks
- TypeScript: Strict mode, no
any, proper null handling
- Python: Type hints, PEP 8, no mutable defaults
- Nix: No
with statements, nixfmt-rfc-style
- Go: Idiomatic error handling, proper defer
- Rust: Ownership patterns, lifetime management
- Shell: Proper quoting, safe practices
Feedback Style
- Specific: Reference exact lines with examples
- Actionable: Suggest concrete improvements
- Prioritized: Critical issues first
- Constructive: Acknowledge good practices
- Educational: Explain the "why"
1---2name: review-code-quality3description: Use when reviewing code for quality, security vulnerabilities, and best practices4---5
6# Code Quality & Security Review
7
8Guidelines for comprehensive code review covering quality, security, and best practices.
9
10## When to Use
11
12- Code review before merge
13- Security assessment of changes
14- After implementing authentication/authorization
15- When handling sensitive data
16- Dependency updates
17
18## Review Methodology
19
201. **Identify** questionable or improvable areas
212. **Dig deeper** - Examine ripple effects, dependencies, related code
223. **Play devil's advocate** - Consider invalidating evidence
234. **Document reasoning** before conclusions
245. **Surface only high-confidence** suggestions
25
26## Quality Checklist
27
28### Code Quality
29- [ ] Logic correctness and error handling
30- [ ] Resource management and cleanup
31- [ ] Naming conventions and readability
32- [ ] Function complexity < 10 cyclomatic
33- [ ] No duplication (DRY principle)
34- [ ] Code coverage > 80%
35
36### Security Review
37- [ ] Input validation and sanitization
38- [ ] Authentication/authorization checks
39- [ ] No injection vulnerabilities (SQL, XSS, command)
40- [ ] Proper cryptographic practices
41- [ ] Sensitive data handled securely
42- [ ] Dependencies scanned for vulnerabilities
43
44### Performance
45- [ ] Algorithm efficiency appropriate
46- [ ] No N+1 query problems
47- [ ] Memory usage reasonable
48- [ ] Async patterns used correctly
49- [ ] Caching considered where beneficial
50
51### Design
52- [ ] SOLID principles followed
53- [ ] Appropriate abstraction levels
54- [ ] Low coupling, high cohesion
55- [ ] Interface contracts clear
56
57## Security Principles
58
591. **Defense in Depth** - Multiple redundant controls
602. **Least Privilege** - Minimum necessary access
613. **Never Trust Input** - Validate all external input
624. **Fail Securely** - Default to secure state on error
635. **Secure Error Handling** - No sensitive info in errors
64
65## Common Vulnerabilities
66
67### Injection
68- SQL: Use parameterized queries
69- XSS: Sanitize output, use CSP
70- Command: Avoid shell; use safe APIs
71
72### Authentication
73- Session fixation: Regenerate on login
74- Credential storage: Use bcrypt/argon2
75- Token handling: Validate expiry, signature
76
77### Data Exposure
78- Encrypt at rest and in transit
79- Mask sensitive data in logs
80- Implement proper access controls
81
82## Output Format
83
84Number all suggestions. Each entry:
85
861. **Reasoning**: Step-by-step exploration with references to files/functions, including counterarguments considered
872. **Conclusion**: If justified, state the actionable recommendation
88
89### Example
90
91```
921.
93 - Reasoning: Examined calculateTotal() null-safety. Traced usages
94 in services/baz.ts. Constructor always sets value.
95 - Conclusion: No change needed; code is safe.
96
972.
98 - Reasoning: Observed duplicate logic in calculateTotal() and
99 sumOrderAmounts(). Confirmed identical logic, abstraction viable.
100 - Conclusion: Refactor into shared helper function.
101```
102
103## Severity Levels
104
105| Level | Description | Action |
106|-------|-------------|--------|
107| Critical | Exploitable vulnerability, data loss risk | Block merge |
108| High | Significant security/quality issue | Must fix |
109| Medium | Should be addressed | Fix recommended |
110| Low | Improvement opportunity | Optional |
111
112## Language-Specific Checks
113
114- **TypeScript**: Strict mode, no `any`, proper null handling
115- **Python**: Type hints, PEP 8, no mutable defaults
116- **Nix**: No `with` statements, nixfmt-rfc-style
117- **Go**: Idiomatic error handling, proper defer
118- **Rust**: Ownership patterns, lifetime management
119- **Shell**: Proper quoting, safe practices
120
121## Feedback Style
122
123- **Specific**: Reference exact lines with examples
124- **Actionable**: Suggest concrete improvements
125- **Prioritized**: Critical issues first
126- **Constructive**: Acknowledge good practices
127- **Educational**: Explain the "why"