Security Code Review: A systematic examination of source code to identify security vulnerabilities, with focus on authentication, authorization, input validation, and data handling.
When reviewing human code, I look for mistakes. When reviewing AI code, I look for omissions.
AI doesn’t forget to close a database connection by accident. It systematically omits entire security concerns because they weren’t in the prompt. The auth system works, but there’s no rate limiting. The API returns data, but there’s no authorization check.
The Review Hierarchy
Review in this order. Each level assumes the previous one is solid.
Level 1: Authentication
Start here. If auth is broken, everything else is irrelevant.
Questions:
How are sessions/tokens created?
How are they validated on each request?
Where is the validation middleware?
What happens when validation fails?
Red flags:
1
2
3
4
5
6
7
8
9
10
11
// jwt.decode without verify
constuser=jwt.decode(token);// No expiration
consttoken=jwt.sign({userId});// Weak secret
constSECRET='secret';// Token stored in localStorage
localStorage.setItem('token',response.token);
Auth tells us WHO. Authz tells us WHAT they can do.
Questions:
Can user A access user B’s resources?
Are admin endpoints protected?
Is authorization checked server-side?
What happens when authorization fails?
Red flags:
1
2
3
4
5
6
7
8
9
10
11
12
// Trusting client-provided userId
constdocuments=awaitdb.documents.findMany({where:{userId:req.body.userId}// Not req.user.id!
});// Role check only on frontend
{user.isAdmin&&<AdminPanel/>}// No backend check
// Missing ownership verification
app.delete('/api/posts/:id',async(req,res)=>{awaitdb.posts.delete({where:{id:req.params.id}});});
Are validation errors informative without being exploitable?
Is validation consistent across endpoints?
What types are actually enforced?
Review checklist:
API request bodies validated
Query parameters validated
URL parameters validated
File uploads validated (type, size, content)
Headers validated where used
Red flags:
1
2
3
4
5
6
7
8
9
10
// No validation
const{email,password}=req.body;awaitcreateUser(email,password);// Client-only validation
<inputtype="email"required/>// Server doesn't validate
// Type coercion issues
constid=req.params.id;// String, not number
awaitdb.users.findUnique({where:{id}});// May work, may not
Level 4: Data Handling
How sensitive data flows through the system.
Questions:
Are passwords hashed before storage?
Is sensitive data logged?
What’s returned in API responses?
How are files stored?
Red flags:
1
2
3
4
5
6
7
8
9
10
// Password in logs
console.log('Login attempt:',{email,password});// Full user object returned
res.json({user});// Includes password hash?
// Sensitive data in error messages
catch(error){res.status(500).json({error:error.message});// May leak internals
}
Level 5: Third-Party Integration
AI loves adding libraries. Each one is attack surface.
Questions:
Are API keys in environment variables?
Are webhooks verified?
Is data validated before passing to external services?
## Security Review: [Project Name]
Date: [Date]
Reviewer: [Name]
Commit: [Hash]
### Summary
[High-level findings]
### Critical Issues
1. [Issue]: [Location]
- Impact: [What attacker can do]
- Fix: [How to fix]
### High Issues
[...]
### Recommendations
- [Systemic improvements]
### Out of Scope
[What wasn't reviewed]
FAQ
How long should an AI code review take?
Depends on scope. Auth-focused review: 1-2 hours. Full security review: 4-8 hours. Plan for 2x the time of a human code review—AI generates more code and has more systematic issues.
Should I review all generated code?
No. Focus on code that handles: authentication, authorization, payments, sensitive data, file operations. Skip pure UI components unless they handle user input.
Can AI tools help with security review?
Somewhat. Use AI to explain unfamiliar code patterns. Don’t use AI to determine if something is secure—it has blind spots for the same patterns it creates.
How do I verify fixes without creating new vulnerabilities?
Test the specific vulnerability manually before and after the fix. Run automated scans after fixes to catch regressions. Have a second reviewer check significant security changes.
Conclusion
Key Takeaways
AI code reviews focus on omissions, not mistakes
Review in order: auth, authz, input validation, data handling, integrations
Run automated scans first to catch obvious issues
Manually test authorization with multiple user accounts
Time-box reviews and prioritize auth flows
Document findings with severity, impact, and remediation