Chapter 1The security mindset
In 2017 attackers took personal records on roughly 147 million people from Equifax through a web framework flaw (Apache Struts, CVE-2017-5638) that had been patched two months earlier. Nobody broke the encryption; the attackers found one unpatched door, then walked through a network that trusted anything already inside. This chapter teaches you to see systems the way they did, and to find the doors before someone else does.
After this chapter you can
- Explain assets, threats, vulnerabilities and risk, and how they combine
- Map an attack surface and draw trust boundaries on a data-flow diagram
- Apply STRIDE to every element of a diagram to generate threats systematically
- Build an attack tree and reason about attacker cost
- Place an attack on the kill chain and in MITRE ATT&CK terms
- Design controls using defense in depth, least privilege and assume breach
Assets, threats, vulnerabilities and risk
Security starts with four words that people use loosely and practitioners use precisely. An asset is anything worth protecting: customer data, signing keys, uptime, your reputation. A threat is someone or something that could harm an asset. A vulnerability is a weakness a threat can use, and risk is the combination of how likely that is and how bad it would be.
| Term | Question it answers | Example for an online shop |
|---|---|---|
| Asset | What do we lose if it goes wrong? | Card tokens, customer addresses, the admin panel |
| Threat actor | Who would want to hurt it? | Card fraud gangs, a disgruntled ex-employee, bots |
| Vulnerability | Where is the weakness? | Admin panel reachable from the internet with password-only login |
| Impact | How bad is the outcome? | Mass refund fraud, regulator fines |
| Likelihood | How plausible is it? | High: credential stuffing against admin logins is routine |
| Risk | Is it worth fixing first? | High likelihood times high impact means fix it this sprint |
The practical consequence is that you cannot protect everything equally. Risk gives you an ordering. A critical bug in a service with no sensitive data and no network exposure can rank below a medium bug on your login page.
You have four ways to handle any risk: mitigate it (add a control), avoid it (remove the feature), transfer it (insurance, a payment provider that holds card data for you), or accept it (document and move on). Accepting a risk is a legitimate decision when someone with authority makes it knowingly. Ignoring a risk is not the same thing.
The CIA triad and what attackers actually want
Every security property you will meet reduces to three goals. Confidentiality means only authorized parties can read data. Integrity means data and systems change only in authorized ways. Availability means the system works when legitimate users need it.
Different businesses weight these differently. A hospital cares most about availability and integrity of patient records, because a wrong dose kills faster than a leak does. A messaging app may rank confidentiality first. Ransomware is interesting because it hits all three: it encrypts data (availability), and modern gangs steal a copy first to threaten publication (confidentiality).
Two properties often get added to the triad. Authenticity is knowing who you are talking to, and non-repudiation is being able to prove later that someone did something. You will see both again in the chapter on applied cryptography, where signatures provide them.
Attack surface and attacker economics
The attack surface is every point where an attacker can send input to your system or pull data out of it. It is larger than people think. It includes internet-facing ports and APIs, but also the CI pipeline, third-party JavaScript, employee laptops, support staff who can reset passwords, and the npm packages you pulled in last week.
- Network surface: open ports, public endpoints, VPN gateways, exposed admin consoles.
- Software surface: every parser, file upload, deserializer and query builder that touches untrusted input.
- Human surface: help desk, phishable staff, contractors with access.
- Supply chain surface: dependencies, build systems, SaaS integrations with tokens into your data.
Attackers are economic actors. Most are running a business, and they pick targets and techniques with the best return for the least effort. This is why credential stuffing, phishing and exploiting known, already-patched CVEs dominate real incidents: they are cheap and they scale.
That framing explains the defender's dilemma: the attacker needs one working path, while the defender must cover all of them. The way out is not perfection. It is making the cheap paths expensive and making sure you notice when someone walks the expensive ones.
Trust boundaries and data-flow diagrams
A trust boundary is any line where data or control passes between parties with different levels of trust: browser to server, your service to a third-party API, a normal user process to the kernel. Almost every vulnerability lives on a trust boundary, because that is where untrusted input meets code that assumes it is safe.
You find boundaries by drawing a data-flow diagram (DFD). A DFD has four element types: external entities (people or systems you do not control), processes (your code), data stores (databases, buckets, queues), and data flows (arrows). Trust boundaries are drawn as boxes around elements that share a trust level.
Every arrow that crosses a boundary box is a place to ask hard questions. Who authenticates this flow? Is the input validated? What happens if the payment provider's webhook is forged? Notice that the worker processes files that a customer uploaded: that internal arrow carries untrusted data even though both ends live in your account.
Threat modeling with STRIDE
A threat model is a structured answer to four questions, popularized by Adam Shostack: what are we working on, what can go wrong, what are we going to do about it, and did we do a good job. The DFD answers the first. STRIDE is a checklist that answers the second, so you do not depend on inspiration.
| Letter | Threat | Property violated | Typical example | Typical control |
|---|---|---|---|---|
| S | Spoofing | Authenticity | Forged webhook claiming to be the payment provider | Signature on the webhook, mTLS |
| T | Tampering | Integrity | Changing the price field in an order request | Server-side validation, MACs |
| R | Repudiation | Non-repudiation | User denies placing an order, and you have no log | Tamper-evident audit logs |
| I | Information disclosure | Confidentiality | Bucket readable by anyone with the URL | Private buckets, signed short-lived URLs |
| D | Denial of service | Availability | Huge upload exhausts worker disk | Size limits, quotas, rate limits |
| E | Elevation of privilege | Authorization | Normal user calls an admin API | Authorization check on every request |
The technique that makes STRIDE work is STRIDE per element: walk every element and every boundary-crossing flow in the DFD and ask which letters apply. Processes are exposed to all six. Data stores mostly face tampering, disclosure and denial of service. Flows face tampering, disclosure and denial of service in transit.
Scope and diagram
Pick one feature or service. Draw the DFD with trust boundaries. Ten elements is plenty for a first pass.
Enumerate threats
For each element and boundary-crossing flow, go through the applicable STRIDE letters and write one concrete sentence per threat: actor, action, asset.
Rate them
Give each threat a likelihood and an impact (low, medium, high is enough). Resist false precision.
Decide and track
Mitigate, avoid, transfer or accept each one. Mitigations become tickets with owners, not paragraphs in a document nobody reopens.
Validate
Check that controls exist and work: a test, a config check, or an attempt to exploit it in a lab.
Attack trees
STRIDE gives you breadth. An attack tree gives you depth on one goal. The root is the attacker's objective, children are ways to achieve it, and leaves are concrete actions. Children are either alternatives (OR: any one works) or requirements (AND: all are needed).
Annotate each leaf with a rough cost and skill level. Here, changing an order ID in a URL costs nothing and needs no skill, so an insecure direct object reference (IDOR) is the path real attackers try first. That single annotation tells you where to spend your next day of engineering.
Attack trees also show where one control kills several paths. Removing database credentials from source code and requiring authorization checks on object IDs prunes two branches with two small changes.
The kill chain and MITRE ATT&CK
Real intrusions are sequences, not single events. Lockheed Martin's Cyber Kill Chain describes seven stages: reconnaissance, weaponization, delivery, exploitation, installation, command and control, and actions on objectives. Its value is the idea that breaking any link stops the chain, so defenders get several chances.
MITRE ATT&CK is the more detailed and now more common vocabulary. It is a public knowledge base of adversary behavior organized as tactics (the goal, such as Initial Access or Credential Access) and techniques (how, such as T1190 Exploit Public-Facing Application). Defenders use it to describe incidents precisely, to measure detection coverage, and to plan emulation exercises.
You will use ATT&CK heavily in the chapters on red teaming and adversary emulation and on detection engineering. For now, the key habit is to name each step of an attack and ask what you would see if it happened.
Defense in depth, least privilege and assume breach
Three principles turn a threat model into an architecture.
Defense in depth means layering independent controls so that one failure is not a breach. The Equifax attack crossed a patching failure, then flat internal networking, then credentials stored on reachable hosts, then weeks of unnoticed data leaving the network. Any one layer working would have shrunk the damage.
Least privilege means every user, service and token gets only the access it needs, for only as long as it needs it. A web API that only reads orders should use a database role that cannot drop tables. A CI job that publishes a package should not hold production cloud credentials.
Assume breach means designing as if an attacker is already inside. You segment so they cannot move freely, you log so you can reconstruct what they did, and you rehearse response. It is the mindset behind zero trust, covered in the chapter on network defense and zero trust.
Perimeter mindset
- Hard shell, soft inside
- Trust based on network location
- Success means nobody gets in
- Logging is for compliance
Assume-breach mindset
- Every hop authenticated and authorized
- Trust based on identity and device state
- Success means fast detection and small blast radius
- Logging is how you answer what happened
Key terms
- Asset
- Anything of value that you need to protect, such as data, keys, availability or reputation.
- Vulnerability
- A weakness in design, code or configuration that a threat can exploit.
- Risk
- The combination of the likelihood of a threat succeeding and the impact if it does.
- Attack surface
- Every point where an attacker can send input to a system or extract data from it.
- Trust boundary
- A line where data or control passes between parties with different levels of trust.
- Data-flow diagram
- A diagram of external entities, processes, data stores and flows, used as the map for threat modeling.
- STRIDE
- A checklist of six threat categories: spoofing, tampering, repudiation, information disclosure, denial of service and elevation of privilege.
- Attack tree
- A tree with an attacker goal at the root and alternative or required steps as children, used to find the cheapest attack paths.
- MITRE ATT&CK
- A public knowledge base of real adversary tactics and techniques, used as a common language for attacks and detections.
- Least privilege
- Granting each identity only the access it needs, for only as long as it needs it.
Threat model a small web app end to end
Goal: produce a complete threat model (DFD, STRIDE table, attack tree, prioritized mitigations) for a real running app, and validate at least one threat by observation.
You need: Docker (Docker Desktop on macOS or Windows, docker.io on Linux), a browser with developer tools, and a text editor. You will run OWASP Juice Shop, a deliberately vulnerable shop built for training, on your own machine. Only ever test targets you own or run locally like this one.
-
Start the app and confirm it runs:
docker run -d --name juice -p 127.0.0.1:3000:3000 bkimminich/juice-shop docker logs -f juice # wait for "Server listening on port 3000"Open
http://localhost:3000. You should see a storefront selling juice. -
Explore it as a user for 15 minutes. Register an account, log in, add items to a basket, leave a product review, try the complaint form with a file upload. Keep developer tools open on the Network tab and write down every distinct API path you see (for example
/rest/user/login,/api/BasketItems). -
Create a folder
threat-model/with a filethreat-model.md. Write a one-paragraph scope: what the app does, who uses it, and which assets matter (customer accounts, order history, payment data, admin functions). -
Draw the DFD as a mermaid block in that file. Include at least: customer browser, the Angular single-page app, the Express API, the database, the file upload store, and an admin user. Draw trust boundaries around the internet and around the server.
-
Build a STRIDE table with columns Element, Letter, Threat, Likelihood, Impact. Aim for at least 15 rows, covering every boundary-crossing flow. Write threats as sentences with an actor: "An anonymous user changes the basket ID in a request to view another user's basket."
-
Inspect the authentication token. Log in, then find the token in the Network tab (the
Authorization: Bearerheader) or in Application, Local Storage. Paste it into a local JWT decoder, or run:TOKEN='paste-token-here' echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null; echoYou should see a JSON payload. List every field it contains and ask: should a client-readable token carry this? Record what you find as an information disclosure threat in your table.
-
Pick the goal "Access another customer's data" and draw an attack tree with at least three branches. Mark each leaf with a cost (low, medium, high).
-
Write a prioritized mitigation list: top five threats, the control for each, and which principle it applies (defense in depth, least privilege, assume breach).
-
Clean up when done:
docker rm -f juice
Check your work: your threat-model.md renders a DFD with labelled trust boundaries, contains 15 or more STRIDE rows with every letter used at least once, includes one threat you confirmed with your own eyes in step 6, and ends with five mitigations ranked by risk.
Stretch: open Juice Shop's Score Board (it is hidden; finding it is the first challenge) and solve two challenges that correspond to threats in your table. Add a column noting which of your predicted threats turned out to be real. Commit the folder to a public repo as your first portfolio piece.
Check yourself
A service with a critical-severity bug has no network exposure and holds no sensitive data. Your login page has a medium-severity bug and is internet facing. Which should you usually fix first?
An internal worker processes files that customers uploaded through your public API. Both run in your cloud account. How should you treat the files in the worker?
A payment provider sends webhooks to your API to confirm payments. An attacker sends a fake 'payment succeeded' webhook. Which STRIDE category is this, and which control addresses the root cause?
In an attack tree, one leaf is 'change the order ID in the URL' with cost low, and another is 'phish an employee' with cost medium. What does this tell you?
Which design best reflects the assume-breach principle?
Recap
- Risk is likelihood times impact, and it decides what you fix first, not raw severity.
- Attackers are economic: make the cheap paths expensive and the expensive paths visible.
- Draw a data-flow diagram with trust boundaries; most vulnerabilities live where untrusted data crosses them.
- STRIDE per element turns threat brainstorming into a checklist you can finish.
- Attack trees and ATT&CK help you reason about real attack paths step by step.
- Defense in depth, least privilege and assume breach turn a threat model into architecture.
Go deeper
- Threat Modeling: Designing for Security (Adam Shostack): the standard book on STRIDE and practical threat modeling.
- Threat Modeling Manifesto: a short statement of values and patterns from experienced practitioners.
- OWASP Threat Modeling: community overview with links to methods and tools.
- OWASP Threat Dragon: free tool for drawing DFDs and recording STRIDE threats.
- MITRE ATT&CK: the reference for adversary tactics and techniques.
- Lockheed Martin Cyber Kill Chain: the original description of the seven-stage intrusion model.