Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 37 ยท Threats and Models

Threat Modelling with STRIDE and Data Flow Diagrams

Learn threat modelling step by step: draw a data flow diagram, apply the six STRIDE categories, rank threats, pick mitigations, and automate the checklist in Python.

Threat modelling is the practice of thinking about what could go wrong with a system before it is built or changed, while fixes are still cheap. Instead of waiting for a penetration test to find holes, you sit down with a diagram and ask structured questions. The point is not to predict every attack. It is to find the design-level problems (a database that trusts any internal host, a login that travels in clear text) that no amount of patching will fix later.

A simple and popular method has four questions: What are we building? What can go wrong? What are we going to do about it? Did we do a good enough job? This lesson answers the first three with two tools: data flow diagrams and the STRIDE categories.

Step 1: draw what you are building

A data flow diagram (DFD) has only a few element types:

  • External entities: people or systems outside your control (a customer, a partner API).
  • Processes: things that run code (a web server, a worker).
  • Data stores: databases, file shares, queues.
  • Data flows: arrows showing data moving between the others.
  • Trust boundaries: dashed lines where the level of trust changes (internet to DMZ, DMZ to internal network).

Threats cluster where data crosses a trust boundary, so mark the boundaries carefully.

flowchart LR
    U["Customer (external)"] -->|HTTPS| W["Web server"]
    subgraph DMZ
      W
    end
    W -->|SQL over network| A["Application server"]
    subgraph Internal
      A --> D[("Database")]
    end

Two trust boundaries: internet to DMZ, and DMZ to the internal zone. Each arrow crossing a boundary needs questions asked.

Step 2: what can go wrong? STRIDE

STRIDE is a mnemonic for six kinds of threat. Each one violates a security property you already know.

Letter Threat Property violated Typical network example Typical mitigation
S Spoofing Authentication Forged IP, stolen token, fake server Mutual TLS, strong authentication
T Tampering Integrity Changed packets, altered config MACs, signatures, TLS
R Repudiation Non-repudiation "I never did that" with no logs Audit logging, signed records
I Information disclosure Confidentiality Sniffed credentials, verbose errors Encryption, access control
D Denial of service Availability Flooding, resource exhaustion Rate limits, redundancy
E Elevation of privilege Authorisation Moving from web server to database admin Least privilege, segmentation

Apply the letters to each element. Not every letter applies to every element. A useful guide: external entities can be spoofed and can repudiate; processes can suffer all six; data stores mainly suffer T, I, D (and R if they hold logs); data flows suffer T, I, D.

Step 3: decide what to do

For each threat you choose one of four responses: mitigate (add a control), eliminate (remove the feature), transfer (insurance, a managed service) or accept (document why). Rank by risk so the important ones are done first. A light scoring approach is DREAD or the simple likelihood-times-impact from the first lesson; the exact method matters less than using it consistently.

Automating the checklist

Even a small system produces dozens of STRIDE questions. A script that walks the diagram and generates them keeps you honest. The program below stores a tiny DFD as data, applies the allowed STRIDE categories per element type, and prints one question per cell, highlighting flows that cross trust boundaries.

Python Generate STRIDE questions from a diagram

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.

This is only the question generator. The thinking (answering each question) is the human part. For the flow Customer -> Web server, for example, a good answer to tampering is "TLS 1.3 with certificate validation; the server rejects plain HTTP".

A worked example

Take the flow Web server -> App server [REST over network] in the diagram. Walking STRIDE:

  • Spoofing: can anything on the DMZ pretend to be the web server? Mitigation: mutual TLS, or at least a firewall rule allowing only the web server's address and port.
  • Tampering: could an attacker on the path change requests? Mitigation: encrypt and authenticate the link even inside the data centre.
  • Information disclosure: do errors reveal internals? Mitigation: generic error pages, logs kept server-side.
  • Denial of service: can the web tier flood the app tier? Mitigation: rate limits and timeouts between tiers.
  • Elevation of privilege: if the web server is compromised, what can it call? Mitigation: the app server exposes only the endpoints the web tier needs, with authorisation checks per call.

Record each answer next to the element, with an owner and a status. That table is your threat model.

Python Rank threats and track mitigations

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.

Tips for good threat models

  • Model early, then update when the design changes. A model in a drawer is worthless.
  • Involve developers, operators and security together. Each knows things the others do not.
  • Keep it small. One diagram per feature or subsystem beats a poster nobody reads.
  • Focus on trust boundaries and on assets worth stealing.
  • Turn mitigations into tickets with owners. A finding without an owner is just a worry.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the 'S' in STRIDE stand for, and which property does it violate?

    Spoofing is pretending to be someone or something else. It violates authentication.
  2. 2. Where should you look first in a data flow diagram?

    Trust boundaries are where data moves between levels of trust, so most attacks and mistakes cluster there.
  3. 3. A threat is 'attacker on the LAN changes requests between two servers'. Which STRIDE category is it?

    Altering data in transit is tampering, an integrity threat. TLS with authentication is the typical mitigation.
  4. 4. Which of these is NOT one of the four standard responses to a threat?

    You may accept a risk, but it must be a documented decision. Silently ignoring a threat is not a response.

Summary

  • Threat modelling finds design-level problems early by asking what can go wrong before building.
  • Draw a data flow diagram with entities, processes, stores, flows and trust boundaries.
  • STRIDE covers spoofing, tampering, repudiation, information disclosure, denial of service and elevation of privilege.
  • For each threat choose mitigate, eliminate, transfer or accept, and rank by risk.
  • Keep the model small, current and owned; generate checklists with a script if helpful.

Next: Reconnaissance and Port Scanning for Defenders