The March 22 review gave Verdalia nine findings, and a reasonable doubt: are those all of them? A list of principles helps you recognize defects, but it does not guarantee that you have looked everywhere, nor does it say what to fix first. Threat modeling is the method that fills that gap. In this lesson you will learn to draw a system from the security point of view, to walk through it in an orderly way asking what can go wrong, to assess each risk, and to decide what to do about it. The Verdalia team will devote a session to two parts of the store, order confirmation and the admin panel, and will come out of it with a risk register that orders the work for the rest of the module.
One warning: threat modeling is a design technique, and here each threat is described at the level needed to design its defense. In a real system, the model and the measures that come out of it must be reviewed with a security professional and, when they affect personal data or payments, with legal and compliance advice (GDPR, PCI DSS).
What Threat Modeling Is and When to Do It
Threat modeling is a structured analysis of a system to identify what can go wrong in terms of security, before it happens, and to decide what to do about it. It resembles the search for single points of failure in Module 4: there, each element of the diagram was crossed out and we asked what the customer would see. Here, each element is walked through and we ask what someone with bad intentions, or someone who makes a mistake, could do with it.
It is not an audit or a penetration test. It requires no tools: a whiteboard, the system diagram, and the people who know it are enough.
| When | Why |
|---|---|
| When designing a new system or feature | Fixing a design costs a conversation; fixing a system in production, weeks |
| When the architecture changes | Every new component and every new connection brings new threats |
| When the data being processed changes | Starting to store personal data changes the impact of everything |
| Periodically, and after an incident | The system and the threats evolve |
Verdalia is late: it has added seven machines and four technologies without doing it. That is the usual case, and it can be fixed.
The Four Questions
All threat modeling, with any technique, answers four questions:
| Question | What is done | Result |
|---|---|---|
| 1. What are we building? | The system is drawn: components, data, and connections | A data flow diagram |
| 2. What can go wrong? | The diagram is walked through looking for threats, with a guide such as STRIDE | A list of threats |
| 3. What are we going to do about it? | Each threat is assessed and its treatment decided | A prioritized risk register |
| 4. Did we do a good job? | It is checked that the measures exist and work, and that the model is still current | Tests, reviews, and an updated model |
The fourth is the one most often forgotten. A risk register nobody opens again is a document, not a control.
Data Flow Diagrams and Trust Boundaries
The Elements
The architecture diagrams we have used so far show which pieces there are. For security, something else matters: where the data travels and who trusts whom. The data flow diagram has five elements:
| Element | What it represents | Example in Verdalia |
|---|---|---|
| External entity | Someone or something outside our control | The customer, PagoRaíz |
| Process | Code that transforms or moves data | The store, the notification-service |
| Data store | Where data rests | PostgreSQL, Redis |
| Data flow | Data traveling between two elements | The request to confirm an order |
| Trust boundary | The line where the level of trust changes | The step from the internet into the internal network |
Trust boundaries are the most important element. On one side of the line, the data is trustworthy; on the other, it is not. Every flow that crosses a boundary must be checked: who sends it, whether they have permission, and whether the data is valid. Most serious threats appear at those crossings.
Verdalia's Diagram
flowchart LR
subgraph internet["Internet, untrusted"]
customer["Customer"]
employee["Employee"]
end
subgraph internal["Verdalia internal network, a single zone"]
lb["Load balancer"]
store["Store, 3 servers"]
db[("PostgreSQL")]
redis[("Redis")]
queue["RabbitMQ"]
notif["notification-service"]
end
subgraph external["External services"]
payment["PagoRaíz"]
mail["Email provider"]
end
customer -->|"1. HTTPS, confirm order"| lb
employee -->|"HTTPS, panel"| lb
lb -->|"2. Unencrypted HTTP"| store
store -->|"3. Session"| redis
store -->|"4. Order and stock"| db
store -->|"5. HTTPS, charge"| payment
store -->|"6. Message"| queue
queue -->|"7. Message"| notif
notif -->|"8. SMTP"| mail
Each box is a trust zone, and its edges are the boundaries. The diagram shows three things the architecture diagram from Module 4 did not:
- There is a single inner boundary. Once inside the internal network, everything trusts everything. The load balancer, which receives traffic from the internet, is in the same zone as the database.
- Customers and employees come in through the same door. The admin panel shares its address, load balancer, and servers with the store.
- Flows 5 and 8 cross a boundary outward. We also have to ask what data leaves and who it is handed to.
A tip: do not look for the perfect diagram. An incomplete one that people argue over is worth more than an exhaustive one nobody reads.
STRIDE
STRIDE is a guide for answering the second question. Its name gathers the initials of six threat categories. Each one is the negation of one of the properties from the previous lesson:
| Letter | Category | Property it attacks | Question it raises |
|---|---|---|---|
| S | Spoofing | Authenticity | Can someone impersonate another user or another component? |
| T | Tampering | Integrity | Can someone alter data, in transit or at rest? |
| R | Repudiation | Traceability | Can someone deny an action without our being able to prove it? |
| I | Information disclosure | Confidentiality | Can someone see data that is not theirs to see? |
| D | Denial of service | Availability | Can someone keep the system from serving legitimate users? |
| E | Elevation of privilege | Authorization | Can someone do more than they are allowed to? |
Category by Category, in the Store
- Spoofing. Someone gets into a customer's account with a password that customer used on another site and that leaked there. Or a program on the internal network calls the
notification-serviceas if it were the store, because the service does not ask who is calling. - Tampering. The order amount travels in a hidden field of the confirmation form. If the store took it at face value, changing it would be enough to pay less. Any data that arrives from the browser may have been modified.
- Repudiation. A €300 refund shows up as approved by the account “warehouse,” which three people use. None of them remembers doing it, and there is no way to find out.
- Information disclosure. A customer changes the order number in the page address and sees someone else's order, with their name and home address. Or the activity logs keep the email and address of every buyer, in files nobody protects.
- Denial of service. A program launches thousands of searches per minute on a campaign Saturday. It does not have to be an attack: a badly programmed bot from a price comparison site produces the same effect.
- Elevation of privilege. A customer support employee types by hand the address of a panel page their menu does not show them, and the page works.
How It Is Applied
The diagram is walked through element by element, and the six questions are asked. Not every category applies to every element:
| Element | S | T | R | I | D | E |
|---|---|---|---|---|---|---|
| External entity | Yes | Yes | ||||
| Process | Yes | Yes | Yes | Yes | Yes | Yes |
| Data store | Yes | Sometimes | Yes | Yes | ||
| Data flow | Yes | Yes | Yes |
The table is an aid for leaving nothing out, not a rule. A threat that does not fit well under any letter is written down all the same: classifying it matters less than finding it.
Other Approaches
| Approach | What it consists of | Strength | When to use it |
|---|---|---|---|
| STRIDE | Six threat categories applied to each element of the diagram | Simple and systematic | Teams that are starting out; design analysis |
| Attack trees | Start from an attacker's goal and break it down into the paths that lead to it | Goes deep into one specific threat | For analyzing the most serious risks in depth |
| PASTA | Seven-stage process that starts from business objectives and simulates the attacks | Links technical risk with business risk | Organizations with their own security team |
| LINDDUN | Threat categories focused on privacy | Covers what STRIDE only touches on in passing | Systems with a lot of personal data |
| OWASP Top 10 | List of the most frequent risks in web applications, revised every few years | Based on real data from many organizations | As a checklist, not as a method |
The last one deserves a clarification. The OWASP Top 10 says which flaws are the most frequent in general, not which ones your system has. It is a good complement: after the session, you go through the list to see whether anything slipped through. Broken access control, the kind of flaw that lets you see another customer's order, has been among the top entries for years.
Assessing and Treating Risk
Probability Times Impact
A session produces more threats than a team can handle. To order them, each one is assigned two values, and the risk is their product:
The scales must be defined before scoring, in business language. These are Verdalia's:
| Value | Probability | Impact |
|---|---|---|
| 1 | Remote: requires exceptional means and knowledge | Minor: internal nuisance, no effect on customers |
| 2 | Unlikely: requires prior access to the internal network | Moderate: under €1,000, or few customers affected |
| 3 | Possible: within reach of someone with average skills | Serious: thousands of euros, or data of dozens of customers |
| 4 | Likely: easy, and there are reasons to try it | Severe: a campaign day lost, or data of hundreds of customers |
| 5 | Almost certain: happens automatically and massively on the internet | Very severe: leak of the customer base, or loss of the data |
The product is translated into a level with a risk matrix:
| Probability \ Impact | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| 5 | Medium | High | Critical | Critical | Critical |
| 4 | Low | Medium | High | Critical | Critical |
| 3 | Low | Medium | Medium | High | Critical |
| 2 | Low | Low | Medium | Medium | High |
| 1 | Low | Low | Low | Low | Medium |
The thresholds are: critical, 15 or more; high, 10 to 14; medium, 5 to 9; low, under 5. The figures are estimates agreed on between people, not measurements. Their usefulness is to order and to force discussion: if Íker scores a threat with a 2 and Lucía with a 4, one of the two knows something the other does not.
The Four Ways to Treat a Risk
| Treatment | What it consists of | Example in Verdalia |
|---|---|---|
| Mitigate | Apply controls that reduce the probability or the impact | Require a second factor to enter the panel |
| Transfer | Shift the risk to a better-prepared third party | Card data is handled by PagoRaíz, not Verdalia |
| Accept | Take it on consciously, because reducing it costs more than the harm | The physical theft of a server at the provider's data center |
| Avoid | Remove the feature or the data that gives rise to the risk | Drop the bulk export of customers from the panel |
Three nuances:
- No treatment brings the risk to zero. What is left afterwards is called residual risk, and it is written down too.
- Transferring is not washing your hands of it. Verdalia remains accountable to its customers for having chosen its gateway well.
- Accepting is a business decision. Risks are accepted by whoever answers for their consequences, not by whoever discovers them. In Verdalia, Andrés accepts them, and it is put in writing, as in ADR-006.
Verdalia: The March 31 Session
On Wednesday, March 31, the team devoted two hours to modeling. Marta, Íker, and Lucía took part, and Andrés joined for the last half hour to assess the impacts. They chose two parts of the system: the “confirm order” flow, because money and personal data move through it, and the admin panel, because it concentrated four of the nine findings.
The Threats Found
| Id | Threat | STRIDE | P | I | Risk | Planned mitigation | Resolved in |
|---|---|---|---|---|---|---|---|
| TH-10 | Access to the panel from the internet with an old account or a guessed password | S | 4 | 5 | 20 | Removal of surplus accounts, second factor, panel off the internet | Authentication; Network Security |
| TH-01 | A customer views or confirms another customer's order by changing the identifier | E | 4 | 4 | 16 | Check on the server that the order belongs to whoever requests it | Authentication and Authorization |
| TH-11 | Panel routes without permission checks | E | 3 | 5 | 15 | Mandatory check on every route | Authentication and Authorization |
| TH-13 | Bulk export of customers from the panel | I | 3 | 5 | 15 | Avoided: the feature is removed | Data Protection |
| TH-02 | Mass testing of leaked passwords against customer accounts | S | 5 | 3 | 15 | Attempt limit and detection of leaked passwords | Authentication and Authorization |
| TH-04 | Order amount tampered with in the request | T | 3 | 4 | 12 | The server recalculates the amount from the cart | Resolved after the session, with an automated test |
| TH-06 | Flood of automated requests during the campaign | D | 3 | 4 | 12 | Rate limiting on the load balancer | Network Security |
| TH-03 | Reading Redis sessions from an internal machine | I | 2 | 5 | 10 | Password on Redis and network divided into zones | Network Security |
| TH-14 | Malicious deletion or encryption of the database, with untested backups | D | 2 | 5 | 10 | Backups outside the data center, with tested restores | Backups |
| TH-15 | Customer passwords recoverable if the table leaks | I | 2 | 5 | 10 | Store them with a slow, salted function | Authentication and Authorization |
| TH-07 | Personal data in the activity logs | I | 3 | 3 | 9 | Mask it when writing the log | Data Protection |
| TH-12 | Refund approved from a shared account | R | 3 | 3 | 9 | Personal accounts and audit log | Authentication; Data Protection |
| TH-05 | Passwords readable in the unencrypted internal traffic | I | 2 | 4 | 8 | Encrypt the internal traffic that carries credentials | Network Security |
| TH-08 | Unauthenticated calls to the notification-service |
S | 2 | 3 | 6 | API key between the store and the service | Authentication and Authorization |
| TH-09 | Theft of card data | I | 1 | 5 | 5 | Transferred: handled by PagoRaíz | Data Protection |
| TH-16 | Physical theft of a server at the provider | I | 1 | 3 | 3 | Accepted |
What the Session Taught
- Eight of the sixteen threats were new. They were neither among the findings of the 22nd nor among the risks the team had carried over from Module 4. Someone else's order, leaked passwords, the tamperable amount, the customer export, and personal data in the logs appeared by following the flows, not by going over the principles.
- The five critical ones have something in common: none requires getting into the internal network. They are reachable from the internet, with a browser. The threats the team had most in mind, Redis with no password and unencrypted traffic, ended up at the high and medium levels, because they require prior access.
- Threat TH-04 turned out to be half a false positive. Íker checked that the store had already been recalculating the amount on the server since Module 2, when
OrderService.confirmstarted recording the shipping cost. The hidden field was still in the form, but nobody read it. The field was removed and an automated test that proves it was added. - Andrés changed one score and asked one question. He raised the impact of the customer export from 4 to 5: for the business, a leak of the customer base is the worst possible scenario. And he asked what the feature was for. It had been used once in two years. Removing it was the cheapest mitigation of the session.
The Fourth Question
So that the register does not remain a document, the team agreed on three rules:
- Every mitigated threat has a verification: an automated test, a step in the setup checklist, or a dated review.
- The register lives in the repository, in
docs/security/, next to the ADRs. It contains no secrets. - The model is reviewed whenever the architecture changes and, in any case, every six months. The next mandatory review will be the move to the cloud.
The Risk Register in Python
A risk register is a table. Keeping it as data lets you sort it, count it, and check that nobody has entered an impossible value:
from collections import Counter
from dataclasses import dataclass
CATEGORIES = {
"S": "Spoofing", "T": "Tampering", "R": "Repudiation",
"I": "Disclosure", "D": "Denial of service", "E": "Elevation of privilege",
}
THRESHOLDS = [(15, "critical"), (10, "high"), (5, "medium"), (1, "low")]
@dataclass
class Threat:
id: str
description: str
category: str # one STRIDE letter
probability: int # from 1 (remote) to 5 (almost certain)
impact: int # from 1 (minor) to 5 (very severe)
treatment: str = "mitigate"
def __post_init__(self):
if self.category not in CATEGORIES:
raise ValueError(f"{self.id}: unknown category")
if not (1 <= self.probability <= 5 and 1 <= self.impact <= 5):
raise ValueError(f"{self.id}: probability and impact range from 1 to 5")
@property
def risk(self):
return self.probability * self.impact
@property
def level(self):
return next(name for minimum, name in THRESHOLDS if self.risk >= minimum)
REGISTER = [
Threat("TH-01", "View or confirm another customer's order", "E", 4, 4),
Threat("TH-02", "Mass testing of leaked passwords", "S", 5, 3),
Threat("TH-03", "Reading sessions in Redis from the internal network", "I", 2, 5),
Threat("TH-04", "Order amount tampered with in the request", "T", 3, 4),
Threat("TH-05", "Passwords readable in the internal traffic", "I", 2, 4),
Threat("TH-06", "Flood of automated requests during the campaign", "D", 3, 4),
Threat("TH-07", "Personal data in the activity logs", "I", 3, 3),
Threat("TH-08", "Unauthenticated calls to the notification service", "S", 2, 3),
Threat("TH-09", "Theft of card data", "I", 1, 5, "transfer"),
Threat("TH-10", "Access to the panel from the internet with an old account", "S", 4, 5),
Threat("TH-11", "Panel routes without permission checks", "E", 3, 5),
Threat("TH-12", "Refund from a shared account", "R", 3, 3),
Threat("TH-13", "Bulk export of customers from the panel", "I", 3, 5, "avoid"),
Threat("TH-14", "Deletion of the database with untested backups", "D", 2, 5),
Threat("TH-15", "Passwords recoverable if the customers table leaks", "I", 2, 5),
Threat("TH-16", "Physical theft of a server at the provider", "I", 1, 3, "accept"),
]
def prioritize(register):
"""Highest risk first; at equal risk, highest impact first."""
return sorted(register, key=lambda t: (t.risk, t.impact), reverse=True)
print(f"{'Id':6} {'P':>1} {'I':>1} {'Risk':>6} {'Level':8} {'Treat.':11} Threat")
for threat in prioritize(REGISTER):
print(f"{threat.id:6} {threat.probability} {threat.impact} {threat.risk:6} "
f"{threat.level:8} {threat.treatment:11} {threat.description}")
by_level = Counter(threat.level for threat in REGISTER)
print()
print("By level:", ", ".join(f"{by_level[name]} {name}" for _, name in THRESHOLDS))
by_category = Counter(CATEGORIES[threat.category] for threat in REGISTER)
print("By category:", ", ".join(f"{name} {n}" for name, n in by_category.most_common()))Output:
Id P I Risk Level Treat. Threat TH-10 4 5 20 critical mitigate Access to the panel from the internet with an old account TH-01 4 4 16 critical mitigate View or confirm another customer's order TH-11 3 5 15 critical mitigate Panel routes without permission checks TH-13 3 5 15 critical avoid Bulk export of customers from the panel TH-02 5 3 15 critical mitigate Mass testing of leaked passwords TH-04 3 4 12 high mitigate Order amount tampered with in the request TH-06 3 4 12 high mitigate Flood of automated requests during the campaign TH-03 2 5 10 high mitigate Reading sessions in Redis from the internal network TH-14 2 5 10 high mitigate Deletion of the database with untested backups TH-15 2 5 10 high mitigate Passwords recoverable if the customers table leaks TH-07 3 3 9 medium mitigate Personal data in the activity logs TH-12 3 3 9 medium mitigate Refund from a shared account TH-05 2 4 8 medium mitigate Passwords readable in the internal traffic TH-08 2 3 6 medium mitigate Unauthenticated calls to the notification service TH-09 1 5 5 medium transfer Theft of card data TH-16 1 3 3 low accept Physical theft of a server at the provider By level: 5 critical, 5 high, 5 medium, 1 low By category: Disclosure 7, Spoofing 3, Elevation of privilege 2, Denial of service 2, Tampering 1, Repudiation 1
Explanation:
Threatis a dataclass, likeOrderin Module 2. Thetreatmentfield has a default value,"mitigate", because it is the most frequent.__post_init__runs when each object is created and validates the data. A register with a probability of 7 or a made-up category fails on loading, not months later.riskandlevelare computed properties: they are not stored, they are derived. That way it is impossible for the recorded risk not to match its probability and impact. It is the DRY principle, applied to data.THRESHOLDSis sorted from highest to lowest.next(...)returns the first level whose minimum the risk reaches.prioritizesorts by a tuple. At equal risk, the threat with the higher impact goes first: between one that is likely and minor and one that is unlikely and very severe, we prefer to handle the second one first.Countercounts the occurrences of each value, andmost_commonreturns them sorted.
Interpretation:
- There are ten threats between critical and high. They are the module's work plan, in order.
- Seven of the sixteen are information disclosure. It reflects what Verdalia has that is valuable: its customers' data.
- There is only one repudiation and one tampering. It may be that the system is fine in that respect, or that the team did not know how to look for them. A very uneven count invites a second look at the categories with few entries.
Common Mistakes and Tips
- Waiting until the system is finished. Modeling pays off more on a design, when changing costs little.
- Leaving it in the hands of a single person. Whoever develops, whoever operates, and whoever knows the business see different threats.
- Thinking only of sophisticated attackers. Most incidents are due to mistakes, oversights, and automated programs that sweep the internet.
- Arguing for an hour over whether a threat is an S or an E. Write it down and move on.
- Scoring everything as critical. If everything is a priority, nothing is. Scales written down in advance help to avoid it.
- Accepting risks without the business knowing. A risk accepted by someone who does not answer for it is a risk ignored.
- Never opening the register again. Every architecture change should start by asking which trust boundaries it touches.
- Practical tip. If you do not know where to start, choose the flow the money goes through and follow it end to end.
Exercises
Exercise 1: Classify With STRIDE
State the STRIDE category of each threat and the property it attacks:
- A warehouse employee modifies the stock of a product to hide a loss, and the system does not record who made the change.
- An email that appears to come from Verdalia asks customers to confirm their password on a fake page.
- The store's error page shows the SQL query that failed and the name of the database server.
- A customer discovers that, by adding
?role=adminto the address, the panel lets them in.
Exercise 2: “Plant of the Month”
Verdalia is preparing the “Plant of the Month” subscription: the customer signs up, and every month they are charged and sent a plant. On the 1st of each month, a scheduled job goes through the active subscriptions, requests the charge from PagoRaíz with a reference that identifies the customer to the gateway, and creates the orders. Identify at least four threats, score them with the lesson's scales, and propose a treatment for each.
Solutions
Solution to Exercise 1
- There are two threats. The modification is tampering, against integrity. The lack of a record is repudiation, against traceability. It is common for one situation to contain several.
- Spoofing, against authenticity. The one being impersonated is Verdalia. It is not a flaw in the store, but it is a threat to its customers, and there are measures that reduce it, such as configuring the domain's email authentication.
- Information disclosure, against confidentiality. It exposes no customer data, but it helps prepare other attacks.
- Elevation of privilege, against authorization. The server trusts a value sent by the client: it violates complete mediation.
Solution to Exercise 2
| Threat | STRIDE | P | I | Risk | Treatment |
|---|---|---|---|---|---|
| The job runs twice and charges every customer twice | T | 3 | 4 | 12, high | Mitigate: idempotency key per customer and month, such as SUB-<customer>-2027-06 |
| Someone signs up for a subscription on another customer's account | S | 3 | 3 | 9, medium | Mitigate: ask for the password again when subscribing |
| A customer denies having taken out the subscription | R | 3 | 3 | 9, medium | Mitigate: store the date, IP address, and acceptance of the terms |
| Leak of the stored charge references | I | 2 | 4 | 8, medium | Transfer and mitigate: the reference only works with Verdalia's key at PagoRaíz; it is stored encrypted |
| A customer cannot cancel and keeps being charged | D | 2 | 3 | 6, medium | Mitigate: cancellation from the account, with confirmation by email |
The scores may vary: what matters is justifying them. The first threat requires no attacker, and it is the one with the highest risk. Notice that the scheduled job is a new process that acts with no customer in front of it: nobody would see a wrong charge until the complaints arrived. Recurring charges also have legal and compliance implications that must be reviewed with specialized advice.
Conclusion
In this lesson you have learned that threat modeling answers four questions: what we are building, what can go wrong, what we are going to do about it, and whether we did a good job. You have learned to draw a data flow diagram with its trust boundaries, to walk through it with the six STRIDE categories, to assess each risk as the product of its probability and its impact, and to choose between mitigating, transferring, accepting, or avoiding it. You have also met other approaches and the role of the OWASP Top 10 as a checklist.
In Verdalia, a two-hour session produced sixteen threats, eight of them unknown until that day. One was avoided by removing a feature, another was transferred to PagoRaíz, another was accepted, and a fourth, the tamperable amount, turned out to be already resolved. The register makes it clear where to start: the five critical threats are reachable from the internet, and four of them have to do with who can get in and what they can do once inside.
An old account that is still active, a customer who sees someone else's order, routes that check nothing, passwords tried by the thousands. All are variants of two questions: who you are and what you are allowed to do. We will answer them in the next lesson: “Authentication and Authorization.”
