Threat Modeling skill for Claude Code
Find design flaws before they become incidents. Gives Claude a disciplined STRIDE process instead of a generic list of scary threats. It builds a Mermaid data flow diagram from your code and configs, marks trust boundaries, enumerates threats per element, cites existing controls by file, and ranks residual risk. The output is a versioned model document with owners, tickets, and explicitly accepted risks.
- Name
threat-modeling- Size
- 189 lines · ≈2,000 tokens
- Every turn
- ≈115 tokens · 6% of listing
- Files
- 1
- License
- MIT
- Updated
What Claude sees before loading it
This description is the only part of the skill that sits in context all the time: about 115 tokens on every turn, out of a skill listing budget of roughly 2,000 tokens on a 200K-token model that every installed skill shares. Claude reads it to decide when to load the full playbook below. How many skills fit.
description: Builds STRIDE threat models for systems and features — data flow diagrams in Mermaid, trust boundaries, per-element threat enumeration, existing and missing mitigations, and a risk-ranked action list. Use when designing a new service or feature, before a security review, when adding a third-party integration, handling sensitive data, crossing a new trust boundary, or when asked to "threat model this", "what could go wrong", or "STRIDE". Try asking
- Threat model the new Stripe webhook and payout flow before we build it
- We're adding SSO with Okta — what could go wrong? Use STRIDE
- Create a threat model doc for our file-sharing service and rank the risks
What changes with it installed
A common default approach to this work, and what the playbook has Claude Code do instead.
| Without the skill | With threat-modeling |
|---|---|
| Lists fifty generic threats like DDoS and SQL injection without tying any of them to a component or flow | Attaches each threat to a DFD element using STRIDE per element: external entities get S and R, processes all six |
| Draws an architecture diagram from guesses, inventing a cache or queue the codebase does not actually contain | Builds the Mermaid data flow diagram from code, configs and docs, labeling every flow with protocol, data and authentication |
| Marks a threat as mitigated because the team says so, with no pointer to where the control lives | Cites each existing mitigation by file and line or config key, and records controls it cannot find as planned or missing |
Use it when
- A new service, feature, or integration is being designed
- Sensitive data or money starts flowing through a new path
- A compliance review or security team asks for a threat model
- An existing architecture needs a prioritized list of security gaps
Skip it when
- You need a line-by-line review of existing code — use owasp-review instead
- The task is diagram notation itself rather than risk — use c4-diagrams instead
How to check the result
Every boundary-crossing flow in the diagram has threats considered, every existing mitigation cites a file or setting, and every High or Critical risk has an owner and ticket.
The common mistake it prevents
Treating traffic inside the VPC as trusted and skipping the compromised-internal-service scenario, which is exactly how lateral movement succeeds.
A threat model is done when it answers four questions with evidence: what are we building (a diagram that matches reality), what can go wrong (threats tied to specific elements and boundaries), what are we doing about it (mitigation per threat, existing or planned, with an owner), and did we do a good job (review against the diagram and open risks accepted by name).
Ground rules
- Model the system as it is or will be built, from code, configs, and architecture docs. Ask the user when the data flow is unknown; never invent components.
- Threats attach to diagram elements and to flows crossing trust boundaries. A threat with no element is a brainstorm, not a model.
- Prefer ten specific, ranked threats over fifty generic ones.
- Scope one feature or service per model. A whole company in one diagram is unreadable.
Workflow
- [ ] 1. Define scope, assets, and security objectives
- [ ] 2. Draw the data flow diagram (DFD) with trust boundaries
- [ ] 3. Enumerate threats per element with STRIDE
- [ ] 4. Record existing mitigations from code/config
- [ ] 5. Rank residual risk
- [ ] 6. Decide: mitigate, transfer, accept, or eliminate — with owners
- [ ] 7. Write the model document and validation notes
1. Scope and assets
Write down:
- In scope: the feature/service, its data stores, its external dependencies.
- Assets: what an attacker wants — credentials, PII, payment data, tenant data, signing keys, compute, availability, reputation.
- Actors: anonymous users, authenticated users per role, admins, internal services, third parties, operators with prod access.
- Assumptions: e.g. “TLS terminates at the load balancer”, “the IdP is trusted”. Assumptions are where real attacks live; list them explicitly so they can be challenged.
Gather evidence before drawing:
ls docs/ adr/ architecture/ 2>/dev/null
grep -rnE "https?://[a-z0-9.-]+" --include=*.{env.example,yaml,yml,toml,json} . | grep -v node_modules | head -50
grep -rniE "s3|bucket|queue|sqs|pubsub|kafka|redis|postgres|mongo|stripe|twilio|webhook" --include=*.{ts,js,py,go,yaml,tf} . | cut -d: -f1 | sort -u | head -40
2. Data flow diagram
DFD element types: external entity (actor/system you do not control), process (your code), data store, data flow, trust boundary. Draw it in Mermaid so it lives in the repo:
flowchart LR
subgraph Internet[Untrusted: Internet]
U[User browser]
S[Stripe]
end
subgraph DMZ[Boundary: edge]
LB[Load balancer / WAF]
end
subgraph App[Trusted: app VPC]
API[API service]
W[Webhook worker]
Q[(Job queue)]
DB[(Postgres: orders, PII)]
end
U -- "HTTPS: login, orders (JWT)" --> LB --> API
API -- "SQL over TLS" --> DB
S -- "HTTPS webhook (signed)" --> LB --> W
W --> Q --> API
API -- "HTTPS: create PaymentIntent" --> S
Label every flow with protocol, data, and authentication. Every arrow crossing a subgraph edge is a trust-boundary crossing and gets the most scrutiny.
3. STRIDE per element
| Threat | Violates | Applies to | Ask |
|---|---|---|---|
| Spoofing | Authentication | External entities, processes | Can someone pretend to be this user/service? |
| Tampering | Integrity | Flows, stores, processes | Can data be modified in transit, at rest, or in the client? |
| Repudiation | Non-repudiation | Processes, external entities | Could an actor deny an action because we lack audit evidence? |
| Information disclosure | Confidentiality | Flows, stores, processes | Can data leak via responses, logs, errors, backups, side channels? |
| Denial of service | Availability | Processes, stores, flows | Can someone exhaust CPU, memory, connections, quotas, money? |
| Elevation of privilege | Authorization | Processes | Can a lower-privileged actor do something reserved for a higher one? |
STRIDE-per-element shortcut: external entities get S and R; data flows get T, I, D; data stores get T, I, D (and R if they hold audit logs); processes get all six.
High-yield threats to check at every boundary crossing:
- Missing or bypassable authentication on internal endpoints (“it’s inside the VPC”).
- Object-level authorization (IDOR) and tenant isolation.
- Webhook/callback spoofing without signature verification and replay window.
- Secrets in env vars readable by too many processes, or in logs.
- SSRF from any process that fetches URLs into the trusted zone.
- Unbounded inputs: file sizes, pagination, regex, batch sizes, LLM tokens.
- Admin and support tooling with broad data access and weak audit.
- Third-party compromise: what happens if Stripe/IdP/CDN/npm package is malicious?
4. Existing mitigations
For each threat, look for the control in code or config and cite it
(middleware/auth.ts:22 verifies JWT signature and aud). A mitigation you cannot find
is “planned” or “missing”, not “existing”.
5. Rank risk
Use a simple, explainable scale; do not pretend to precision.
| Likelihood \ Impact | Low | Medium | High |
|---|---|---|---|
| High (unauthenticated, easy, known technique) | Medium | High | Critical |
| Medium (needs account or specific condition) | Low | Medium | High |
| Low (needs insider, chained bugs, rare config) | Low | Low | Medium |
Impact anchors: High = cross-tenant data, credential/key compromise, payment fraud, full outage. Medium = single-user data, partial degradation. Low = minor info leak.
6. Decide
| Response | When |
|---|---|
| Mitigate | Default for High/Critical; add a control and a test |
| Eliminate | Remove the feature, data, or flow (often cheapest: stop storing it) |
| Transfer | Push to a provider with a contract (hosted payments page, managed IdP) |
| Accept | Low risk or cost exceeds impact; requires a named approver and review date |
7. Output
# Threat model: <feature/service>
**Version / date:** v1, 2026-03-02 **Authors:** ... **Reviewers:** ...
**Scope:** ... **Out of scope:** ...
## Assets and actors
...
## Assumptions
1. TLS terminates at LB; traffic inside VPC is plaintext. (Challenge: is that acceptable?)
## Data flow diagram
<mermaid block>
## Threats
| ID | Element / flow | STRIDE | Threat | Existing mitigation | Risk | Response | Owner |
|---|---|---|---|---|---|---|---|
| T1 | Stripe -> Webhook worker | S, T | Forged webhook marks order paid | None found | Critical | Mitigate: verify `Stripe-Signature`, 5-min tolerance | @payments |
| T2 | API -> DB | I | Orders endpoint returns other tenants' rows | tenant_id filter in repo layer (orders.repo.ts:40) | Low | Accept, add regression test | @api |
## Actions
- [ ] T1 verify webhook signatures (owner, due date, ticket)
## Accepted risks
| ID | Rationale | Approver | Review by |
## Validation
- Diagram reviewed against deployed infra on <date>; differences: ...
Gotchas
- Diagrams drift. Store the model next to the code and update it in the PR that changes a flow or boundary.
- “Internal” is not a trust level. Model the compromised-internal-service case: what can one popped container reach?
- Do not stop at the happy path: include admin flows, background jobs, backups, data exports, CI/CD with deploy credentials, and support tooling.
- Repudiation is the most skipped category; audit logs for money movement and permission changes are cheap and often legally required.
- LLM features add boundaries: model output is untrusted input to anything it calls. Hand depth to prompt-injection-defense.
Verification
- Every boundary-crossing flow in the diagram has at least one threat considered or a written reason it has none.
- Every “existing mitigation” cites a file, config key, or provider setting.
- Every High/Critical has an owner and a ticket; every accepted risk has an approver.
- Walk the diagram with someone who operates the system; fix any element they do not recognize before ranking.
Questions about Threat Modeling
What does STRIDE stand for in threat modeling?
Spoofing, Tampering, Repudiation, Information disclosure, Denial of service and Elevation of privilege, where a lower-privileged actor does something reserved for a higher one. Each maps to the property it violates: authentication, integrity, non-repudiation, confidentiality, availability and authorization. The per-element shortcut applies S and R to external entities, T, I and D to data flows and data stores, and all six to processes. Repudiation is the most skipped category, yet audit logs for money movement and permission changes are cheap and often legally required.
How should I rank threats once they are identified?
Use a three-by-three likelihood and impact grid rather than a precise numeric score. High likelihood means unauthenticated, easy or a known technique; medium needs an account or a specific condition; low needs an insider or chained bugs. High impact covers cross-tenant data, key compromise, payment fraud or a full outage, and high likelihood with high impact is Critical. Mitigate High and Critical risks by default with a control and a test; accepting a risk needs a named approver and a review date.
Where should Claude Code save a threat model in the repository?
Next to the code it describes, as a versioned Markdown document with the Mermaid diagram inline. Diagrams drift, so update the model in the same pull request that changes a flow or trust boundary, and ask Claude Code to re-check it then. Keep one feature or service per model, and give it architecture docs or describe unknown flows, because the skill tells Claude to ask rather than invent components. For a line-by-line audit of the resulting code, use owasp-review.
About this skill
Drafted with AI assistance to the site's editorial standard (a selective trigger, a real workflow, known pitfalls and a verification step) and maintained by Atif M.. First published , last updated . MIT licensed.