Skip to main content
Engineering/threat-modelExperimentalUpdated

Threat Model

Build a STRIDE threat model of a whole system: its trust boundaries, ranked threats that survived a disproof pass, and prioritized mitigations. Use when designing a new architecture, inheriting or onboarding onto an existing system, or preparing for a security review of an entire app.

Use this when you need the threats to a whole system, not one feature: designing a new architecture, onboarding onto a client's system, inheriting an app, or preparing for a security review or risk assessment. You walk away with a trust-boundary map, a ranked threat matrix of threats that survived a disproof pass, a short list of facts that need validating, prioritized mitigations and an annotated diagram. For one feature, story or PR, use /security-review instead.

The steps answer the four questions of the Threat Modeling Manifesto: what are we working on (Steps 1 and 2), what can go wrong (Steps 3 to 6), what are we going to do about it (Step 7), and did we do a good enough job (Step 9).

Related skills: Takes architecture input from /system-diagram and domain boundaries from /architecture-discovery. Hands high-risk components to /security-review for a per-feature deep dive, and borrows its six-part boundary test. Records security architecture decisions with /adr-generate.

You provide

  • {{system}}: the system's name and what it does, in a sentence.
  • {{architecture}}: a diagram, a description, or a repo path and commit to read. For k8mak.com, site/ at origin/main.
  • {{data_sensitivity}}: what data it holds, by class (PII, PHI, financial, public, internal).
  • {{integrations}} (optional): third-party APIs, SaaS dependencies, payment processors, if the architecture does not show them.
  • {{compliance}} (optional): frameworks that mandate controls (PCI-DSS, HIPAA, SOC 2).
  • {{posture}} (optional): mature security practice or greenfield, and any known threat intelligence.

Process

Step 1: Gather the system context

Collect: the architecture, data flows (what moves where, in what format, over what protocols), trust boundaries, authentication and authorization mechanisms, external integrations, data sensitivity, and the LLM and agent surface (model calls, RAG pipelines, tool-calling agents, system prompts, vector stores, multi-model routing; what reaches the model and what the model can do). With only a description, sketch a component list with data flows first, or run /system-diagram.

When the system is built, read the code. For a Next.js and Supabase app such as k8mak.com, read in this order and record the commit:

  1. Every route handler: find site/app/api -name route.ts, and every 'use server' file.
  2. Which of them use the service role, which bypasses every RLS policy (Supabase API keys): grep -rln "createServerSupabase" site/app site/lib.
  3. Auth: site/lib/auth/config.ts (Auth.js, admin by ALLOWED_EMAILS) and site/middleware.ts, remembering that middleware (renamed proxy.ts in Next.js 16) is not an authorization gate (CVE-2025-29927 bypassed it outright; fixed in 15.2.3 and backports).
  4. Rate limiting: site/lib/rate-limit.ts, and grep -L "checkRateLimit" across the write routes.
  5. Headers and hosting: site/next.config.mjs, site/vercel.json, and curl -sI https://www.k8mak.com (the apex 308s to www).
  6. Data: site/supabase/migrations/ for RLS, grants, views and definer functions, and the Supabase Security Advisor (get_advisors, read-only).
  7. External integrations: grep -rhoE "process\.env\.[A-Z_]+" site/app site/lib | sort -u.

The per-file checks behind each read are in /security-review's code checks. Live checks are anonymous GET and curl -sI only.

Step 2: Map the trust boundaries

Map every point where data crosses a trust boundary: client to server, service to service, internal to external (third-party APIs, webhooks), user to admin, encrypted to unencrypted (TLS termination), network zones (public internet, DMZ, private subnet, database tier). For each, record source, destination, protocol, authentication method and data sensitivity, with an id (B1, B2 ...). A shared credential is a boundary of its own: one service-role key in several Vercel projects joins their blast radius (the lost-explorer threat model T-01 and B6).

Step 3: Apply STRIDE per component

For each component on or crossing a boundary, ask the six STRIDE questions:

CategoryQuestion
SpoofingCan an attacker impersonate a legitimate user, service or component?
TamperingCan data be modified in transit or at rest without detection?
RepudiationCan a user or system deny performing an action with no way to prove otherwise?
Information DisclosureCan data leak through error messages, logs, side channels, page payloads or unauthorized access?
Denial of ServiceCan the component be overwhelmed, starved of resources, or made unavailable (including a cost attack on usage-billed compute)?
Elevation of PrivilegeCan an attacker gain higher permissions than intended?

Be specific: not "the API could be attacked" but "an unauthenticated user could enumerate valid user IDs via timing differences in the login response."

Step 4: Add the LLM and agent layer (only when the system has one)

Work through each class in reference/llm-layer.md for every model or agent on a boundary, tagged with its OWASP LLM Top 10 2025 or Agentic Top 10 2026 id. Treat every input that reaches the model as instruction surface. Roll the threats into the same matrix. Otherwise write "No LLM, RAG or agent surface" and the evidence (for example, no model SDK in package.json).

Step 5: Try to disprove each threat

Adapted from Cloudflare's security-audit skill (MIT): nothing is rated until something has tried to refute it. Run every threat from Steps 3 and 4 through the six-part boundary test in /security-review Step 4 (lower-trust actor, accepted input, intended control, boundary crossed, who is harmed, concrete result), then try to knock it down from the architecture provided. Where the platform can delegate, give each threat to a fresh agent that did not write it; otherwise re-read the Step 2 boundary list first. Give each threat one status:

  • Credible: all six parts named and the refutation failed. It goes in the matrix with scores.
  • Needs validation: it turns on a control or deployment fact not in what was provided (a gateway rule, a network policy, a provider setting). It goes in "Needs validation" with the exact missing fact and who can answer it, with no likelihood, impact or score.
  • Dropped: a documented control or an impossible precondition refutes it. One line under "Considered and dropped".

Step 6: Build the threat matrix

Fill the matrix in reference/matrix-template.md with every Credible threat, ranked by risk score, then the "Needs validation" and "Considered and dropped" lists, and a short "What I checked and found sound" list so the next review does not redo it. Score with the template's scale: likelihood 1 to 5, impact 1 to 5, risk = L x I, Critical >= 20, High >= 12, Medium >= 6, Low < 6. Show the multiplication.

Step 7: Prioritize mitigations

For every High or Critical threat, recommend a control with its type (preventive, detective, corrective), effort (S, M, L) and priority (P1 to P4). Each must be detailed enough for an engineer to estimate; the template shows the bar. Route a component that needs a deeper per-feature pass to /security-review, and a decision worth recording to /adr-generate.

Step 8: Annotate the data flow diagram

Mark the diagram (or component list) with trust boundary lines (dashed borders around zones), numbered threat entry points referencing threat ids, the highest-risk components highlighted, and data sensitivity labels on each flow. From a text description, produce a labeled diagram in Mermaid or ASCII.

Step 9: Review whether it was good enough

Ask the user:

  • Are there components or integrations we missed?
  • Does the team have threat intelligence: known attack patterns against similar systems?
  • Are there compliance requirements that mandate specific controls (PCI-DSS, HIPAA, SOC 2)?
  • What is the team's current security posture: mature security practice or greenfield?
  • Which threats feel most realistic given the organization's exposure?
  • If the system uses an LLM or agent: are all instruction-bearing inputs (retrieval sources, tool outputs, fetched pages) accounted for, and is every tool the agent can call scoped to least privilege?

Name what would make this model stale (a new boundary, a new integration, a new data class) so it is re-run then. The Manifesto values "continuous refinement over a single delivery".

Output contract

  • The header states scope and evidence: what was read (with commit for code), what was checked live and how, and what was not checked.
  • Every trust boundary has an id, source, destination, protocol or auth, and data sensitivity.
  • Every threat in the matrix is Credible, names a STRIDE category, a component or boundary id and a specific attack vector.
  • Every matrix row shows likelihood, impact and the multiplied risk score, and the band matches the scale.
  • Every "Needs validation" row names the exact missing fact and an owner, with no score.
  • Every dropped threat has a one-line reason.
  • LLM-layer threats carry an OWASP LLM 2025 or Agentic 2026 id, or the document says why the layer does not apply.
  • Every High or Critical threat has a mitigation with type, effort and priority, specific enough to estimate.
  • The diagram marks boundaries, numbered entry points and sensitivity labels.
  • Assumptions are stated (for example, "assuming TLS 1.2+ is enforced at the load balancer"), and a component without enough detail is flagged as a gap.
  • Every claim about live data or settings that was not checked carries .
  • Prose follows knowledge/voice-tone-guide.md, with no em-dashes.

Ruled out

  • Never write a generic threat ("the API could be attacked"). Name the vector.
  • Never rank by how interesting a threat is. Rank by risk score.
  • Never score a threat that depends on an unseen control. It gets a question in "Needs validation", never a number.
  • Never guess at a component that lacks detail. Flag it as a gap.
  • Never write a mitigation an engineer could not estimate.
  • Never run an active attack against production: no writes, crafted payloads, brute-force loops or spoofed headers. Live checks are anonymous GET only, as in the lost-explorer threat model appendix.

Not covered

  • One feature, story or PR, with attacker stories, Gherkin criteria and a code check: use /security-review.
  • A portfolio-wide sweep of every k8mak.com app across security, Vercel and Supabase: use /site-audit.
  • Drawing the architecture from scratch: use /system-diagram.
  • A third-party vendor's posture: use /vendor-security-assessment.
  • Cloud identity sprawl and permission scope: use /identity-permission-audit.
  • AI failures with no attacker (hallucination, drift): use /ai-failure-mode-analysis.
  • Mapping controls to a compliance framework: use /compliance-map.
  • Plan-level risks that are not security (adoption, delivery, market): use /pre-mortem.

Example Output

  • Built Next.js and Supabase app (2026-10-28): assets/lost-explorer/experience-sweep-2026-10/03-threat-model.md, guyswherearewe.com read at a named commit: all 37 route handlers, auth, rate limiting and 15 migrations, a boundary map (B1 to B6), 19 scored threats led by a shared service-role key's blast radius, a "found sound" list, mitigations, open questions and an appendix of anonymous live checks. Its Step 3b note ("no model SDKs in package.json") is the not-applicable pattern Step 4 asks for.

examples.md is an illustration generated for the site (a fictional patient portal), not a past run; use it for the output shape only.

Run this now

0/4000

Part of these Playbook topics

One tool, one hard lesson. Only when there is something worth sending.

Occasional emails. Unsubscribe any time.