Lesson 1 of 6
Knowing the application
Listen to an AI summary of Knowing the application
Why a reviewer learns the application first
Some weaknesses depend on what the application is for. The sports shop sells cup final tickets, and only members may buy a ticket. Code that sells a cup final ticket to a customer who is not a member runs with no error. A reviewer who does not know the rule cannot see the mistake.
Four questions to ask first
A reviewer answers four questions before reading the source code:
- What does the application do?
- Who uses the application?
- Which data must the application protect?
- Where does data from outside come in?
What does the application do
The sports shop sells kit and match tickets. A customer signs in, searches for an item, pays at the checkout and views the order. A customer can also upload a photo for the customer's account.
A reviewer also learns the rules of the application. A rule says who may do something, when and how often. A later lesson on misuse cases shows how to find a rule that the code does not check.
Who uses the application
A reviewer learns what each kind of user is allowed to do. In the shop, a customer buys items and views the customer's own orders. Shop staff add items and change prices. The shop is on the internet, so a person with no account can still open the sign-in page.
Which data must the application protect
Sensitive data is data that would cause harm if the data leaked, changed or was lost. A reviewer takes more care over code that reads, changes or shows sensitive data.
- A customer's password
- Sensitive. A person who learns the password can sign in as the customer.
- A customer's home address
- Sensitive. A leaked home address shows strangers where the customer lives.
- The date of the cup final
- Not sensitive. The shop shows the date to everyone.
Where does data from outside come in
A reviewer looks at an application the way a burglar looks at a house. The burglar sees the doors, the windows and what is kept inside. The doors and windows stand for the places where data comes in. What is kept inside stands for the sensitive data.
An entry point is a place where data from outside can enter an application. Data reaches the shop inside a request. The person who sends a request can put any data in any part of the request. Each part that the code reads is an entry point: the path, a query parameter, a header, a cookie and the body, which holds the form fields and any uploaded file (What is in a request).
Entry points in the sports shop
The sign-in form, the search box, the checkout form and the photo upload are entry points of the sports shop.
People
customers, shop staff, anyone on the internet
- send requests
Entry points
sign-in form, search box, checkout form, photo upload, headers, cookies
- the code reads or changes
Data the shop keeps
names, home addresses, passwords, orders
What is a route
A route is the code on the server that answers requests for one path, such as /search. Some people call a route an endpoint.
Look at the path on the first line of the search route of the sports shop, and at the marked line.
The person can type anything, so the marked line reads from an entry point.
Why a new route needs a careful review
A house has a few doors. An application gains a new entry point with every route. Anyone on the internet can send a request to a route, with any data in the request.
A merge request that adds a route adds an entry point. The reviewer checks who may use the new route and what the route does with the data.
Languages and frameworks
A framework is a large library that does the common jobs of an application. Reading requests and sending back web pages are two such jobs. In the search route, app.get and req come from a framework.
A reviewer finds out which programming language and which framework the application uses. A framework can have protections of its own, such as refusing an uploaded file that is too large.
Configuration is the set of settings that change how software behaves without changing the source code. A setting says how large an uploaded file may be, and can switch the limit off. Code that relies on the limit then has no protection. The lesson on framework configuration covers the settings a reviewer checks.
Check your understanding
Name three of the four questions a reviewer answers before reading the source code.
Show the answer
Any three of these. What does the application do? Who uses the application? Which data must the application protect? Where does data from outside come in?
The sports shop keeps a customer's password, a customer's home address and the date of the cup final. Which two are sensitive data?
Show the answer
The password and the home address. Each would cause harm if leaked, and the shop shows the date of the cup final to everyone.
Give one reason why a merge request that adds a route needs a careful review.
Show the answer
A new route is a new entry point. Anyone on the internet can send a request to the route, with any data in the request.