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 Targets

Phase 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

Documentation Quality
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:

  1. Use the application

  2. Examine pages and requests

  3. Prioritize based on behavior

Example: Page throws many errors β†’ focus on it

Priority Functions by Category

Category
Examples
Why Priority

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

  1. Read function line by line

  2. Add comments for what each line does

  3. Trace variables to sources in other files

  4. 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

Low Impact
Medium Impact
High Impact

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

Finding
Probability
Impact
Priority

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

  1. Start broad, then narrow - Understand overall design first

  2. Follow the data - Trace user input through the application

  3. Question assumptions - "Is this always true?"

  4. Check edge cases - What happens with unexpected input?

  5. Review dependencies - Third-party code can be vulnerable too

Last updated