From Threats to Owned, Verifiable Mitigations
Turn a threat list into a ranked register where every entry has a mitigation, a named owner and a way to prove it works, record risk acceptance with an expiry, and add a CI check that fails when the register is incomplete or the application grows an entry point the model does not know about.
Contentsand lesson path
On this page
- The problem
- Step 1: Rate and decide
- Step 2: Write the register and check it
- Step 3: Fix the two entries
- Step 4: Make acceptance expire
- Step 5: Catch design changes in CI
- 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
- Prioritise threats by risk and map each one to a mitigation, an owner and a verification method (test, detection or design review).
- Keep a threat model current by revisiting it on design changes and embedding it in the team's delivery workflow.
01. The problem
After lessons 3 and 4, BookSwap has fifteen open threats and an attack tree that says the ownership check on loans is the most valuable fix. That is analysis, not protection. Threat models fail most often at this point: the list goes into a wiki page, nobody owns the items, and six months later nobody knows which ones were fixed.
This worked example answers question 3 of the four questions, "what are we going to do about it?", and part of question 4, "did we do a good enough job?". You will build a threat register: one entry per threat, ranked by risk, where each entry says what will be done, who is responsible and how anyone can check that it worked. Then you will make the register a file in the repository that CI checks on every pull request, so it stays true as the design changes.
You need Python 3.10 or later and a folder called register-lab.
02. Step 1: Rate and decide
Risk combines how likely a threat is to happen with how bad it would be. The OWASP Risk Rating Methodology uses the standard model, risk = likelihood × impact, and builds each side from factors such as attacker skill, ease of discovery and business impact. A small team can start simpler: rate likelihood and impact from 1 (low) to 3 (high), multiply, and get a score from 1 to 9. The scale is coarse on purpose. Arguing whether something is a 6 or a 7 wastes time; arguing whether it is low, medium or high is a useful conversation.
Then choose a treatment for each threat. NIST SP 800-39 names four kinds of risk response, and they map well onto threats:
- Mitigate: add a control that lowers likelihood or impact, such as an ownership check.
- Accept: decide consciously to live with the risk, because fixing it costs more than the harm. Acceptance needs a person with the authority to accept it and a date to look again.
- Avoid: remove the risky feature or data. Not storing phone numbers avoids leaking them.
- Transfer (NIST says share or transfer): move part of the risk to another party, for example by using a payment provider so card numbers never reach your servers.
Every entry also needs a verification: evidence that the treatment is in place and works. Three kinds cover most cases. A test is an automated check that fails if the control is missing, such as a request for another member's loans that must return 403. A detection is an alert or log rule, verified by replaying the bad behaviour in staging and confirming the alert fires. A design review is a recorded decision, such as an architecture decision record, for controls that are structural and expensive to test automatically, like running the image decoder in a sandbox.
03. Step 2: Write the register and check it
The register is a JSON file. It also lists the entry points the model covers, which step 5 uses. Two entries are incomplete on purpose, the way real first drafts are. Save it as register-lab/register.json.
{
"system": "BookSwap",
"entry_points": ["POST /api/login", "GET /api/loans", "POST /api/covers"],
"threats": [
{"id": "R1", "title": "Any member reads another member's loans",
"likelihood": 3, "impact": 3, "treatment": "mitigate",
"mitigation": "Filter loans by the session member id, never by a query value",
"owner": "api: Priya",
"verify": {"type": "test", "ref": "test_loans.py::test_other_member"}},
{"id": "R2", "title": "Member replaces another member's cover",
"likelihood": 3, "impact": 2, "treatment": "mitigate",
"mitigation": "Check book.owner_id == session member id before saving",
"owner": "TBD",
"verify": {"type": "test", "ref": "test_covers.py::test_foreign_book"}},
{"id": "R3", "title": "Cover photos leak GPS location in EXIF",
"likelihood": 3, "impact": 2, "treatment": "mitigate",
"mitigation": "Strip all metadata when re-encoding the image",
"owner": "api: Priya",
"verify": {"type": "test", "ref": "test_covers.py::test_exif_removed"}},
{"id": "R4", "title": "Crafted image runs code through the image library",
"likelihood": 1, "impact": 3, "treatment": "mitigate",
"mitigation": "Decode images in a sandboxed worker with no network access",
"owner": "infra: Tomas",
"verify": {"type": "review", "ref": "adr/0014-image-sandbox.md"}},
{"id": "R5", "title": "Uploads are not tied to a member in the audit log",
"likelihood": 2, "impact": 2, "treatment": "mitigate",
"mitigation": "Write member id and request id on every upload event",
"owner": "api: Priya",
"verify": {"type": "detection", "ref": "replay upload; alert upload-no-member"}},
{"id": "R6", "title": "Scripted uploads fill the bucket quota",
"likelihood": 2, "impact": 1, "treatment": "accept",
"accepted_by": "eng-head: Ama"}
]
}The checker reads the register, a list of the routes the application really exposes, and today's date (passed in, so the result does not depend on when you run it). It reports missing fields, expired acceptances and unknown entry points, prints the register ranked by risk with ties broken by impact, and exits 1 if anything is wrong. Save it as register-lab/register.py, create the routes file, and run it.
"""Validate a threat register, rank it by risk, and spot unmodelled entry points."""
import json
import sys
from datetime import date
VERIFY = {"test", "detection", "review"}
TREATMENTS = {"mitigate", "accept", "avoid", "transfer"}
def problems_in(threat, today):
found = []
if threat["treatment"] not in TREATMENTS:
found.append(f"treatment must be one of {sorted(TREATMENTS)}")
if threat["treatment"] == "accept":
if not threat.get("accepted_by"):
found.append("accepted risk needs accepted_by")
if not threat.get("review_by"):
found.append("accepted risk needs a review_by date")
elif date.fromisoformat(threat["review_by"]) < today:
found.append(f"acceptance expired on {threat['review_by']}")
return found
if not threat.get("owner") or threat["owner"].upper() == "TBD":
found.append("needs a named owner")
if threat.get("verify", {}).get("type") not in VERIFY:
found.append(f"verify.type must be one of {sorted(VERIFY)}")
elif not threat["verify"].get("ref"):
found.append("verify.ref must point at the test, alert or review")
return found
def main(register_path, routes_path, today_text):
reg, today = json.load(open(register_path)), date.fromisoformat(today_text)
failed = False
for t in reg["threats"]:
for p in problems_in(t, today):
print(f"PROBLEM {t['id']}: {p}")
failed = True
routes = [r.strip() for r in open(routes_path) if r.strip()]
for route in routes:
if route not in reg["entry_points"]:
print(f"REVISIT new entry point not in the model: {route}")
failed = True
ranked = sorted(reg["threats"], key=lambda t: (-t["likelihood"] * t["impact"],
-t["impact"], t["id"]))
print("risk id treatment owner proof")
for t in ranked:
if t["treatment"] == "accept":
who, how = t.get("accepted_by"), f"review by {t.get('review_by')}"
else:
check = t.get("verify", {})
who, how = t.get("owner"), f"{check.get('type')}: {check.get('ref')}"
risk = t["likelihood"] * t["impact"]
print(f"{risk:>4} {t['id']:<2} {t['treatment']:<9} {who:<12} {how}")
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main(*sys.argv[1:4]))printf 'POST /api/login\nGET /api/loans\nPOST /api/covers\n' > routes.txt
python3 register.py register.json routes.txt 2026-11-16; echo "exit=$?"PROBLEM R2: needs a named owner
PROBLEM R6: accepted risk needs a review_by date
risk id treatment owner proof
9 R1 mitigate api: Priya test: test_loans.py::test_other_member
6 R2 mitigate TBD test: test_covers.py::test_foreign_book
6 R3 mitigate api: Priya test: test_covers.py::test_exif_removed
4 R5 mitigate api: Priya detection: replay upload; alert upload-no-member
3 R4 mitigate infra: Tomas review: adr/0014-image-sandbox.md
2 R6 accept eng-head: Ama review by None
exit=1R2 has an owner of "TBD", which means nobody. R6 is accepted but has no review date, so the acceptance would silently last for ever. Both are the most common ways registers decay, and both are now a failing check instead of a comment in a meeting. The ranked list already helps: R1, the loans IDOR, comes first, which matches the attack tree.
04. Step 3: Fix the two entries
Give R2 a named owner and give R6 a review date. In register.json, change R2's "owner": "TBD" and the end of R6's accepted_by line so they read as below, then run the check again.
"owner": "api: Jon",
"accepted_by": "eng-head: Ama", "review_by": "2027-05-01"}python3 register.py register.json routes.txt 2026-11-16; echo "exit=$?"risk id treatment owner proof
9 R1 mitigate api: Priya test: test_loans.py::test_other_member
6 R2 mitigate api: Jon test: test_covers.py::test_foreign_book
6 R3 mitigate api: Priya test: test_covers.py::test_exif_removed
4 R5 mitigate api: Priya detection: replay upload; alert upload-no-member
3 R4 mitigate infra: Tomas review: adr/0014-image-sandbox.md
2 R6 accept eng-head: Ama review by 2027-05-01
exit=0Every entry now answers the three questions a reader has: what will be done, by whom, and how we will know. The ref values point at things that can be opened, such as a test name or a decision record, not at intentions. R5 uses a detection because the risk is about evidence: the useful proof is that an upload without a member id raises an alert, which a staging replay shows.
05. Step 4: Make acceptance expire
An accepted risk is a decision with a shelf life. Run the same check as if it were June 2027, after R6's review date:
python3 register.py register.json routes.txt 2027-06-01 | head -2PROBLEM R6: acceptance expired on 2027-05-01
risk id treatment owner proofIn CI the date is today's, so on 2 May 2027 the pipeline starts failing until someone either renews the acceptance (with a new date and the same accountable person) or chooses another treatment. This turns "we will look at it again" into something that actually happens.
06. Step 5: Catch design changes in CI
A register only stays true if it changes when the design changes. The cheapest signal is the list of entry points. Suppose a developer adds "import a cover from a URL". That is a new entry point, and a risky one: if the server fetches any URL a member gives it, a member can make it fetch internal addresses, a flaw called server-side request forgery (SSRF). Add the route and run the check:
echo "POST /api/covers/import-url" >> routes.txt
python3 register.py register.json routes.txt 2026-11-16 | head -1REVISIT new entry point not in the model: POST /api/covers/import-urlThe pipeline now fails until the model catches up. The developer adds the entry point and a threat entry for it in the same pull request. Save this helper as register-lab/add_r7.py and run it, then check again:
import json
reg = json.load(open("register.json"))
reg["entry_points"].append("POST /api/covers/import-url")
reg["threats"].append({
"id": "R7", "title": "Import-from-URL fetches internal addresses (SSRF)",
"likelihood": 2, "impact": 3, "treatment": "mitigate",
"mitigation": "Allow only https URLs that resolve to public IPs; no redirects",
"owner": "api: Jon",
"verify": {"type": "test", "ref": "test_import.py::test_metadata_ip_blocked"}})
json.dump(reg, open("register.json", "w"), indent=2)python3 add_r7.py
python3 register.py register.json routes.txt 2026-11-16; echo "exit=$?"risk id treatment owner proof
9 R1 mitigate api: Priya test: test_loans.py::test_other_member
6 R7 mitigate api: Jon test: test_import.py::test_metadata_ip_blocked
6 R2 mitigate api: Jon test: test_covers.py::test_foreign_book
6 R3 mitigate api: Priya test: test_covers.py::test_exif_removed
4 R5 mitigate api: Priya detection: replay upload; alert upload-no-member
3 R4 mitigate infra: Tomas review: adr/0014-image-sandbox.md
2 R6 accept eng-head: Ama review by 2027-05-01
exit=0R7 and R2 both score 6, and R7 ranks higher because its impact is higher: reaching internal services is worse than replacing a cover. In a real repository, CI generates routes.txt from the framework's router (Flask's flask routes or a test that lists registered paths), so nobody maintains it by hand. A workflow like the one below runs the check on every pull request. It is shown for reference and was not run here; tools/list_routes.py stands for your framework's route dump, and the checkout action is pinned to a full commit SHA with its tag in a comment.
# .github/workflows/threat-model.yml
name: threat-model
on: pull_request
permissions:
contents: read
jobs:
register:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: List the routes the app exposes
run: python3 tools/list_routes.py > routes.txt
- name: Check the threat register
run: python3 register.py register.json routes.txt "$(date -u +%F)"Routes are one trigger. The others from lesson 1 (a new third party, a new data store, a new kind of personal data) are harder to detect automatically, so teams add them as questions to the pull-request template. Tools such as OWASP pytm or Threat Dragon keep the diagram itself in the repository as code or JSON, so changes to it get reviewed next to the code that caused them.
07. Check your understanding
08. Apply it
Finish the skill project. Turn your payment-flow threats into a register.json with likelihood, impact, treatment, a named owner and a verification for each. Include at least one accepted risk with a review date and one detection. Run register.py against a routes file for your application until it exits 0, and add the workflow so the check runs on every pull request.
09. Review prompt
From memory, list the four risk treatments and the three kinds of verification, with one BookSwap example of each. Then explain how the register in this lesson notices that the design changed, and what it cannot notice on its own.
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.