Designing for security
Last updated
Security added after launch is a patch; security designed in is a property. Threat modelling is how teams design it in: look at the design, ask what could go wrong, and decide what to do about each answer before any code exists. In this lesson you'll mark Pila's trust boundaries, use STRIDE to find threats at each one, and choose a defence for every threat.
By the end of this lesson you can
- Run a simple threat model with four questions
- Use STRIDE to find threats, and say which kind each one is
- Mark trust boundaries on a design and choose a defence for each threat
Four questions
A threat model is a structured look at a design to find what could go wrong before it does. OWASP, an open community for application security, frames it as four questions:
- What are we working on? The design: lesson 4.4's diagrams.
- What can go wrong? The threats.
- What are we going to do about it? A defence for each, or a decision to accept the risk.
- Did we do a good job? Check, and come back when the design changes.
It needs no special tools: a diagram, a whiteboard, the team, and an afternoon. The attacks themselves are taught in Simple Cybersecurity; here the focus is on designing so they don't work.
Where trust changes
Threats cluster where data crosses from something you trust less to something you trust more: a trust boundary. Look at Pila's container diagram again:
- A patient texts through the SMS company, which calls Pila’s web app (written in Python) over HTTPS.
- The web app reads and writes the database.
- Counter staff use the counter page in a browser, which talks to the web app over HTTPS.
- The waiting-room screen is another browser page, asking the web app who’s next.
Pila's trust boundaries:
- The internet and the web app. Anything reaching the web app, even claiming to be the SMS gateway, could come from anyone.
- Browsers and the web app. The counter page runs on a computer at the counter; the screen runs in the waiting room. Either could be tampered with.
- The web app and the database. Only the app should reach the database at all.
- Staff roles. A counter account and an administrator account are on different sides of a boundary too.
Every arrow that crosses a boundary is a place to ask STRIDE's questions.
STRIDE, in plain words
STRIDE was created at Microsoft in 1999 and is explained in Adam Shostack's Threat Modeling (2014). Each letter is a kind of threat, and each breaks a security property you want:
| Threat | In plain words | Breaks | At Pila |
|---|---|---|---|
| Spoofing | Pretending to be someone or something else | Authenticity | A fake “gateway” request |
| Tampering | Changing data or code you shouldn’t | Integrity | Moving your ticket to number 1 |
| Repudiation | Denying you did something, with no proof either way | Non-repudiation | “I never skipped her” |
| Information disclosure | Seeing data you shouldn’t | Confidentiality | Phone numbers on the screen |
| Denial of service | Stopping others from using it | Availability | 5,000 texts at 6 a.m. |
| Elevation of privilege | Doing more than you’re allowed | Authorisation | A counter account deleting a day |
Find the kind of threat
Here are threats the Pila team found at its trust boundaries. Which kind is each? Every one comes with the defence the team chose.
0 of 7 placed right
Someone sends Pila a request that looks as if it came from the SMS gateway, to take numbers for phones that never texted
A script texts PILA 5,000 times at 6 a.m. so real patients get “full”
Someone changes their ticket in the database to number 1
A staff member skips a patient, then says they never did
The waiting-room screen shows patients’ phone numbers
A counter staff account can open the page that deletes a whole day
The admin page is open to anyone who guesses its address
Each threat gets a response: reduce it (most of these), remove it by changing the design (the screen never receives phone numbers at all), transfer it (the SMS company handles its own network), or accept it, on purpose and written down.
Secure by design
The US Cybersecurity and Infrastructure Security Agency's Secure by Design campaign asks software makers to take responsibility for their customers' security, rather than leaving it to them. Some of its principles, applied to Pila:
- Safe by default. No default admin password: the first administrator sets their own at install. Sign-in is on from the start, not an option.
- Remove whole classes of problem. Using the database library's parameterised queries everywhere rules out SQL injection, instead of hoping each query is careful.
- Security is part of the requirements, with a number where possible (lesson 3.6): "Every admin request checks the signed-in role."
Spot the trap: security after launch
With the launch date close, Kap. Ernesto asks to skip the afternoon’s threat model: “It’s a queue app, not a bank. Add security after launch, if anyone attacks it.”
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- OWASP: Threat Modeling: the four questions of threat modelling
- OWASP: Threat Modeling Process: trust boundaries, STRIDE, and choosing responses
- Microsoft Learn: Threats in the Threat Modeling Tool (STRIDE): the six STRIDE categories, from the company where STRIDE began
- CISA: Secure by Design: makers taking responsibility for security, with safe defaults