Threat modelling a web shop
Table Bay Online and everyone in it are invented for this course, and so is every customer, order, supplier and address in the examples. Real standards and laws, such as OWASP's guidance and POPIA, are named only for what they themselves say.
1. Why model threats before you build
Palesa's first draft of the new shop works. Every page loads, the cart fills and the test orders go through. Naledi Mahlangu, who owns Table Bay Online, asks the question every owner should ask before launch: "What could go wrong with this, and what are we doing about it?" Nobody can answer that by clicking through the pages. It needs a threat model.
A threat model is a short, structured description of three things: what you are building, what can go wrong with it, and what you will do about each thing that can go wrong. OWASP's Threat Modeling Cheat Sheet puts the whole method as four questions, taken from the Threat Modeling Manifesto:
- What are we working on?
- What can go wrong?
- What are we going to do about it?
- Did we do a good enough job?
Those four questions are this whole course in miniature. Module 0 and this module answer the first: you set up the shop and now describe the finished shop as a picture of its parts and the data that moves between them. This module answers the second, using a prompt called STRIDE. Modules 2 to 7 answer the third, one control at a time. Module 8 answers the fourth with a review of the shop you have built.
Cheaper to design in than to bolt on
OWASP's cheat sheet says threat modelling "is ideally performed early in the SDLC, such as during the design phase". SDLC is the software development life cycle: the steps from an idea to running software and on through its changes. Early is the right moment because a control is a design decision before it is code. When the order page is first designed, "a customer may see only their own orders" is one condition in one database query. Added after launch, it means finding every page, export and admin screen that ever reads an order, and hoping none was missed.
That is why you model the shop now, as it will be when finished, before you build the rest of it. Module 0 gave you a skeleton: a product list, a product page and a cart. The finished shop will also have accounts and sign-in, staff pages, search, product pictures, checkout, a payment provider, a courier and a security log. You know all of that from the course's design, so you can model it today and let the model decide which controls Modules 2 to 7 must build, and in what order. The threat model is the plan the rest of the course carries out.
A map, not a certificate
A threat model does not prove that a shop is safe. It records what you looked at, what you decided and why, so that others can check your thinking and so that you can come back to it when something changes. OWASP says a threat model "should be maintained, updated and refined alongside the system", and that it is "not something that is performed once and never again". When Table Bay Online later adds a page for Jason to import a supplier's price list, that page is a new place where outside data enters, and the model is opened again.
It is also not a list of attacks, a penetration test or a guide to breaking anything. You model your own design, as its builder, to decide how to protect it. Every threat in this module is written as what could go wrong, in plain words, beside the control that prevents it.
What the law asks for, and what good practice adds
Table Bay Online keeps its customers' names, delivery addresses, phone numbers, email addresses and order histories. That makes it a responsible party under the Protection of Personal Information Act 4 of 2013 (POPIA), and section 19 sets out what it must do to keep that information secure.
A responsible party must take reasonable measures to "(a) identify all reasonably foreseeable internal and external risks to personal information in its possession or under its control" and "(b) establish and maintain appropriate safeguards against the risks identified". It must also regularly verify that the safeguards are effectively implemented, and keep them updated in response to new risks or deficiencies.
Protection of Personal Information Act 4 of 2013, section 19(2)POPIA does not name threat modelling or any other method. What it requires is the outcome: foreseeable risks identified, internal ones as well as external, and safeguards put in place against them. A threat model is good practice, not a legal requirement, but it is one of the clearest ways to show that a web shop has done exactly what section 19(2)(a) and (b) describe. Section 19(3) adds that a responsible party must have due regard to generally accepted information security practices, and OWASP's guidance is among the most widely used for web applications. OWASP itself is an open community project: its documents impose no South African legal duty.
Who takes part
A threat model for a small shop is not a long document written by one person. It is better made in a working session of an hour or two with the people who know the shop: Naledi, who knows what matters to the business, Jason, who knows how the shop is used every day, Palesa, who knows the code, and you, who lead the session and write it up. Each sees threats the others miss. Jason, for example, knows that customers sometimes phone to ask for an order to be changed, which is exactly the kind of request someone could fake.
2. Assets
An asset is anything of value to the business that could be harmed. In a web shop that is more than data. It includes the accounts that unlock data, the money that moves through orders and refunds, the shop's ability to keep trading, its good name, and the secrets that hold the system together.
For each asset, ask which kind of harm matters. Security people use three words for this:
- Confidentiality
- Only the people who should see something can see it. A customer's address seen by another customer is a loss of confidentiality.
- Integrity
- Information is correct and changed only by those allowed to change it. An order marked paid when no money arrived is a loss of integrity.
- Availability
- The shop and its information are there when needed. A shop that cannot take orders on a Saturday morning has lost availability.
Table Bay Online's main assets
Here are the six asset groups the finished shop holds, ranked by the harm their loss would do to the business. The ranking is a judgement, made with Naledi, and the reasons matter more than the order.
| Rank | Asset | Where it lives | The harm that matters most | Why it ranks here |
|---|---|---|---|---|
| 1 | Customers' personal information: names, delivery addresses, phone numbers, email addresses, order histories, account passwords (stored as hashes) | The database, data/shop.sqlite, and its backups | Confidentiality, then integrity | Harm to real people, a legal duty under POPIA to protect it and to report a compromise, and the loss of customers' trust. It cannot be taken back once it is out. |
| 2 | Staff and admin accounts (Jason's and Naledi's) | The users table and the sessions of people signed in | Confidentiality and integrity | An admin account is a key to almost every other asset: customer records, products, orders, refunds and the log. |
| 3 | Orders, payments and refunds | The orders, order_items, payments and refunds tables | Integrity | Money. An order shipped without payment, or a refund larger than what was paid, is a direct loss. |
| 4 | The shop's secrets: the webhook secret it shares with the payment provider, the server's access keys, and the session ids that stand for people signed in | The configuration on the server, and the session store | Confidentiality | Whoever holds a secret can act as its owner. The webhook secret could make a fake payment message look real. |
| 5 | The ability to trade | The server, the shop's code, the database and the connection to the payment provider | Availability | A shop that is down loses sales and leaves customers unsure whether their orders went through. Serious, but usually recoverable. |
| 6 | Reputation | In customers' and makers' minds | All three, through the others | Rarely harmed directly, but every other loss on this list ends up here. |
Two judgements in the table are worth noticing. First, staff accounts rank above the order records, although orders hold the money. That is because an account is not just an asset in itself: it is a key to other assets, and an admin account opens nearly all of them. Second, the ability to trade ranks below the secrets. A shop that is down for an hour loses some sales. A leaked webhook secret could let money stories be told to the shop that never happened, quietly, until it is noticed.
The asset that is not on the list
Card numbers do not appear in Table 1, and that is deliberate. Customers pay on the hosted payment provider's own page, so their card details never reach Table Bay Online's server, and the shop's database has no column for a card number, a card verification value or an expiry date. The safest data is data you never hold. Removing an asset altogether is a control in its own right, and Module 5 builds the checkout so that it stays that way.
Ranking without numbers
You do not need a formula to rank assets in a small shop. For each one, ask five questions in plain words: how badly would its loss hurt customers, does the law require us to protect it or report its loss, how much money could we lose, would we stop trading, and how long would it take to recover? An asset with several bad answers is high. One with mostly mild answers is low. Write the reason beside each rank, because the reason is what Naledi needs to check your judgement, and what you need when the shop changes.
3. Actors
An actor is anyone or anything that interacts with the shop: people, and other computer systems. Listing the actors does two jobs. It says what each one is allowed to do, which becomes the rules that Module 2 builds, and it reminds you that threats come from more places than an outsider on the internet.
| Actor | Who or what | What they may do |
|---|---|---|
| Visitor | Anyone with a browser, not signed in | Browse products, search, fill a cart, register, sign in. |
| Customer | A signed-in account holder, such as Thandeka Mtshali or Riaan Delport | Everything a visitor may do, check out and pay, and see their own account and their own orders. Never anyone else's. |
| Staff | Jason Petersen, operations and customer service | The staff pages: see orders and move them through their allowed steps, such as packed and shipped. |
| Admin | Naledi Mahlangu, owner and information officer | Everything staff may do, and add and edit products, upload product pictures, make refunds and read the security log. |
| Payment provider's server | The hosted payment provider's own computers | Send the shop a signed message at its webhook address saying how a payment went. Nothing else. |
| Courier's booking API | The courier's system the shop calls to book deliveries | Receive a delivery's name, address and phone number from the shop, and return a booking reference. |
| Supplier feeds | Stock information from makers such as Saltpan Ceramics and Dwarsrivier Linen | Supply product and stock details, which the shop treats as untrusted input. |
| Developer | Palesa Mokwena, trading as Mokwena Web Studio | Change the shop's code and deploy it, and reach the server and its data to do so. |
| Host | The company that rents Table Bay Online its virtual private server | Run the machine the shop lives on, with the access to it that this needs. |
| Outsider | Anyone else, with no account and no business with the shop | Nothing beyond what a visitor may do. |
What attackers want
It helps to know what someone with bad intentions would want from a shop like this, because it tells you which assets draw attention. Usually it is one of five things:
- customers' personal information, to sell or to use in scams that sound convincing because they quote a real order
- staff and admin accounts, because they unlock everything else
- money, through orders that look paid when they are not, or refunds that should never have been made
- the server itself, to use its resources for something else
- simply disruption.
You do not need to know how any of this is done to protect against it. You need to know what is worth protecting and where it can be reached, and that is what the model records.
Insiders, customers and honest mistakes
The most common mistake in a first threat model is to picture only an outsider on the internet. POPIA's own words are "internal and external risks", and for good reason. Three kinds of internal risk belong in every web shop's model:
- The signed-in customer. A customer is trusted with their own account and nothing more. A customer who changes the number in the address bar of their order page is an actor the model must cover. Module 2 builds the check that answers it.
- Staff accounts used by someone else. Jason's laptop could be stolen while he is signed in, or his password could be reused from another site that leaked. The account does what Jason may do, whoever is at the keyboard.
- Honest mistakes. A refund typed with an extra zero, a customer list exported to a personal email address to work on at home, a product description pasted from a supplier's site with its markup still in it. None is an attack, and each can do real harm.
Actors who are operators
Four actors process Table Bay Online's personal information on its behalf: the host, the payment provider, the courier's booking API and Palesa. POPIA calls such a party an operator. Section 21 requires the responsible party to ensure, in a written contract, that each operator establishes and maintains the security measures section 19 refers to, and section 21(2) requires an operator to notify the responsible party immediately where there are reasonable grounds to believe that personal information has been accessed or acquired by an unauthorised person. For the threat model, that means each operator is both an actor and a dependency: the shop relies on their security as well as its own. Module 7 returns to what happens when one of them reports a compromise.
4. Data flows and trust boundaries
Now draw the shop. Not its screens, but its data: where information enters, where it is processed, where it is stored and where it leaves. The usual picture is a data-flow diagram, and OWASP describes it as a way to "visually model a system, its data flows, and interactions with external entities". It needs only five kinds of shape:
- External entity
- Something outside the shop that sends or receives data: a browser, the payment provider, a supplier. Drawn as a plain box.
- Process
- Code that does something with data: the shop's PHP. Drawn as a rounded box.
- Data store
- Where data rests: the database, the uploads folder, the logs.
- Data flow
- Data moving between the others. Drawn as an arrow, labelled with what moves.
- Trust boundary
- A dashed line wherever data crosses from somewhere the shop trusts less into somewhere it trusts more.
What a trust boundary is
A trust boundary is any line where data or a request passes from something the shop trusts less into something it trusts more, or from one owner's control into another's. The shop's code trusts its own database. It must not trust anything a browser sends, because whoever runs the browser decides what it sends. So the line between the browser and the server is a trust boundary, and everything that crosses it must be checked on the inside, by the code that is about to rely on it.
That last point is the rule the whole course rests on: check data where it crosses into trusted code, on the trusted side. A check in the browser, such as a form field marked required or a JavaScript limit on a quantity, is a convenience for honest customers. It proves nothing to the server, because the browser is on the other side of the boundary. In Module 0 you met a small example: the cart takes each price from the database, never from the form, because a price in a form field would arrive from the untrusted side.
The finished shop's boundaries
Figure 2 numbers six places where data crosses the boundary around the server. Here is what crosses at each, and what the shop must therefore check.
| # | Boundary | What crosses it | What the shop must check on its side |
|---|---|---|---|
| 1 | Customer's browser to the shop | Every page request: the address with its values, form fields including hidden ones, the session cookie, and the customer's return from the payment page | Who is signed in, whether they may do this to this record, that every value is the kind expected, and that nothing typed is ever treated as code |
| 2 | Staff browser to the shop | The same, plus admin forms and uploaded product pictures | All of the above, plus the role on every staff page and the real content of every uploaded file |
| 3 | Payment provider to the shop | A message at the webhook address saying how a payment went | That the message is really from the provider, and that its order, amount and currency match the shop's own order |
| 4 | The shop to the courier | A customer's name, delivery address and phone number | That only what a delivery needs leaves, over an encrypted connection, to an operator with a written contract |
| 5 | Supplier feeds to the shop | Product names, descriptions and stock numbers | That every value is the kind expected, and that a description is shown as text, never as markup |
| 6 | The developer and the host to the server | Code changes, configuration and direct access to the files and data | Who has access, with what, and that live customer data is never copied into development |
Two more lines are worth drawing, although they sit inside the server. The first is between privilege levels: the staff pages run in the same code as the customer pages, but a request that reaches them must come from someone with the right role. A boundary does not have to be a network cable. The second is the database itself. Data that comes back out of the database may have been typed by a visitor last month, so when the shop prints it on a page, it treats it with the same care as data typed a second ago. Module 3 builds that care into every page.
Worked example: tracing one checkout across its boundaries
Thandeka Mtshali buys a linen apron and a stoneware mug. Follow the data, step by step, through the finished shop, and name each boundary it crosses.
- She presses "Pay now". Her browser sends a form to the shop's checkout address. It carries her session cookie and the form's token. Boundary 1. The shop must check that she is signed in, that the form came from her own session, and that the cart in her session holds products that exist. It takes every price from its own database, never from the form.
- The shop records a pending order. It writes the order and its items to the database: the reference, her user id, the status
pendingand the total. This is inside the boundary, and the shop trusts its own database. - The shop hands her to the payment page. It sends her browser to the hosted payment provider with the order reference and amount. Data leaves the shop here, but only what the provider needs: no address, no history.
- She types her card details on the provider's page. This happens entirely outside Table Bay Online's boundary. The card details go from her browser to the provider and never touch the shop's server.
- The provider's server tells the shop. It sends a signed message to the webhook address: this order reference, this amount, this currency, paid. Boundary 3. The shop must check that the message really came from the provider and that its details match the pending order before it changes anything.
- She comes back. The provider sends her browser back to the shop's return address. Boundary 1 again. This arrives through her browser, so the shop must not treat it as proof of payment. It shows "We are confirming your payment" and lets the webhook decide.
- The shop books the delivery. When Jason packs the order, the shop sends her name, address and phone number to the courier's booking API. Boundary 4. Only what the delivery needs leaves, to an operator under contract.
What the trace shows: one ordinary checkout crosses the boundary four times, and at each crossing the shop has a different question to answer. Notice that the payment result arrives twice, by two routes: once through the customer's browser and once from the provider's server. They do not deserve the same trust. The next section's second worked example shows why.
5. STRIDE as a prompt
The second question, "What can go wrong?", is the hardest to answer from a blank page. STRIDE gives you six prompts to ask at each boundary. OWASP describes it as "a mature and popular threat modeling technique and mnemonic originally developed by Microsoft employees". It is a thinking aid. It is not a legal standard, it is not a checklist that proves anything, and it does not need special software.
| Letter | Threat | In plain words | What it threatens |
|---|---|---|---|
| S | Spoofing | Someone or something pretends to be someone or something else. | Authentication: knowing who you are dealing with |
| T | Tampering | Data is changed, on its way in, at rest or on its way out, by someone not allowed to change it. | Integrity |
| R | Repudiation | Someone denies doing something, and nobody can show that they did. | Being able to show who did what |
| I | Information disclosure | Information reaches someone who should not have it. | Confidentiality |
| D | Denial of service | The shop, or part of it, stops working for the people who need it. | Availability |
| E | Elevation of privilege | Someone does something their role does not allow. | Authorisation: deciding what each person may do |
How to use it
Take each place where data crosses a boundary, one at a time, and ask the six questions about it: could someone pretend to be someone else here, change something they should not, deny what they did, see what they should not, stop it working, or do more than their role allows? Not every letter applies everywhere. The product list, for example, shows only what anyone may see, so information disclosure barely applies to it. Write down only the threats that are real for that entry point, each in a sentence of plain words, and move on.
An entry point is a place where a request or data enters the shop: a page address, a form, the webhook, a feed, an upload. In the finished shop, every route in the route table is an entry point, and so is each outside feed. Section 6 turns each entry point's threats into controls, and in the practical work you take every one of them through STRIDE.
Most real findings sit at the boundaries, so start there. And write threats as what could go wrong, not as how. "Another customer's order could be shown" is a threat you can design a control for. Working out exactly how someone would make it happen adds nothing to the defence and is not the job.
Worked example: STRIDE over the payment return address and the webhook
The checkout trace showed the payment result arriving twice: through the customer's browser at the return address, and from the provider's server at the webhook. Naledi asks whether it matters which one the shop believes. Take each through STRIDE.
| Prompt | Return address (through the browser) | Webhook (from the provider's server) |
|---|---|---|
| S, Spoofing | Anyone can open the return address in a browser, paid or not. Nothing in the visit proves who sent it. | Anyone who learns the webhook address could send a message there that claims to be the provider. The provider signs each message with a secret it shares only with the shop, so the shop can tell a real one from a pretend one. |
| T, Tampering | Every value in the address can be changed by whoever runs the browser, including any that look like a status or an amount. | A message could arrive with an amount that differs from the order. The signature covers the whole message, and the shop also checks the amount, currency and reference against its own order. |
| R, Repudiation | A customer could say they paid because they reached the return page. The page proves only that the browser arrived there. | The provider's reference for each payment is recorded once, so there is a clear record of which payment paid which order. |
| I, Information disclosure | The return page must not show order details to whoever opens it. It shows only that the payment is being confirmed. | The webhook's answer to the provider says only "received" or "refused", nothing about the shop's data. |
| D, Denial of service | Repeated visits do nothing, because a visit changes nothing. | Many messages arriving must be cheap to refuse. A message that fails its signature check is refused before any other work is done. |
| E, Elevation of privilege | A visit must never be able to change an order's status. | A verified message may do exactly one thing: move one pending order to paid, through the order's allowed steps. Nothing else. |
The conclusion: the return address arrives through the untrusted browser and can prove nothing, so it never changes an order. It only shows the customer a "confirming your payment" page. The webhook comes from the provider's server and, once its signature is verified and its details match, is the only thing allowed to mark an order paid. The same message arriving twice, which providers do on purpose when they are unsure a message was received, records one payment, not two. This one decision, made now in the threat model, is the spine of Module 5, which builds it.
6. From threats to controls
The third question is "What are we going to do about it?" OWASP's cheat sheet gives four possible answers, from the threat-modelling writer Adam Shostack. Each threat gets one of them, and the choice is written down.
| Response | What it means | A Table Bay Online example |
|---|---|---|
| Mitigate | Reduce the likelihood or the harm with a control. | The ownership check on the order page, so another customer's order is never shown. |
| Eliminate | Remove the feature or part that causes the threat. | Never taking card details on the shop's own pages, so there is no card data to lose. |
| Transfer | Give the responsibility, by contract or otherwise, to someone better placed. | The payment provider handles card entry. OWASP notes that transferring a risk "does not itself reduce the likelihood or harmful consequences": the contract must still be checked. |
| Accept | Knowingly live with the threat, because the other options are not acceptable for now. | Launching with two-step sign-in designed but not yet fully built, recorded with an owner and a date (Modules 2 and 8). |
Accepting a risk is a legitimate answer, but only when it is written down, with who accepted it, why and when it will be looked at again. An unrecorded risk is not accepted. It is just unnoticed.
Where to spend effort first
A small shop cannot build everything at once, so the threats need an order. OWASP says that "in theory, ranking should be based on the mathematical product of an identified threat's likelihood and its impact", and adds that both can be hard to calculate. For a small shop, three levels of each, High, Medium and Low, are enough. Impact comes from the assets: a threat to customers' personal information or to admin accounts is high. Likelihood comes from how easy and how tempting the threat is: a threat any visitor could try from a browser, against something valuable, is likely.
Figure 4 places nine threats. The two in the top right are the most important. Another customer's order (A) is the classic access-control mistake: any signed-in customer could stumble on it, and it exposes personal information. A guessed staff password (B) is likely because people reuse passwords, and its impact is high because staff accounts unlock so much. Both are answered in Module 2. Three threats sit at high impact and medium likelihood: an order marked paid without payment (C, Module 5), text typed into the search being treated as part of a database query (D, Module 3) and an uploaded file being run as code (E, Module 3). Each needs a specific mistake to exist, but each would be serious.
The backbone of the course
Put the boundaries, the threats and the responses together, and you have the table that tells Modules 2 to 7 what to build. Here it is for the main groups of entry points. In the practical work you extend it to every route of the finished shop.
| Entry point | Asset at stake | Main threats | Control | Module |
|---|---|---|---|---|
| Sign-in and registration | Accounts | S: guessed or reused passwords. I: the page revealing which emails have accounts. | Slow salted password hashes, an attempt limit, one message for every failure, safe sessions, two-step sign-in designed for staff | 2 |
| A customer's account and orders | Personal information | I: another customer's order shown. S: a session taken over. | Every record fetched by its id and its owner, session cookie settings, a new session id at sign-in | 2 |
| Staff and admin pages | Everything | E: a customer or visitor reaching a staff page. T: a request forged from another site. R: changes nobody can trace. | The role checked on the server on every page, a form token, the security log | 2, 4, 7 |
| Search, forms and product text | Personal information, the ability to trade | T and I: typed text treated as part of a query, or as markup in a page. | Validation on the way in, prepared statements, encoding on the way out | 3 |
| Product picture uploads | The server | E: an uploaded file run as code. D: very large files. | A real content check, a size limit, a generated name, storage outside the web root | 3 |
| Checkout and the payment return | Orders and money | T: prices or amounts changed. S: the return address taken as proof of payment. | Prices from the database, a pending order, a return page that changes nothing | 5 |
| The payment webhook | Orders and money | S: a message pretending to be from the provider. T: a changed amount. R: the same payment counted twice. | Signature verification, amount and reference checks, each payment recorded once, the order's allowed steps | 5 |
| The server and its configuration | Secrets, everything | I: secrets in the code, error details on screen. E: the server run with more rights than it needs. | Secrets outside the code, safe error pages, safe headers, least privilege, tested backups | 4, 6 |
| All of the above, afterwards | Everything | R: nobody can show what happened. Attacks nobody notices. | A security log of sign-ins, payments and admin actions, and alerts a person sees | 7 |
Notice how often Module 2 appears at the top. Sign-in, sessions and access control protect the two highest-ranked assets and answer the two highest-ranked threats, which is why they come first in the build.
The one-page threat model
A threat model that runs to forty pages is rarely read and almost never kept up to date. For a shop of this size, one page is enough, and it should hold:
- What is being modelled, by whom, and on what date
- The assets, ranked, with a reason for each rank
- The actors, including insiders, customers and operators
- A reference to the data-flow diagram and its numbered boundaries
- The entry points ranked by likelihood and impact, each with its control and the module that builds it
- The three controls to build first, and why
- Any risk knowingly accepted, with its owner and the date to look at it again
- What will trigger a review: a new feature, a new outside party, an incident, or a set date
Common mistakes
- Modelling only outsiders. The signed-in customer, staff accounts in the wrong hands and honest mistakes are where many real problems start.
- Threats without controls. A list of what could go wrong, with nothing beside it, frightens people and protects nothing. Every threat gets a response.
- Writing how, not what. The model needs "a customer could see another's order", not a description of technique. Plain words are clearer and safer.
- Treating it as proof. A model shows what you thought of. Checks on the built shop show what works.
- Never opening it again. A model made once and filed is out of date by the first new feature.
- Say what you are modelling, and who is in the room.
- List the assets and rank them by the harm their loss would do.
- List the actors and what each may do, insiders and operators included.
- Draw the data flows and mark every trust boundary.
- At each entry point, ask the six STRIDE questions and write the real threats in plain words.
- Give each threat a response and a control, rank by likelihood and impact, build from the top, and revisit when the shop changes.
Sources
- OWASP Cheat Sheet Series, Threat Modeling Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Threat_Modeling_Cheat_Sheet.html (read on 11 November 2026)
- Protection of Personal Information Act 4 of 2013, sections 19 and 21