Code Review
Overview
The first and most crucial step - reviewing source code to understand design and functionality.
Requirements
Programming language knowledge
Ability to read multiple languages
Knowledge of potential flaws
Understanding of advanced web vulnerabilities
Code Review Phases
Planning & Data Gathering
β
Scope Selection
β
Prioritization & Scope Reduction
β
Reverse Engineering
β
Prioritize TargetsPhase 1: Planning & Data Gathering
Meetings Required
Development team
Other stakeholders
Assets to Collect
Source code
Test server access
Design documentation
User credentials (various roles)
Key Points
All tests on test environment first
May need to set up own test server
Learn to replicate production environment
Phase 2: Scope Selection
With Documentation
Study application design documents
Understand each function's role
Identify critical areas
Without Documentation
Reverse engineer codebase
Read comments (if any)
Map function relationships
Cost Impact
Well documented
Lower cost, faster testing
Poor documentation
Higher cost, longer exercise
No comments
Most expensive, most time
Phase 3: Prioritization & Scope Reduction
Technique 1: Application Design Based
Select functions based on understanding of application design before looking at code.
Example: Files under /purchases/ deal with payment β high priority
Technique 2: Search-Based
Search for sensitive functions through codebase.
PHP Examples:
Pros: Fast Cons: May miss opportunities
Technique 3: Dynamic Usage
Mix of dynamic + static analysis.
Process:
Use the application
Examine pages and requests
Prioritize based on behavior
Example: Page throws many errors β focus on it
Priority Functions by Category
Authentication
login, password reset
Auth bypass
OS Interaction
exec, system, file ops
Command injection, LFI
Database
queries, ORM calls
SQL injection
User Input
forms, uploads
XSS, file upload
Crypto
encryption, hashing
Weak crypto
Session
session handling
Session hijacking
Phase 4: Reverse Engineering
Process
Read function line by line
Add comments for what each line does
Trace variables to sources in other files
Review external functions called
Why It Matters
Example Scenario:
Dangerous function interacts with OS
Direct input is well filtered β
BUT: Under some conditions, input not filtered
OR: Additional input source (e.g., from DB) not filtered
Without reverse engineering β Overlooked With thorough reverse engineering β Caught
Documentation Pattern
Phase 5: Prioritize Targets
Impact Γ Probability Matrix
High Prob
Medium (3)
High (4)
Highest (5)
Med Prob
Low (2)
Medium (3)
High (4)
Low Prob
Lowest (1)
Low (2)
Medium (3)
Prioritization Examples
Auth bypass in login
High
High
Highest
XSS in admin-only page
High
Low
Medium
SQLi in rarely-used feature
Low
High
Medium
Info disclosure
Medium
Low
Low
Code Review Checklist
Preparation
Scope
Analysis
Output
Dangerous Functions by Language
PHP
Python
JavaScript (Node.js)
Java
Tips
Start broad, then narrow - Understand overall design first
Follow the data - Trace user input through the application
Question assumptions - "Is this always true?"
Check edge cases - What happens with unexpected input?
Review dependencies - Third-party code can be vulnerable too
Last updated