lessons/review-method.md

Lesson 1 of 18

How to read code like a risk auditor

A repeatable method for any endpoint: context, sources, sinks, controls and logic.

Remember: Follow data from source to sink, then ask which control is missing between them.

A secure code review answers one question: can an attacker make this code do something its owner never intended? You answer it by following data, not by memorising vulnerability names. The same four steps work for a 10-line handler and for a 10,000-line service.

The four steps

  • Context: what does this endpoint do? Does it move money, touch personal data, or grant permissions?
  • Sources: where can untrusted data enter? Request body, URL, query string, headers, cookies, uploaded files, responses from other services.
  • Sinks: where does that data have an effect? SQL, shell commands, outgoing HTTP requests, file paths, HTML output, redirects, balance updates.
  • Controls: between source and sink, what checks exist? Authentication, object-level authorisation, validation, and do they run on the server?
const amount = body.amountMinor;
await transfer(session.userId, body.fromId, body.toId, amount);
Source: body.amountMinor. Sink: the transfer. Control: none. Stop here and ask the question.

Look for what is missing

Most real findings are missing controls, not wrong ones. Read the code and ask what should be checked, then find out whether it is.

  • Who is the caller, and has their identity been verified?
  • Does the ID in the request belong to that caller?
  • Are the type, sign, size and range of each value validated?
  • What happens if the same request runs twice, or twenty times in parallel?
Say what you would do next, out loud: “I would check how fromId is validated before the transfer.” A review is a conversation about risk, not a verdict on the author.

Questions to ask yourself

  1. What is the most valuable thing this endpoint can change?
  2. Which input is untrusted?
  3. Where is the check, if any, and does it run on the server?