Threat modelling and zero trust
Find what an attacker would target in your design before you build it, and stop trusting a call just because it comes from inside.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
On 16 June 2023, the US State Department told Microsoft about strange access to its email. A custom alert on mailbox access logs had fired. 1
Microsoft found that an attacker it calls Storm-0558 was reading mail with forged login tokens. The tokens were signed with a Microsoft consumer account key from 2016. That key was only meant to sign tokens for consumer email, not enterprise mailboxes. It was also meant to be retired in March 2021. 1
The key should never have opened enterprise mail. But Microsoft had built one shared endpoint that listed active signing keys for both consumer and enterprise systems. The libraries that check tokens were not properly updated to tell the two kinds of key apart. So mail accepted a token signed by either kind of key. 1
The attacker reached the mailboxes of 22 organizations and 503 personal accounts. It downloaded about 60,000 emails from the State Department alone. 1 Microsoft still did not know how the key was stolen when the Cyber Safety Review Board finished its review. The Board called the intrusion "preventable". 1
The Board listed several errors. For example, the old key was never removed, and Microsoft did not detect the forged tokens itself. But it found that without the validation flaw, no enterprise customer would have been hit. 1
In our reading, the missing check sat on a trust boundary between consumer and enterprise systems. A threat model asks at each such line: what if a token from the other side shows up here? The Board asked cloud providers to design identity systems "informed by a rigorous threat model". 1
It happens for real
Microsoft · 16 Jun 2023Storm-0558: a consumer signing key opened enterprise mailboxesAn attacker read Exchange Online mail at 22 organizations and 503 personal accounts with forged tokens, including about 60,000 emails from the US State Department. All incidents tagged “security”The idea in simple words
A threat model is a structured look at a design to find what could go wrong with its security and privacy. 2 You do it before you build, and you keep doing it as the design changes. 3
It comes down to four questions: 2
- What are we working on?
- What can go wrong?
- What are we going to do about it?
- Did we do a good enough job?
Zero trust is a related idea. No user, device or service is trusted just because of where it sits on the network. Every request proves who it comes from and gets checked. 5
The key idea. Draw where data crosses from one level of trust to another. Ask what could go wrong at each crossing. Then check identity and permission at every crossing, including the ones inside your own network.
How it works
Draw the system and its trust boundaries
Start with a data flow diagram. OWASP says a useful model shows trust boundaries, data flows, data stores, processes and external entities. These often mark the places attackers aim at. 3
A trust boundary is where data or a call moves between parts you trust differently. Examples: the internet to your API, one tenant to another, a partner's webhook to your code, or a consumer system to an enterprise one.
Step through a small design: an expense app where users upload receipts.
- What are we working on? A user uploads a receipt to the API. The API stores the file in a bucket. A worker reads it and saves the totals in the database.
- Mark the trust boundaries. TB1: requests arrive from the internet. TB2: the file's content was written by the user, so the worker must treat it as hostile input.
- Walk STRIDE where data crosses TB1. Spoofing: a caller pretends to be another user, or the request body names someone else's userId. Take the user from the verified session instead.
- Now the bucket and TB2. Information disclosure: the bucket is public, or its links never expire. Elevation of privilege: a crafted file attacks the parser in a worker that holds database admin rights.
- Zero trust adds one rule. The API and the worker each prove their own identity, and every call is checked. Being inside the network grants nothing.
Ask what can go wrong: STRIDE
STRIDE is a list of six prompts. Each letter is a kind of threat, and each one breaks a security property. 3
| Letter | Threat | Breaks | Receipt app example |
|---|---|---|---|
| S | Spoofing: using someone else's identity 4 | Authentication | The body sends another user's userId, or a stolen session uploads. |
| T | Tampering: changing data you should not 4 | Integrity | A user edits an expense total after it was approved. |
| R | Repudiation: denying an action with no proof 4 | Accounting | A user says "I never uploaded that". |
| I | Information disclosure 4 | Confidentiality | The bucket is public, or links never expire. |
| D | Denial of service 4 | Availability | A 2 GB upload fills the worker's disk. |
| E | Elevation of privilege 4 | Authorization | A crafted PDF exploits the parser, and the worker has database admin rights. |
Walk the list at each trust boundary. Spend most time where outside data enters. You will find ideas that are not on the list. That is fine.
Choose what to do
Rank each threat by how likely it is and how bad it would be. OWASP admits both are hard to measure, and that this ranking ignores the work to fix each one. 3 So weigh the cost of the fix too. A simple high, medium or low for each is enough to start.
Then pick one of four responses: 3
- Mitigate: lower the chance it happens. Lock an expense once it is approved.
- Eliminate: remove the feature. Maybe you do not need public receipt links at all.
- Transfer: give the cost to someone else, such as an insurer. This does not make the event less likely or less harmful. 3
- Accept: write down why, and who agreed.
For the receipt app, a good list is short. Take the user from the verified session, not the body. Keep the bucket private and use links that expire in minutes. Log every upload with the user ID. Limit the file size. Run the parser with no database rights; it hands results to a small writer with insert-only access.
Each fix should be testable. OWASP asks reviewers to check that agreed mitigations can be tested. 3
Keep it lightweight
The manifesto values "people and collaboration" over processes, methodologies and tools. It also values "continuous refinement" over a single delivery. 2 Threat modelling should fit how your team already works, in small steps scoped to the part that changed. 2
In practice: add a "Threats" section to each design doc. Spend 30 minutes with the people who know the design. Turn each decision into a ticket or a test. The fourth question checks the model itself. Does the diagram match the system? Does every threat have a response, and can each fix be tested? 3 Ask it again after launch or after an incident.
Zero trust: what it means
The old model is a castle. Anything inside the wall is trusted. Google's BeyondCorp paper says that once the wall is breached, the attacker has easy access to the internal network. 6
NIST's definition: zero trust "assumes there is no implicit trust granted to assets or user accounts based solely on their physical or network location". 5 Two of its tenets matter most for daily work:
- Every connection is protected, wherever it comes from. A request from inside must meet the same rules as one from outside. 5
- Access is granted per session, with least privilege. Access to one resource does not grant access to another. 5
At Google, every internal app sits behind an internet-facing access proxy. It checks the user, their groups, the device certificate and the device's state on every request. 6 In a Google office, a laptop without a valid certificate lands on a network with very limited access. 6
Zero trust for a service team
You probably do not run the access proxy. You run services. For you, zero trust means three habits.
Every caller has an identity. Each workload gets its own identity, proved with a short-lived certificate or token. SPIFFE names workloads with IDs like spiffe://acme.com/billing/payments, and rotates their keys often and automatically. 7 A service mesh can do this for you. See Service mesh and sidecars.
Every request is checked. Verify the caller's credential, then check what it may do. Never trust a header because the call came from inside.
# Wrong: any pod that can reach us can claim to be any user
user_id = request.headers["X-User-Id"]
# Right: verify a signed token for this service, then read the user from it
claims = verify_token(request.headers["Authorization"], audience="receipts-api")
user_id = claims["sub"]Credentials are short-lived and narrow. Each service gets only the permissions it needs. 5 How to issue and rotate them is in Secrets and key management.
What zero trust does not mean
- It is not a product. NIST calls it a set of guiding principles. Moving to it is "a journey", not a swap of technology. 5
- It does not remove the firewall overnight. NIST expects most companies to run a hybrid of zero trust and perimeter controls for an indefinite period. 5
- It does not stop a valid account. An attacker with real credentials can still reach what that account may reach. Zero trust should stop it from moving further. 5
- It adds a critical part. If the policy service fails or is attacked, people may not reach anything. Run it in several places. 5
Trade-offs
| Option | What it catches | Cost | Main risk | Use it when |
|---|---|---|---|---|
| No threat model, code review only | Bugs in single lines. | None up front. | No Design flaws, like a missing boundary check, ship. | Small changes with no new data flow. |
| 30-minute four-question session | Many design flaws at trust boundaries. | Low. One meeting per design. | Shallow if the right people are not there. | Every new feature, endpoint or integration. |
| Full STRIDE per element, with a tool | More threats, written down for audits. | High. Days of work. | It goes stale if nobody updates it. 3 | Identity, payments and other high-risk systems. |
| Network perimeter as the main control | Outsiders who never got in. | Low. It already exists. | No Once inside, an attacker moves freely. 5 | Only as one layer among others. |
| Zero trust: per-request identity and policy | Stolen access to one part reaching other parts. 5 | Medium to high. Identity for every workload and device. | The policy service becomes critical. 5 | New systems, and step by step for old ones. 5 |
Simple rule: threat model every design that adds a trust boundary. Make every service check its caller, whatever network the call comes from.
At work: how a senior uses this
- In design review, ask: "Where are the trust boundaries, and what checks the data at each one?"
- Draw the data flow on the whiteboard first. Most missed threats hide in arrows nobody drew.
- Ask: "What if a valid token from the wrong tenant, environment or system shows up here?" That was the Storm-0558 question.
- Never accept "it is internal" as a reason to skip authentication. Ask who else can reach that network.
- Turn each threat into a ticket, a test or a written acceptance with an owner. A list in a doc is not a fix.
- Revisit the model when the design changes, not on a calendar.
- Prefer shared libraries for token checks. The Board found that many different token libraries made correct, uniform checks harder. 1
With AI
What to ask the agent
"Here is our design doc. Draw a data flow diagram as a Mermaid chart. Mark every trust boundary and list the data that crosses each one."
"For each trust boundary in this diagram, list STRIDE threats. For each, give likelihood, impact and one concrete mitigation. Mark the ones you are unsure of."
"Search this service for code that reads user or tenant IDs from headers or request bodies without verifying a token. List file and line."
What to check yourself
- The agent's diagram matches the real system. Check it against your deploy config, not only the doc.
- Generic threats like "use strong passwords" add noise. Keep only threats tied to a flow in your design.
- Mitigations name a real place in your code or config. "Add validation" is not a mitigation.
- Each internal endpoint the agent writes checks the caller's identity, not just its IP address.
- The agent cannot judge business impact. You decide the ranking with your team.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 7 sources and related lessons
- Cyber Safety Review Board, Review of the Summer 2023 Microsoft Exchange Online Intrusion (20 March 2024) (opens in a new tab)
The official review. Pages 1 to 7 tell how a consumer signing key opened enterprise mailboxes; pages 20 and 21 list the fixes the Board asks of all cloud providers. - Braiterman, Shostack, Marcil et al., Threat Modeling Manifesto (opens in a new tab)
The four questions, plus short values and principles for doing threat modelling as a team habit. - OWASP Cheat Sheet Series, Threat Modeling Cheat Sheet (opens in a new tab)
Data flow diagrams, STRIDE, how to rank threats, the four ways to respond, and how to review the result. - Microsoft Learn, Threats - Microsoft Threat Modeling Tool (opens in a new tab)
A table with a plain definition and an example for each STRIDE category. - Rose, Borchert, Mitchell and Connelly, NIST SP 800-207: Zero Trust Architecture (NIST, August 2020) (opens in a new tab)
The definition of zero trust, its seven tenets in section 2.1, and the threats to a zero trust design in section 5. - Ward and Beyer, BeyondCorp: A New Approach to Enterprise Security, ;login: vol. 39 no. 6 (USENIX, December 2014) (opens in a new tab)
How Google moved its internal apps behind an access proxy that checks user and device on every request. - SPIFFE, SPIFFE Concepts (opens in a new tab)
The SPIFFE ID format, short-lived identity documents for workloads, and the Workload API.
Real incident: Microsoft, 16 Jun 2023: Storm-0558: a consumer signing key opened enterprise mailboxes
Related: Authentication and authorization · OWASP Top 10 and secure coding · Authorization models: RBAC, ABAC and ReBAC · Secrets and key management · Dependency and supply-chain security · Service mesh and sidecars · Design docs and RFCs
- Authentication and authorization: how to check a user and their permission on every request.
- Authorization models: RBAC, ABAC and ReBAC: how to write the "what may this caller do" rules.
- Dependency and supply-chain security: threats that arrive in code you did not write.
- Design docs and RFCs: where your "Threats" section lives.