Threat modelling
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
Threat modelling is thinking through what could go wrong with a system while you design it, so you can fix problems before attackers find them. Follow the four questions on one small online bakery: draw the system and its trust boundary, name what to protect and from whom, use STRIDE to find six kinds of threat, write each one into a Python threat list with its fix, then decide a response for every threat and check the work.
Four questions
Threat modelling means thinking through what could go wrong with a system during design, to fix problems before attackers find them. It follows four questions: what are we working on, what can go wrong, what will we do, did we do enough?
threat model a careful look at what could go wrong
with a system, done while designing it
Q1 What are we working on?
Q2 What can go wrong?
Q3 What are we going to do about it?
Q4 Did we do a good enough job?اقرأ الدرس خطوة بخطوة
Four questions
Threat modelling means thinking through what could go wrong with a system during design, to fix problems before attackers find them. It follows four questions: what are we working on, what can go wrong, what will we do, did we do enough?
threat model a careful look at what could go wrong with a system, done while designing it Q1 What are we working on? Q2 What can go wrong? Q3 What are we going to do about it? Q4 Did we do a good enough job?Q1: draw the system
First, draw what you are building. Our example is a small online bakery. A customer (outside the shop) sends orders to the web app (a process), which saves them in a database (a data store). Arrows show the data flows.
Q1 What are we working on? a data flow diagram has four kinds of part: external entity the customer process the web app data store the database data flow orders, queries (the arrows)What we protect, from whom
Next, name the assets: customer details, password hashes and orders in the database, and the app staying online. Then ask who might cause harm: criminals after data or money, pranksters, or a careless insider. The attacker block stands for all of them.
assets what is worth protecting database customer details, password hashes, orders web app the shop staying online who criminals after data or money pranksters, a careless or unhappy insiderThe trust boundary
A trust boundary is where data crosses between places we trust differently. Everything arriving from the internet could come from anyone, the attacker included. Most threats cluster where data crosses this line, so look there first.
trust boundary where the level of trust changes outside the internet: customer, attacker inside the web app and its database rule treat every message that crosses as possibly hostile until checkedQ2: STRIDE
To answer "what can go wrong?", check each part against STRIDE: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service, Elevation of privilege. Each letter breaks one security property, such as integrity or availability.
Q2 What can go wrong? S Spoofing breaks authentication T Tampering breaks integrity R Repudiation breaks non-repudiation I Information disclosure breaks confidentiality D Denial of service breaks availability E Elevation of privilege breaks authorizationS: spoofing the sign-in
Spoofing: someone signs in as a customer using a stolen or guessed password. We write the threat into our list, a Python dict, with its fix: multi-factor authentication (MFA), so a password alone is not enough.
S spoofing pretending to be someone else where sign-in, crossing the boundary mistake a password is the only proof fix MFA: a second proof, such as a code line 2 "S login": "MFA"T: tampering with an order
Tampering: the order's price is changed before it reaches the app, for example by editing the page in the browser. The mistake is trusting a price the browser sends. The fix: the app looks up every price itself.
T tampering changing data without permission where the order data flow mistake trusting a price sent by the browser fix the server sets the price from its list line 3 "T price": "own price"R: "I never ordered that"
Repudiation: a customer says "I never placed that order" and nobody can prove what happened. The fix is an audit log: the app records who did what and when, and keeps that record safe from changes.
R repudiation denying an action, with no proof where the web app mistake no record of who did what fix an audit log: who, what, when line 4 "R deny it": "audit log"I: a data leak
Information disclosure: customer details leak from the database or its queries. One fix is least privilege: the app gets only the access it needs, so one bug cannot expose everything. Passwords are stored only as hashes, never as plain text.
I information disclosure data reaches the wrong people where the database and its queries mistake the app may read and change everything fix least privilege: only the access it needs store password hashes, never passwords line 5 "I leak": "least access"D and E: floods, admin pages
Denial of service: a flood of requests makes the shop too busy for real customers; fix it with rate limits. Elevation of privilege: a customer reaches the staff admin page; fix it by checking their role on every request.
D denial of service the shop stops answering fix rate limits per user E elevation of privilege a customer opens a staff page fix check the role on every request lines 6, 7Q3: decide what to do
For each threat you choose a response. Mitigate: add a fix, as we did. Eliminate: remove the risky feature. Transfer: make another party responsible, like a payment provider. Accept: write down why the risk is small enough.
Q3 What are we going to do about it? mitigate add a control (all six here) eliminate remove the feature that causes it transfer make another party responsible accept record why the risk is acceptableQ4: check the work
Finally, check: every threat on the list has a decision, and every fix is tested. Our program prints 6, one entry per threat. A threat model is never finished: run it again whenever the design changes.
Q4 Did we do a good enough job? every threat has a decision? yes every fix tested? do it design changed? model it again $ python threats.py 6
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01What are the four questions of threat modelling?
These four questions, from the Threat Modeling Manifesto and used by OWASP, give every threat model the same shape: the system, the threats, the responses, and a check.
02In the bakery's diagram, where should you look first for threats?
A trust boundary is where data moves between places trusted differently. Anything that crosses it from the internet could come from anyone, so threats cluster there.
03A customer changes the price of a cake in their browser before sending the order. Which STRIDE threat is this?
Tampering is changing data without permission; it breaks integrity. The fix is for the app to set the price from its own list, never trusting a price the browser sends.
04A customer says "I never placed that order" and nobody can prove otherwise. Which fix helps most?
This is repudiation. A protected audit log records actions so they can be checked later.
05The shop still takes card payments, but signs a contract making a payment provider responsible for keeping card details safe. Which response is that?
Transfer gives contractual or financial responsibility to another party. It is not eliminate: the card feature still exists, only who is responsible for it has changed. Mitigate adds a control, eliminate removes the feature, accept records why the risk is acceptable.
المسرد
- Threat modelling
- Thinking through what could go wrong with a system, usually while designing it, and deciding what to do about each problem. NIST calls it a form of risk assessment that looks at both the attack and the defence sides.
- Data flow diagram (DFD)
- A simple drawing of a system: external entities (like a customer), processes (like a web app), data stores (like a database) and arrows for the data flowing between them.
- Trust boundary
- A line on the diagram where data moves between places trusted differently, such as from the open internet into the shop's own app.
- Asset
- Something worth protecting, such as customer details, password hashes, orders, or the shop staying online.
- STRIDE
- Six kinds of threat: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service and Elevation of privilege. Each breaks one security property.
- Least privilege
- Giving each person or program only the access it needs to do its job, so one mistake cannot expose everything.
- Audit log
- A protected record of who did what and when, so actions can be checked later.
- Mitigate, eliminate, transfer, accept
- The four responses to a threat: add a control, remove the feature, make another party responsible by contract, or record why the risk is acceptable.
الملاحظات والمصادر
- STRIDE is one popular way to brainstorm threats, created at Microsoft. Others exist (attack trees, LINDDUN for privacy, PASTA). What matters is looking at each part and each data flow in a steady, repeatable way.
- A real shop has more parts (a payment provider, staff laptops, a hosting company) and more threats than one per letter. The example keeps one threat per letter so each idea is clear.
- Each fix lowers a risk; none removes it. MFA is strongest when it is phishing-resistant (CISA). Logs must themselves be protected. Rate limits slow floods but large attacks also need help from the hosting provider.
- Mitigate, eliminate, transfer and accept are the four responses listed in the OWASP Threat Modeling Cheat Sheet. Accepting a risk is a decision that is made on purpose and written down; it is not the same as ignoring the risk.
- NIST SP 800-154 is still a draft. NIST SP 800-218 (the SSDF) asks software makers to use threat modelling or similar risk modelling while designing software.
- This course is about defence. It names a threat only at the level of the mistake and its fix, and never shows how to attack a real system.
- OWASP Threat Modeling Cheat Sheet
- OWASP: Threat Modeling Process
- Threat Modeling Manifesto
- NIST CSRC Glossary: threat modeling
- NIST SP 800-154 (Initial Public Draft): Guide to Data-Centric System Threat Modeling
- NIST SP 800-218: Secure Software Development Framework (SSDF) v1.1
- NIST CSRC Glossary: least privilege
- Microsoft: Threat Modeling Tool threats (STRIDE)
- OWASP Top 10: A01:2021 Broken Access Control
- OWASP Logging Cheat Sheet
- OWASP API Security: API4:2023 Unrestricted Resource Consumption
- CISA: More than a Password (multi-factor authentication)
- CISA: Secure by Design
اختبار يتاح بعد الخطوة الأخيرة.