Analyze codebase architecture to generate a STRIDE-based threat model with data flow diagrams, trust boundaries, prioritized threats, and mitigations. Compatible with Microsoft Threat Modeling Tool concepts. Use when asked to "threat model", "security analysis", "STRIDE analysis", "identify security threats", "data flow security", "generate a threat model", or "security architecture review".
Produce a structured threat model using the STRIDE methodology, compatible with Microsoft Threat Modeling Tool concepts.
| Category | Threat | Property Violated |
|---|---|---|
| Spoofing | Impersonating another identity | Authentication |
| Tampering | Unauthorized modification of data | Integrity |
| Repudiation | Denying actions with no proof | Non-repudiation |
| Information Disclosure | Exposing data to unauthorized parties | Confidentiality |
| Denial of Service |
| Making a resource unavailable |
| Availability |
| Elevation of Privilege | Gaining unauthorized privileged access | Authorization |
| Element | Description |
|---|---|
| Process | Code that transforms data (services, APIs, workers) |
| External Interactor | Entities outside your control (users, third-party APIs) |
| Data Store | Persistent storage (databases, files, caches, queues) |
| Data Flow | Data movement between elements (label with protocol) |
| Trust Boundary | Separation between zones of different trust |
Identify: the system under analysis, the deployment model (cloud/on-prem/hybrid), stakeholders, and security requirements (compliance, data classification).
Scan the codebase to identify all DFD elements:
| What to Find | Where to Look |
|---|---|
| Processes | Service entry points, API controllers, background workers, message handlers |
| External interactors | HTTP clients, SDK integrations, user-facing endpoints, webhook receivers |
| Data stores | Database connections, file system access, cache clients, queue producers/consumers |
| Data flows | API routes with request/response types, message contracts, file I/O |
| Trust boundaries | Authentication middleware, authorization decorators, API gateway config |
| Secrets | Connection strings, API keys, certificates, token handling |
Generate a Mermaid diagram with:
subgraph blocks for each trust boundaryFor each data flow crossing a trust boundary, systematically check all 6 STRIDE categories. Record each threat:
| Field | Content |
|---|---|
| ID | T-001, T-002, etc. |
| Element | Which DFD element/interaction |
| STRIDE | S, T, R, I, D, or E |
| Description | What could go wrong |
| Severity | Critical (RCE, auth bypass, full breach) / High (privilege escalation, significant exposure) / Medium (limited exposure, DoS) / Low (info leakage, minor impact) |
| Existing Controls | What the code already does (reference files) |
| Mitigation | What to add or change |
Recommend mitigations from recognized categories: Authentication, Authorization, Input Validation, Cryptography, Auditing & Logging, Communication Security, Configuration Management, Exception Management, Session Management, Sensitive Data handling.
Structure the output as:
User: "Threat model the authentication service."
Output (abbreviated):
Scope: AuthService — OAuth2 + JWT, Azure App Service, PII (email, name)
DFD: Browser →HTTPS→ API Gateway →HTTP→ AuthController →TLS→ SQL Database
[Trust Boundary] ├→HTTPS→ Azure AD | └→TLS→ Redis
Threats (3 of 8):
T-001 | Gateway→AuthController | Spoofing | Medium
Plain HTTP internal traffic. → Enable mTLS or private VNet.
T-002 | AuthController→SQL | Info Disclosure | High
Connection string in appsettings.json. → Migrate to Key Vault.
T-003 | Browser→Gateway | Tampering | Medium
JWT in localStorage (XSS risk). → Use HttpOnly secure cookies.
Verdict: CONDITIONAL — 2 High threats need remediation before production.
User prompt: "Threat model this API"
Agent actions:
src/api/) with PostgreSQL, Redis cache, and a third-party Stripe integration. Data classification: PII (email, address) and payment tokens.Generated threat model (abbreviated):
## Data Flow Diagram
Browser →HTTPS→ [Auth Middleware] →HTTP→ OrderController →TLS→ PostgreSQL
├→HTTPS→ Stripe API
└→TCP→ Redis
## Threats (4 of 9):
| ID | Element | STRIDE | Severity | Mitigation |
|-------|----------------------------|--------|----------|-----------------------------------|
| T-001 | Browser→AuthMiddleware | S | High | Add rate limiting + account lockout |
| T-002 | OrderController→PostgreSQL | I | Critical | Parameterize all queries; audit ORM usage |
| T-003 | OrderController→Stripe | T | High | Verify Stripe webhook signatures |
| T-004 | AuthMiddleware→Redis | I | Medium | Enable TLS for Redis connection |
## Verdict
CONDITIONAL — 1 Critical + 2 High threats require remediation before production.
Top actions: (1) Parameterize DB queries, (2) Verify webhook signatures, (3) Add rate limiting.
Result: STRIDE-based threat model with code-referenced DFD, prioritized threats, and a mitigation plan — ready for security review.
| Scenario | Action |
|---|---|
| Codebase has no identifiable services or entry points | Report that no evaluable architecture was found; ask the user to clarify scope |
| Cannot detect authentication/authorization mechanisms | Note the absence as a Critical finding (missing auth) rather than skipping |
| Source files referenced in DFD are missing or inaccessible | Mark the element with "(file not found)" and flag for manual verification |
| Scope is too broad (entire monorepo) | Ask user to narrow to a specific service or module |