Design · lesson 7 of 10
Ideas in this lesson
AThreat modelwhat could go wrong, before it does
BSTRIDEsix kinds of threat
CTrust boundarywhere data crosses from less trusted to more
DSecure by designsafe by default, not by extra effort

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:

  1. What are we working on? The design: lesson 4.4's diagrams.
  2. What can go wrong? The threats.
  3. What are we going to do about it? A defence for each, or a decision to accept the risk.
  4. 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:

textsHTTPSSQLHTTPSHTTPSPatientSMS companyWeb app(Python)DatabaseCounter staffCounter page(in a browser)Waiting-roomscreen (browser)
  1. A patient texts through the SMS company, which calls Pila’s web app (written in Python) over HTTPS.
  2. The web app reads and writes the database.
  3. Counter staff use the counter page in a browser, which talks to the web app over HTTPS.
  4. The waiting-room screen is another browser page, asking the web app who’s next.
Pila as a C4 container diagram. Solid boxes are Pila’s containers: separately running pieces. Dashed boxes are outside Pila; Pink pills are people. C4 diagrams aren’t UML: they use plain boxes and arrows, with every arrow labelled.

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:

STRIDE
ThreatIn plain wordsBreaksAt Pila
SpoofingPretending to be someone or something elseAuthenticityA fake “gateway” request
TamperingChanging data or code you shouldn’tIntegrityMoving your ticket to number 1
RepudiationDenying you did something, with no proof either wayNon-repudiation“I never skipped her”
Information disclosureSeeing data you shouldn’tConfidentialityPhone numbers on the screen
Denial of serviceStopping others from using itAvailability5,000 texts at 6 a.m.
Elevation of privilegeDoing more than you’re allowedAuthorisationA 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

  1. Someone sends Pila a request that looks as if it came from the SMS gateway, to take numbers for phones that never texted

  2. A script texts PILA 5,000 times at 6 a.m. so real patients get “full”

  3. Someone changes their ticket in the database to number 1

  4. A staff member skips a patient, then says they never did

  5. The waiting-room screen shows patients’ phone numbers

  6. A counter staff account can open the page that deletes a whole day

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

Spot the trapKap. Ernesto

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

Where should a threat model look hardest?
A script uses up all 60 numbers before patients can text. Which STRIDE threat is it?
Hiding the admin link from the counter page, but not checking the role on the admin page itself, defends against elevation of privilege…

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.

All sources for Simple Software Development