Beginner’s Guide to Threat Modeling: Thinking Like an Adversary
Adam Shostack’s 4-Question Framework, Assets, Entry Points & Shift-Left Economics
“Every system has a threat model—either one you designed on purpose, or one an attacker discovers for you on a Friday night.”
Imagine building an entire house, pouring concrete, wiring the electricity, hanging drywall—and only THEN asking an architect, "Hey, shouldn’t the front door have a lock?" You would never build a house that way. Yet software teams do it every quarter: they ship a new microservice, wire up a database, expose a webhook, and ask security to "bless it" two days before launch.
By that point, fixing a fundamental design flaw—like realizing tenant A can query tenant B’s invoices because authorization lives in the UI instead of the API—requires ripping out database schemas, migrating live rows, and delaying the release by three weeks. On a whiteboard during sprint planning, that exact fix takes five minutes and a marker.
Threat modeling is simply the discipline of thinking like an adversary while your architecture is still cheap to change. It turns vague anxiety ("Are we secure?") into concrete engineering decisions.
The 4-Question Framework, Assets & Entry Points
The simplest, most battle-tested structure in security engineering is Adam Shostack’s 4-Question Framework: (1) What are we building?, (2) What can go wrong?, (3) What are we going to do about it?, and (4) Did we do a good job? Notice there is no mention of magic tools or 90-page compliance binders. It works equally well for a 3-person startup and a global bank.
To answer Question 1 without drowning in detail, focus on Assets (what attackers want: PII, payment tokens, signing keys, proprietary models) and Entry Points (every door into the building: REST endpoints, GraphQL mutations, gRPC ports, S3 upload buckets, CI webhooks, and admin consoles).
To answer Question 2, adopt Adversarial Thinking: stop assuming users click buttons in the intended order. Assume an attacker sends raw curl requests with forged headers, replays expired tokens, uploads 4 GB XML bombs, and pivots sideways from your least-important internal worker.
Sketch the components, data stores, actors, and boundaries so everyone shares one mental model.
Walk each entry point and ask how an attacker could spoof identity, tamper with data, or escalate privileges.
Choose concrete mitigations (auth checks, rate limits, encryption) or consciously accept low-severity risks.
Verify controls were actually implemented in code/tests and update the model when requirements shift.
Keep the diagram focused on the feature or system change—never boil the entire company ocean on day one.
Every open port, webhook, file parser, and admin route is an invitation for untrusted input.
Question 4 closes the loop—make sure the mitigation made it into the pull request.
Case Study: The $120,000 "Forgot-to-Check-Org-ID" BOLA Bug
A fast-growing SaaS team shipped a PDF invoice export endpoint /api/v1/invoices/{invoiceId}/pdf. It passed unit tests, lint checks, and even a static code scanner—yet weeks later a researcher discovered any logged-in user could download any enterprise customer’s invoice by incrementing invoiceId.
Trusted the UI Instead of the API
Engineers assumed users would only click invoice links shown on their own dashboard. Nobody drew the API entry point receiving arbitrary invoiceId parameters.
Sequential Enumeration (BOLA / IDOR)
An attacker authenticated with a free trial account and scripted GET /api/v1/invoices/1001..9999, exfiltrating confidential billing PDFs.
10 Minutes on Question 2
Asking "What if a valid user supplies someone else’s ID at this entry point?" immediately flags Broken Object Level Authorization—fixed cleanly with WHERE id = ? AND org_id = jwt.org_id before line 1 is written.
There Are No Dumb Questions
Candid answers to the skeptical questions every security engineer asks first.
Design-Time Threat Modeling vs. Post-Release Penetration Testing
“We hire an external firm every November to hack our production staging environment. Isn’t that enough?”
“A pentest in November tells you that the basement flooded in June. Threat modeling in June makes sure you installed a sump pump before the rain started!”
Sharpen Your Pencil · 60-Second Brain Challenge
Your team is designing a new webhook receiver /webhooks/stripe that updates customer subscription tiers. According to the 4-Question Framework, what is the FIRST critical question to ask in Step 2 ("What can go wrong?")?
- ▸Threat modeling is structured adversarial thinking before code is written—fixing flaws 100× cheaper than in production.
- ▸Use the 4-Question Framework: What are we building? What can go wrong? What will we do? Did we do a good job?
- ▸Always map Assets (what attackers want) and Entry Points (every untrusted door into the system).
- ▸Keep models small, iterative, and scoped to the feature or boundary you are changing.
Practice mapping Assets, Entry Points, and the 4-Question Framework visually in NodeMotion’s Live Canvas →