STRIDE per Element on a Sample Service
Run STRIDE per element on the BookSwap cover-upload feature: generate the worksheet of element and category pairs from a model, write a threat list, let a checker reject misfiled or empty entries, and finish with every pair answered or justified.
Contentsand lesson path
On this page
- Goal and setup
- STRIDE in one page
- Step 1: Describe the system and the scope
- Step 2: Generate the worksheet
- Step 3: Check a first attempt
- Step 4: Complete the threat list
- Step 5: Summarise for the next step
- Check your understanding
- Apply it
- Review prompt
Lessons of Threat Modeling
- Four Questions Behind Every Threat Model Concept · 15 min
- Diagramming Data Flows and Trust Boundaries Worked example · 25 min
- STRIDE per Element on a Sample Service Lab · 30 min
- Attack Trees for the Threats That Matter Worked example · 20 min
- From Threats to Owned, Verifiable Mitigations Worked example · 20 min
- Threat Modeling Check Knowledge check · 8 questions
What you will learn
- Enumerate threats with STRIDE per element and expand the highest-impact ones into attack trees.
01. Goal and setup
In this lab you answer question 2 of the four questions, "what can go wrong?", for one feature of BookSwap: cover-photo uploads. You will use STRIDE per element, the method Microsoft's security team described in 2006 and that most threat-modelling tools still use. Instead of brainstorming freely, you walk through each element of the data-flow diagram and ask only the questions that apply to its type. The result is a threat list that you can show is complete for the scope you chose.
By the end you will have a threats.csv file that covers all 17 element and category pairs of the upload feature, checked by a script that fails on gaps and on common filing mistakes.
You need: Python 3.10 or later. No packages. All commands run inside a folder called stride-lab.
stride-lab/
├── model.json step 1: elements, flows and scopes of BookSwap
├── stride.py step 2: worksheet and checker
├── threats-draft.csv step 3: a first attempt with mistakes
├── threats.csv step 4: the complete threat list
└── tally.py step 5: summary for the next lesson02. STRIDE in one page
Each STRIDE letter is the opposite of a security property you want:
- Spoofing breaks authentication: someone pretends to be another user or system.
- Tampering breaks integrity: someone changes data or code they should not change.
- Repudiation breaks non-repudiation: someone can deny an action because nothing reliable records who did it.
- Information disclosure breaks confidentiality: data reaches someone who should not see it.
- Denial of service breaks availability: the system becomes slow or unusable.
- Elevation of privilege breaks authorisation: someone does things their role does not allow.
Not every letter makes sense for every element. A data flow cannot "pretend to be" anyone, and a stored file cannot "deny" an action. The per-element chart narrows the questions. External entities are checked for spoofing and repudiation. Processes are checked for all six. Data stores and data flows are checked for tampering, information disclosure and denial of service, and a store that holds logs is also checked for repudiation, because those logs are the evidence that stops people denying actions.
When a threat seems to need a letter that does not apply, it usually belongs to a different element. "Someone pretends to be the bucket" is really spoofing of the process or service that answers on the bucket's behalf.
03. Step 1: Describe the system and the scope
The model lists every element of BookSwap and every flow, the same way as the diagram in lesson 2, plus the admin console and the audit log. Because those add flows, the flow ids are numbered again: the flow that stores a cover image is F5 here (F4 in lesson 2), and the email provider flow is F8 (F6 there). The scopes entry names the elements that the cover-upload change touches: the member, the API, the cover bucket, the upload flow F2 and the flow F5 that stores the image. Save it as stride-lab/model.json.
{
"system": "BookSwap",
"elements": {
"member": {"type": "external", "label": "Member browser"},
"admin": {"type": "external", "label": "Staff admin browser"},
"api": {"type": "process", "label": "Web API"},
"worker": {"type": "process", "label": "Email worker"},
"db": {"type": "store", "label": "Postgres"},
"covers": {"type": "store", "label": "Cover bucket"},
"audit": {"type": "store", "label": "Audit log", "holds_logs": true},
"mailer": {"type": "external", "label": "Email provider"}
},
"flows": [
{"id": "F1", "from": "member", "to": "api", "data": "login, search, borrow"},
{"id": "F2", "from": "member", "to": "api", "data": "cover image upload"},
{"id": "F3", "from": "admin", "to": "api", "data": "approve or remove listings"},
{"id": "F4", "from": "api", "to": "db", "data": "member and loan rows"},
{"id": "F5", "from": "api", "to": "covers", "data": "stored cover image"},
{"id": "F6", "from": "api", "to": "audit", "data": "audit events"},
{"id": "F7", "from": "api", "to": "worker", "data": "email job"},
{"id": "F8", "from": "worker", "to": "mailer", "data": "email + API key"}
],
"scopes": {
"cover-upload": ["member", "api", "covers", "F2", "F5"]
}
}From inside stride-lab, check that the file is valid JSON. A missing comma here would otherwise surface later as a confusing error from the checker.
python3 -m json.tool model.json > /dev/null && echo "model.json is valid JSON"model.json is valid JSON04. Step 2: Generate the worksheet
The script has two commands. worksheet lists the element and category pairs you must answer, with a plain-language question for each letter. check compares a threat list with that worksheet. Save it as stride-lab/stride.py.
"""STRIDE per element: build a worksheet for a scope and check a threat list."""
import csv
import json
import sys
APPLIES = {"external": "SR", "process": "STRIDE", "store": "TID", "flow": "TID"}
QUESTION = {
"S": "Can someone pretend to be it, or fool it about who is calling?",
"T": "Can someone change it, or the data it holds or carries?",
"R": "Could someone deny an action because nothing proves who did it?",
"I": "Can someone read data here that they should not see?",
"D": "Can someone make it slow or unavailable?",
"E": "Can someone make it do things their role does not allow?",
}
model = json.load(open("model.json"))
def all_items():
for key, e in model["elements"].items():
letters = APPLIES[e["type"]]
if e["type"] == "store" and e.get("holds_logs"):
letters = "TRID" # a log store also carries the evidence for R
yield key, e["type"], letters
for f in model["flows"]:
yield f["id"], "flow", APPLIES["flow"]
def pairs(scope):
keep = model["scopes"][scope] if scope else None
return [(item, kind, letter) for item, kind, letters in all_items()
if keep is None or item in keep for letter in letters]
def worksheet(scope=None):
rows = pairs(scope)
if scope is None:
print(f"{model['system']}: {len(rows)} element/category pairs")
return
print(f"Scope {scope}: {len(rows)} pairs to answer")
for item, kind, letter in rows:
print(f" {item:<7}{kind:<9}{letter} {QUESTION[letter]}")
def check(scope, path):
wanted = {(item, letter): kind for item, kind, letter in pairs(scope)}
every = {(item, letter) for item, _, letter in pairs(None)}
kinds = {item: kind for item, kind, _ in all_items()}
covered, problems = set(), []
for row in csv.DictReader(open(path)):
key = (row["element"], row["stride"])
where = f"{row['id']} ({row['element']}/{row['stride']})"
if row["element"] not in kinds:
problems.append(f"{where}: no element or flow with this id")
elif key not in every:
kind = kinds[row["element"]]
problems.append(f"{where}: {row['stride']} does not apply to a {kind}; "
"file it on the element that acts")
elif key not in wanted:
problems.append(f"{where}: outside scope {scope}")
elif not row["threat"].strip():
problems.append(f"{where}: empty threat statement")
elif row["status"] in ("mitigated", "n/a") and not row["reason"].strip():
problems.append(f"{where}: {row['status']} needs a reason")
else:
covered.add(key)
missing = [f"{i}/{s}" for i, s in wanted if (i, s) not in covered]
for p in problems:
print("PROBLEM", p)
print(f"Covered {len(covered)} of {len(wanted)} pairs")
for start in range(0, len(missing), 6):
print("Missing:", " ".join(missing[start:start + 6]))
return 1 if problems or missing else 0
if __name__ == "__main__":
cmd, args = sys.argv[1], sys.argv[2:]
if cmd == "worksheet":
worksheet(*args)
elif cmd == "check":
sys.exit(check(*args))python3 stride.py worksheet
python3 stride.py worksheet cover-uploadBookSwap: 52 element/category pairs
Scope cover-upload: 17 pairs to answer
member external S Can someone pretend to be it, or fool it about who is calling?
member external R Could someone deny an action because nothing proves who did it?
api process S Can someone pretend to be it, or fool it about who is calling?
api process T Can someone change it, or the data it holds or carries?
api process R Could someone deny an action because nothing proves who did it?
api process I Can someone read data here that they should not see?
api process D Can someone make it slow or unavailable?
api process E Can someone make it do things their role does not allow?
covers store T Can someone change it, or the data it holds or carries?
covers store I Can someone read data here that they should not see?
covers store D Can someone make it slow or unavailable?
F2 flow T Can someone change it, or the data it holds or carries?
F2 flow I Can someone read data here that they should not see?
F2 flow D Can someone make it slow or unavailable?
F5 flow T Can someone change it, or the data it holds or carries?
F5 flow I Can someone read data here that they should not see?
F5 flow D Can someone make it slow or unavailable?The whole system has 52 pairs; the upload feature has 17. That difference is why scoping matters. A team that tries to answer 52 questions for every change gives up, while 17 focused questions take about half an hour. When the feature ships, the next change gets its own scope, and over time the whole model fills in.
05. Step 3: Check a first attempt
Below is a realistic first draft of the kind a team writes in a meeting. Each row names an element, a STRIDE letter, a one-line threat, a status (open for threats still to handle, mitigated for threats that a control already in place handles, n/a for pairs you decided do not apply) and, for mitigated or n/a, a reason. Save it as stride-lab/threats-draft.csv and run the checker on it.
id,element,stride,threat,status,reason
T1,member,S,Stolen session cookie lets an attacker upload as the member,open,
T2,api,D,A 2 GB upload fills memory and the API restarts,open,
T3,covers,S,Someone pretends to be the bucket,open,
T4,api,E,,open,
T5,F2,T,Image changed in transit,mitigated,
T6,covers,I,Photos keep GPS EXIF data that reveals where a member lives,open,python3 stride.py check cover-upload threats-draft.csv; echo "exit=$?"PROBLEM T3 (covers/S): S does not apply to a store; file it on the element that acts
PROBLEM T4 (api/E): empty threat statement
PROBLEM T5 (F2/T): mitigated needs a reason
Covered 3 of 17 pairs
Missing: member/R api/S api/T api/R api/I api/E
Missing: covers/T covers/D F2/T F2/I F2/D F5/T
Missing: F5/I F5/D
exit=1The checker is the negative test for your process: it shows that gaps and mistakes are caught. Three kinds of problem appear. T3 files spoofing against a data store, which is not a place where identity is claimed. T4 has a category but no threat, which usually means someone said "elevation, probably" and moved on. T5 marks a threat as mitigated without naming the control, so a reviewer cannot tell whether the control exists. On top of that, 14 pairs are missing. The script exits with code 1, so the same check can run in CI.
06. Step 4: Complete the threat list
Now answer every pair. Work through the worksheet from step 2 one line at a time and write the most likely threat for that element and letter. Where a control that is already in place handles a threat, mark it mitigated and name the control in the reason; the threat still applies, and lesson 5 shows how to prove that the control works. Keep n/a for a pair that genuinely does not apply, with its reason. Several threats can share a pair (T10 and T18 are both information disclosure on the bucket). Compare your list with this solution before you run the check; your wording will differ, but each pair should have a comparable entry. Save it as stride-lab/threats.csv.
id,element,stride,threat,status,reason
T1,member,S,Stolen session cookie lets an attacker upload as the member,open,
T2,member,R,Member denies uploading an abusive cover,open,
T3,api,S,Upload accepted with an expired or forged session token,open,
T4,api,T,Member sets another member's book_id and replaces that cover,open,
T5,api,R,Upload log line has no member id or request id,open,
T6,api,I,Error page shows bucket name and stack trace,open,
T7,api,D,A 2 GB upload fills memory and the API restarts,open,
T8,api,E,Crafted image exploits the image library and runs code in the API,open,
T9,covers,T,Object key is the book title so a new upload overwrites another,open,
T10,covers,I,Photos keep GPS EXIF data that reveals where a member lives,open,
T11,covers,D,Scripted uploads fill the bucket quota and raise the bill,open,
T12,F2,T,Image changed in transit,mitigated,HTTPS only with HSTS; TLS protects integrity
T13,F2,I,Upload URL carries the session token and lands in proxy logs,open,
T14,F2,D,Slow uploads hold connections open until workers run out,open,
T15,F5,T,Image changed between API and bucket,mitigated,SDK uses HTTPS to the bucket
T16,F5,I,Image or signed request read in transit,mitigated,Same HTTPS channel as T15
T17,F5,D,Bucket throttling makes uploads hang because the call has no timeout,open,
T18,covers,I,New objects are public-read so private listings leak,open,python3 stride.py check cover-upload threats.csv; echo "exit=$?"Covered 17 of 17 pairs
exit=0Read a few rows closely. T4, a member changing the book_id to replace someone else's cover, is tampering through the API: the attacker uses a legitimate request but the code fails to check ownership. T10 shows why STRIDE is not only about attackers: a phone photo's GPS metadata can reveal where a member lives without anyone doing anything malicious. T12, T15 and T16 are mitigated, with a reason that names the control (HTTPS). The threat still applies, so lesson 5 shows how to record proof that the control works.
07. Step 5: Summarise for the next step
A threat list is input for decisions, so finish with a short summary. Save this as stride-lab/tally.py and run it.
"""Count open threats per STRIDE letter and list the ones on the API process."""
import collections
import csv
rows = [r for r in csv.DictReader(open("threats.csv")) if r["status"] == "open"]
counts = collections.Counter(r["stride"] for r in rows)
print(f"{len(rows)} open threats:", " ".join(f"{k}={counts[k]}" for k in "STRIDE"))
print("Open threats on the API process:")
for r in rows:
if r["element"] == "api":
print(f" {r['id']:<4}{r['stride']} {r['threat']}")python3 tally.py15 open threats: S=2 T=2 R=2 I=4 D=4 E=1
Open threats on the API process:
T3 S Upload accepted with an expired or forged session token
T4 T Member sets another member's book_id and replaces that cover
T5 R Upload log line has no member id or request id
T6 I Error page shows bucket name and stack trace
T7 D A 2 GB upload fills memory and the API restarts
T8 E Crafted image exploits the image library and runs code in the APIFifteen open threats is a normal result for one feature. Not all of them deserve the same effort. In lesson 4 you take the most serious kind, someone reading or changing another member's data through the API, and expand it into an attack tree. In lesson 5 you rate every threat, give each a mitigation, an owner and a way to verify it.
08. Check your understanding
09. Apply it
For the skill project, copy stride.py, turn your lesson 2 diagram of the three-tier application into a model.json with the same shape, and add a scope for the checkout and payment webhook flows. Write threats.csv until python3 stride.py check checkout threats.csv exits 0. Pay attention to the webhook: ask what happens if someone other than the payment provider calls it.
10. Review prompt
Without looking, write the security property each STRIDE letter breaks, and which letters apply to an external entity, a process, a data store, a log store and a data flow. Then explain in one sentence what you do when a threat seems to need a letter that does not apply to its element.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.