Security Threat Model
Deliver an actionable AppSec-grade threat model specific to the repository or a
project path. Anchor every architectural claim to evidence in the repo; keep
assumptions explicit. Prioritize realistic attacker goals and concrete impacts
over generic checklists.
Quality rules (apply throughout)
- Evidence-grounded: every component, data flow, or control must be backed by
at least one repo path and, where helpful, a symbol name, config key, or short
quoted snippet. Do not invent components.
- No secrets in output: if you find tokens, keys, or passwords, redact them
and describe their presence and location only.
- Scope discipline: separate production/runtime behavior from CI/build/dev
tooling and from tests/examples. Separate attacker-controlled inputs from
operator-controlled and developer-controlled inputs.
- Concise for AppSec engineers: use precise terminology; include mitigations
and residual risks; avoid restating large blocks of README/spec.
Workflow
1. Collect inputs
Ask the user (or infer and mark as assumptions):
- Intended usage and deployment model (server, CLI, library, worker)
- Internet exposure (public, internal, air-gapped)
- Authentication / authorization expectations
- Data sensitivity (PII, credentials, financial, public)
- Any explicitly out-of-scope paths
If the user provided a path argument, scope the model to that sub-path.
2. Explore the repo
Use file search, grep -rI (skip binaries), or ripgrep rg (skips binaries by
default) to locate security-relevant surfaces:
- Network listeners, routes, endpoints, RPC handlers, message consumers
- Auth, session/token handling, RBAC/ACL logic
- Parsing/deserialization (JSON/YAML/XML/protobuf), template rendering,
eval
- File upload/read paths, archive extraction, image/document parsing
- Database, queue, and cache clients and query construction
- Secrets/config loading, environment variables, key management
- SSRF-capable HTTP clients, webhooks, URL fetchers
- Sandboxing, privilege boundaries, subprocess execution
- Logging/error handling paths
- CI/build pipelines, dependency management, artifact publishing
3. Build the system model
- List primary components and how they interact.
- Enumerate data flows and trust boundaries: for each boundary specify source →
destination, data types crossing, channel/protocol, security guarantees
(auth, TLS, origin checks, schema validation, rate limits).
- Produce a compact Mermaid flowchart (see diagram rules below).
4. Enumerate assets and attacker model
- List assets that drive risk: credentials, PII, integrity-critical state,
availability-critical components, build artifacts.
- Describe realistic attacker capabilities based on exposure and intended usage.
- Explicitly note non-capabilities to avoid inflated severity.
5. Enumerate threats as abuse paths
- Prefer multi-step attacker stories tied to entry points and trust boundaries.
- Classify each threat: exfiltration, privilege escalation, integrity compromise,
denial of service, supply-chain attack.
6. Prioritize with explicit reasoning
For each threat assign:
- Likelihood: low / medium / high (1–2 sentence justification)
- Impact: low / medium / high (1–2 sentence justification)
- Priority: critical / high / medium / low (likelihood × impact, adjusted for
existing controls)
Risk priority guidance (illustrative):
- Critical: pre-auth RCE, auth bypass, cross-tenant access, sensitive data
exfiltration, key or token theft, sandbox escape
- High: targeted DoS of critical components, partial data exposure, rate-limit
bypass with measurable impact, privilege escalation with realistic prerequisites
- Medium: log/metrics poisoning affecting detection, partial info leaks with
meaningful exposure
- Low: low-sensitivity info leaks, noisy DoS with easy mitigation, issues
requiring unlikely preconditions
7. Validate assumptions with the user (required)
Before producing the final report:
- Summarize the 3–6 key assumptions that most affect scope or risk ranking.
- Ask 1–3 targeted questions to resolve missing context (deployment environment,
scale, auth model, internet exposure, data sensitivity, multi-tenancy).
- Wait for user feedback. If the user cannot answer, proceed with explicit
assumptions and mark any conditional conclusions.
8. Write the report
Produce valid Markdown following the required output format below. Write it to a
file named <repo-or-dir-name>-threat-model.md (use the basename of the repo
root, or the in-scope directory if asked to model a sub-path). Then summarize
the top findings to the user.
Run a quality check before writing:
- All discovered entry points are covered.
- Each trust boundary appears in at least one threat.
- Runtime vs CI/dev separation is maintained.
- User clarifications (or explicit non-responses) are reflected.
- Assumptions and open questions are explicit.
Mermaid diagram rules
Use flowchart TD or flowchart LR only. Rules:
- Only
--> arrows; edge labels limited to plain words via -->|label|.
- Simple node IDs (letters/numbers/underscores only); quoted labels
(
A["Label"]); avoid A(Label) shape syntax.
- No
title lines or style directives.
- No file paths, URLs, or socket paths in node labels (put those in prose).
- Wrap in a fenced
mermaid block.
Required output format
## Executive summary
One paragraph: top risk themes and highest-risk areas.
## Scope and assumptions
In-scope paths, out-of-scope items, explicit assumptions, open questions.
## System model
### Primary components
### Data flows and trust boundaries
Arrow-style bullets (e.g., Internet → API Server). For each boundary: data
types, channel/protocol, security guarantees, input validation.
#### Diagram
<mermaid flowchart>
## Assets and security objectives
Table: Asset | Why it matters | Security objective (C/I/A)
## Attacker model
### Capabilities
### Non-capabilities
## Entry points and attack surfaces
Table: Surface | How reached | Trust boundary | Notes | Evidence (repo path/symbol)
## Top abuse paths
5–10 numbered multi-step sequences: attacker goal → steps → impact.
## Threat model table
Columns: Threat ID | Threat source | Prerequisites | Threat action | Impact |
Impacted assets | Existing controls (evidence) | Gaps | Recommended mitigations |
Detection ideas | Likelihood | Impact severity | Priority
Rules: Threat IDs as TM-001, TM-002, …; Priority one of critical/high/medium/low.
## Criticality calibration
Define critical/high/medium/low for this repo's context. Include 2–3 examples
per level tailored to the repo's assets and exposure.
## Focus paths for security review
2–30 repo-relative paths with one-sentence reason each.
## Quality checklist
Short checklist confirming coverage of entry points, trust boundaries,
runtime/CI separation, user clarifications, and assumptions.
1---2name: security-threat-model3description: Repository-grounded threat modeling that enumerates trust boundaries, assets, attacker capabilities, abuse paths, and mitigations, and writes a concise Markdown threat model. Trigger only when the user explicitly asks to threat model a codebase or path, enumerate threats/abuse paths, or perform AppSec threat modeling. Do not trigger for general architecture summaries, code review, or non-security design work.4---5
6# Security Threat Model
7
8Deliver an actionable AppSec-grade threat model specific to the repository or a
9project path. Anchor every architectural claim to evidence in the repo; keep
10assumptions explicit. Prioritize realistic attacker goals and concrete impacts
11over generic checklists.
12
13## Quality rules (apply throughout)
14
15- **Evidence-grounded**: every component, data flow, or control must be backed by
16 at least one repo path and, where helpful, a symbol name, config key, or short
17 quoted snippet. Do not invent components.
18- **No secrets in output**: if you find tokens, keys, or passwords, redact them
19 and describe their presence and location only.
20- **Scope discipline**: separate production/runtime behavior from CI/build/dev
21 tooling and from tests/examples. Separate attacker-controlled inputs from
22 operator-controlled and developer-controlled inputs.
23- **Concise for AppSec engineers**: use precise terminology; include mitigations
24 and residual risks; avoid restating large blocks of README/spec.
25
26## Workflow
27
28### 1. Collect inputs
29
30Ask the user (or infer and mark as assumptions):
31
32- Intended usage and deployment model (server, CLI, library, worker)
33- Internet exposure (public, internal, air-gapped)
34- Authentication / authorization expectations
35- Data sensitivity (PII, credentials, financial, public)
36- Any explicitly out-of-scope paths
37
38If the user provided a path argument, scope the model to that sub-path.
39
40### 2. Explore the repo
41
42Use file search, `grep -rI` (skip binaries), or ripgrep `rg` (skips binaries by
43default) to locate security-relevant surfaces:
44
45- Network listeners, routes, endpoints, RPC handlers, message consumers
46- Auth, session/token handling, RBAC/ACL logic
47- Parsing/deserialization (JSON/YAML/XML/protobuf), template rendering, `eval`
48- File upload/read paths, archive extraction, image/document parsing
49- Database, queue, and cache clients and query construction
50- Secrets/config loading, environment variables, key management
51- SSRF-capable HTTP clients, webhooks, URL fetchers
52- Sandboxing, privilege boundaries, subprocess execution
53- Logging/error handling paths
54- CI/build pipelines, dependency management, artifact publishing
55
56### 3. Build the system model
57
58- List primary components and how they interact.
59- Enumerate data flows and trust boundaries: for each boundary specify source →
60 destination, data types crossing, channel/protocol, security guarantees
61 (auth, TLS, origin checks, schema validation, rate limits).
62- Produce a compact **Mermaid flowchart** (see diagram rules below).
63
64### 4. Enumerate assets and attacker model
65
66- List assets that drive risk: credentials, PII, integrity-critical state,
67 availability-critical components, build artifacts.
68- Describe realistic attacker capabilities based on exposure and intended usage.
69- Explicitly note non-capabilities to avoid inflated severity.
70
71### 5. Enumerate threats as abuse paths
72
73- Prefer multi-step attacker stories tied to entry points and trust boundaries.
74- Classify each threat: exfiltration, privilege escalation, integrity compromise,
75 denial of service, supply-chain attack.
76
77### 6. Prioritize with explicit reasoning
78
79For each threat assign:
80
81- **Likelihood**: low / medium / high (1–2 sentence justification)
82- **Impact**: low / medium / high (1–2 sentence justification)
83- **Priority**: critical / high / medium / low (likelihood × impact, adjusted for
84 existing controls)
85
86Risk priority guidance (illustrative):
87
88- **Critical**: pre-auth RCE, auth bypass, cross-tenant access, sensitive data
89 exfiltration, key or token theft, sandbox escape
90- **High**: targeted DoS of critical components, partial data exposure, rate-limit
91 bypass with measurable impact, privilege escalation with realistic prerequisites
92- **Medium**: log/metrics poisoning affecting detection, partial info leaks with
93 meaningful exposure
94- **Low**: low-sensitivity info leaks, noisy DoS with easy mitigation, issues
95 requiring unlikely preconditions
96
97### 7. Validate assumptions with the user (required)
98
99Before producing the final report:
100
1011. Summarize the 3–6 key assumptions that most affect scope or risk ranking.
1022. Ask 1–3 targeted questions to resolve missing context (deployment environment,
103 scale, auth model, internet exposure, data sensitivity, multi-tenancy).
1043. **Wait for user feedback.** If the user cannot answer, proceed with explicit
105 assumptions and mark any conditional conclusions.
106
107### 8. Write the report
108
109Produce valid Markdown following the required output format below. Write it to a
110file named `<repo-or-dir-name>-threat-model.md` (use the basename of the repo
111root, or the in-scope directory if asked to model a sub-path). Then summarize
112the top findings to the user.
113
114Run a quality check before writing:
115
116- All discovered entry points are covered.
117- Each trust boundary appears in at least one threat.
118- Runtime vs CI/dev separation is maintained.
119- User clarifications (or explicit non-responses) are reflected.
120- Assumptions and open questions are explicit.
121
122## Mermaid diagram rules
123
124Use `flowchart TD` or `flowchart LR` only. Rules:
125
126- Only `-->` arrows; edge labels limited to plain words via `-->|label|`.
127- Simple node IDs (letters/numbers/underscores only); quoted labels
128 (`A["Label"]`); avoid `A(Label)` shape syntax.
129- No `title` lines or `style` directives.
130- No file paths, URLs, or socket paths in node labels (put those in prose).
131- Wrap in a fenced `mermaid` block.
132
133## Required output format
134
135```
136## Executive summary
137One paragraph: top risk themes and highest-risk areas.
138
139## Scope and assumptions
140In-scope paths, out-of-scope items, explicit assumptions, open questions.
141
142## System model
143### Primary components
144### Data flows and trust boundaries
145Arrow-style bullets (e.g., Internet → API Server). For each boundary: data
146types, channel/protocol, security guarantees, input validation.
147#### Diagram
148<mermaid flowchart>
149
150## Assets and security objectives
151Table: Asset | Why it matters | Security objective (C/I/A)
152
153## Attacker model
154### Capabilities
155### Non-capabilities
156
157## Entry points and attack surfaces
158Table: Surface | How reached | Trust boundary | Notes | Evidence (repo path/symbol)
159
160## Top abuse paths
1615–10 numbered multi-step sequences: attacker goal → steps → impact.
162
163## Threat model table
164Columns: Threat ID | Threat source | Prerequisites | Threat action | Impact |
165Impacted assets | Existing controls (evidence) | Gaps | Recommended mitigations |
166Detection ideas | Likelihood | Impact severity | Priority
167
168Rules: Threat IDs as TM-001, TM-002, …; Priority one of critical/high/medium/low.
169
170## Criticality calibration
171Define critical/high/medium/low for this repo's context. Include 2–3 examples
172per level tailored to the repo's assets and exposure.
173
174## Focus paths for security review
1752–30 repo-relative paths with one-sentence reason each.
176
177## Quality checklist
178Short checklist confirming coverage of entry points, trust boundaries,
179runtime/CI separation, user clarifications, and assumptions.
180```