Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 80 ยท Security Foundations

Threat Modeling with STRIDE

Learn threat modeling step by step: data-flow diagrams, trust boundaries, the six STRIDE categories, attack trees, and a STRIDE checklist built in Python.

Fixing bugs after release is expensive. Threat modeling is the habit of thinking about what could go wrong while you design, when a change costs a whiteboard eraser instead of a rewrite. It is a structured conversation that answers four questions: what are we building, what can go wrong, what will we do about it, and did we do a good job?

The most popular method for the second question is STRIDE, a checklist of six threat categories that you apply to each part of a system. You will draw a small data-flow diagram, mark its trust boundaries, walk through STRIDE, sketch an attack tree, and turn the result into a Python checklist you can reuse. It follows Threats, Vulnerabilities and Risk.

Step 1: Draw what you are building

A threat model starts with a picture. The standard picture is a data-flow diagram (DFD) with four kinds of element:

  • External entity: people or systems outside your control (a customer, a payment provider).
  • Process: code that does something (the web app, a worker).
  • Data store: anywhere data rests (a database, a file, a cache).
  • Data flow: data moving between the other elements (an HTTPS request, a query).

Then you draw trust boundaries: lines where the level of trust changes, such as the border between the internet and your servers, or between the web app and the database. Almost all attacks cross a trust boundary, so these lines are where you look hardest. Anything arriving across one must be treated as untrusted until it is validated.

flowchart LR
    subgraph Internet["Untrusted: the internet"]
        U["Customer browser"]
    end
    subgraph DMZ["Semi-trusted: public servers"]
        W["Web application"]
    end
    subgraph Internal["Trusted: internal network"]
        DB[("Orders database")]
        PAY["Payment service"]
    end
    U -->|"1. HTTPS request"| W
    W -->|"2. SQL query"| DB
    W -->|"3. Charge request"| PAY
    PAY -->|"4. Result"| W

A small shop. Flows 1, 2 and 3 each cross a trust boundary, so each is a place to ask "what could go wrong?"

Step 2: STRIDE, six questions per element

STRIDE is a mnemonic. Each letter is a type of threat, and each is the opposite of a security property you want.

Letter Threat Violates Typical example Typical defense
S Spoofing Authentication Logging in with someone else's stolen password Strong authentication, MFA
T Tampering Integrity Changing a price in the request or in the database Validation, signatures, access control
R Repudiation Non-repudiation "I never placed that order" with no way to prove otherwise Audit logs, signed records
I Information disclosure Confidentiality Error page leaks database details; unencrypted backup Encryption, access control, safe errors
D Denial of service Availability Flooding the login page; huge uploads fill the disk Rate limits, quotas, redundancy
E Elevation of privilege Authorization A normal user reaches an admin function Least privilege, authorization checks

Not every category applies to every element. A rule of thumb:

Element Usually exposed to
External entity S, R
Process S, T, R, I, D, E (all six)
Data store T, R (for logs), I, D
Data flow T, I, D

So for the data flow "web app sends SQL to the database", you ask: could someone tamper with it (injection), read it (sniffing), or flood it? For the process "web application", you ask all six.

Step 3: Record threats and decide

For each plausible threat, write down: what the threat is, which element it targets, and what you will do (mitigate, accept, transfer or avoid, as in the previous lesson). Rate the risk if you need to prioritize. A simple table in the design document is perfectly fine.

Python STRIDE as data: generate a checklist for every element

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The code does not find threats for you. It makes sure you ask every question for every element, which is the main benefit of a checklist: it protects you from forgetting the boring cases.

Attack trees

A STRIDE pass goes wide. An attack tree goes deep on a single goal. The root is what the attacker wants ("read another customer's order"), and the branches are different ways to achieve it. Branches are combined with OR (any one is enough) or AND (all are needed). Leaves are concrete actions, and you annotate them with difficulty, cost or whether a control already exists.

flowchart TD
    G["Goal: read another customer's order"]
    G --> A["Steal that customer's session"]
    G --> B["Guess or change the order ID in the URL"]
    G --> C["Read the database directly"]
    A --> A1["Phish the customer"]
    A --> A2["Read the cookie over unencrypted HTTP"]
    C --> C1["Inject SQL through the search box"]
    C --> C2["Obtain a leaked backup"]
    B --> B1["Control: server checks order ownership"]

Alternative ways (OR) to reach one goal. Each leaf is either a gap to close or a control that already blocks it.

Reading the tree tells you where to invest. If three different branches end at "the server never checks ownership", one fix (an authorization check, see Authorization and Access Control Models) removes a whole subtree.

You can even score a tree. With OR nodes you take the easiest child; with AND nodes the hardest.

Python Score an attack tree: the cheapest path for an attacker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With two leaves blocked by controls, the cheapest remaining way is phishing (5), so that is where the next control should go: MFA, training, or both. Change a leaf to blocked and watch the best attack path move.

Making threat modeling a habit

  • Do it early and repeat on change. Model a new feature before building it, and update the model when the design changes.
  • Involve developers. They know the system; security people know the threats. Together is better than either alone.
  • Keep the diagram small. One page per feature beats a poster nobody reads. Zoom into the risky area instead of drawing everything.
  • Turn findings into work. Each threat needs an owner and a ticket, or it is just a document.
  • Other methods exist. PASTA is risk- and business-centric, LINDDUN focuses on privacy, and attack trees (above) focus on one goal. STRIDE is the best starting point because it is easy to teach and apply.

Common mistakes are drawing only the "happy path", forgetting data stores (backups, logs, caches), and skipping the boundary between your code and third-party services.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which STRIDE category describes an attacker logging in as another user with a stolen password?

    Spoofing is pretending to be someone or something else. Elevation of privilege would be gaining more rights than you were given, for example going from user to admin.
  2. 2. Why are trust boundaries important in a data-flow diagram?

    Data crossing from a less trusted zone to a more trusted one must be treated as untrusted until checked. Those crossings are the first places to look for threats.
  3. 3. An application has no audit log, so a user can claim they never made a purchase and nobody can disprove it. Which STRIDE letter is this?

    Repudiation is the ability to deny an action without the system being able to prove otherwise. Audit logs and signed records are the usual defenses.
  4. 4. In an attack tree, an AND node has children with effort 3 and 8. Using the lesson's scoring, what effort does the node get?

    An AND node needs every step, so the hardest step limits the attacker. The lesson scores it as the maximum, 8. An OR node would take the minimum.
  5. 5. When should a team threat model a new feature?

    Threats found at design time are cheap to fix. Because designs change, the model must be revisited when they do.

Summary

  • Threat modeling asks what we are building, what can go wrong, what we will do, and whether it worked.
  • A data-flow diagram uses external entities, processes, data stores, flows and trust boundaries.
  • STRIDE: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service, Elevation of privilege. Each maps to a security property and a typical defense.
  • Attack trees go deep on one goal with OR/AND branches, showing the cheapest path and the best place for a control.
  • Do it early, keep it small, repeat it, and turn each finding into an owned task.

Next: The Attack Lifecycle and MITRE ATT&CK