At a glance
What you need
- A feature or system you are designing or changing
- The people building it, for about an hour
- A whiteboard, or a diagram tool such as OWASP Threat Dragon
The most expensive security flaws are not typos in code. They are decisions: an internal service that trusts anything on the network, an admin action with no second check, a webhook that never verifies who sent it. Threat modeling finds those flaws while they still live on a whiteboard, where fixing them costs an hour instead of a rewrite.
🗺️
Draw the system
Who and what talks to what, and where trust changes hands.
🎯
Ask what can go wrong
Walk every arrow with STRIDE, six questions an attacker would ask.
🛠️
Decide and follow up
Each threat gets a fix, an owner and a ticket, or a written reason to accept it.
The four questions
Every threat modeling method, from a quick sketch to a formal review, answers the same four questions set out in the Threat Modeling Manifesto:
- What are we working on? A diagram of the feature or system.
- What can go wrong? A list of threats.
- What are we going to do about it? Mitigations, each with an owner.
- Did we do a good enough job? A check that the fixes shipped and the model still matches the system.
You do not need a security team or special software to start. A one-hour session with the people building the feature, a whiteboard (or a shared drawing) and the steps below is enough.
1. Draw a data flow diagram
Use four shapes and keep it to one page:
- External entities (rectangles): people and systems you do not control, such as users, a payment provider, a partner's API.
- Processes (circles): your code, such as the web app, a worker, a serverless function.
- Data stores (two parallel lines): databases, buckets, caches, queues.
- Data flows (arrows): what moves between them, labelled with the protocol and the data, for example "HTTPS, card token".
Then draw the line that matters most: the trust boundaries, dashed lines wherever data crosses from something less trusted to something more trusted. The internet to your load balancer, your app to a third-party API, a tenant's data to a shared worker. Most serious threats sit on an arrow that crosses a dashed line.
Keep it next to the code
Draw the diagram as text (Mermaid or PlantUML) or in OWASP Threat Dragon, and commit it to the repository. A diagram that is reviewed in pull requests stays true; one in a slide deck is out of date by the next sprint.
2. Walk every arrow with STRIDE
STRIDE, created at Microsoft, turns "what can go wrong?" into six concrete questions. Ask each one of every flow that crosses a trust boundary:
Threat → property it breaks
- Spoofing → authentication
- Tampering → integrity
- Repudiation → accountability
- Information disclosure → confidentiality
- Denial of service → availability
- Elevation of privilege → authorization
The question to ask
- Can someone pretend to be this user or service?
- Can the data be changed on the way or at rest?
- Could someone deny doing this, and could we prove it?
- Can someone read what they should not?
- Can someone make this slow or unavailable?
- Can someone do more than they are allowed?
A worked example: a payment webhook
A payment provider calls POST /webhooks/payments when a customer pays, and your app marks the order as paid. One arrow, one trust boundary: the internet to your app. Walking it with STRIDE gives:
❌ What can go wrong
- Spoofing: anyone who finds the address can send "order 1042 paid" and get goods for free.
- Tampering: a real message is replayed later, or its amount is changed.
- Repudiation: a disputed order has no record of what the provider actually said.
- Information disclosure: error pages return stack traces with database details to the caller.
- Denial of service: a flood of fake calls ties up the workers that process real orders.
- Elevation of privilege: the handler runs with the same database rights as the admin panel.
✅ What we do about it
- Verify the provider's signature (an HMAC of the raw body with a shared secret) and compare it in constant time.
- Reject messages with a timestamp older than five minutes, and ignore event IDs already processed.
- Store every raw event with its signature check result.
- Return a bare
400or200; details go to private logs only. - Rate-limit the endpoint and queue the work instead of doing it in the request.
- Give the handler a database account that can only update payment status.
import hmac, hashlib, time
def verify(raw_body: bytes, signature: str, timestamp: str, secret: bytes) -> bool:
if abs(time.time() - int(timestamp)) > 300:
return False # too old: possible replay
signed = timestamp.encode() + b"." + raw_body
expected = hmac.new(secret, signed, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature)
Use your provider's own library and header names where one exists; the shape above is the common pattern.
3. Rank, decide and track
You will find more threats than you can fix this sprint. For each one, agree on one of four answers, and write it down:
- Mitigate. Change the design or add a control. Open a ticket with an owner.
- Eliminate. Remove the feature or the data that creates the risk.
- Transfer. Let a provider carry it, for example hosted card fields so card numbers never reach you.
- Accept. Record who accepted it and why, with a date to look again.
Rank with a simple likelihood × impact grid (low, medium, high) rather than a score with false precision. A threat on an internet-facing flow that touches personal information is never "low impact".
A threat model is not a document. It is a habit: a short conversation every time the design changes.
4. Make it part of how you ship
- When: at design time for every new feature that adds a data flow, a trust boundary, a new kind of personal information or a new third party. Small changes need five minutes, not an hour.
- Who: the developers building it, someone who knows the operations side, and a product owner who can make the trade-offs.
- Where: a "Threats" section in your design document or pull request template, linked to the tickets.
- Check: turn the most important mitigations into tests, such as "a webhook with a bad signature is refused", so they cannot quietly disappear.
Design review checklist
- Is there an up-to-date diagram with the trust boundaries drawn?
- Has every flow crossing a boundary been walked with STRIDE?
- Does each threat have a decision, an owner and a ticket?
- Are the key mitigations covered by automated tests?
- Does the feature collect personal information, and is that recorded in your privacy assessment?
▲ Why it matters in Canada
Canadian privacy law expects safeguards to be built in, not bolted on. Quebec's Law 25 requires a privacy impact assessment for any project to acquire, develop or overhaul an information system involving personal information, and a threat model gives that assessment its security section. Federally, PIPEDA requires security safeguards appropriate to the sensitivity of the information. A written threat model is good evidence that you thought about both.
Keep learning
Next: lock down the path from your code to production, and test your APIs against the attacks they actually face.
