Threat Model Generation
Generate a comprehensive security threat model for a repository using the STRIDE methodology.
When to Use This Skill
- First-time setup - New repository needs initial threat model
- Architecture changes - Significant changes to components, APIs, or data flows
- Security audit - Periodic review or compliance requirement
- Manual request - Security team requests updated threat model
Inputs
| Input |
Description |
Required |
| Repository path |
Root directory to analyze |
Yes (default: current directory) |
| Existing threat model |
Path to existing .factory/threat-model.md if updating |
No |
| Compliance requirements |
Frameworks to consider (SOC2, GDPR, HIPAA, etc.) |
No |
Instructions
Step 1: Analyze Repository Structure
Scan the codebase to understand the system:
Identify languages and frameworks
- Check
package.json, requirements.txt, go.mod, Cargo.toml, etc.
- Note the primary tech stack
Map components and services
- Look for
apps/, services/, packages/ directories
- Identify entry points: API routes, CLI commands, web handlers
- Note databases, caches, message queues
Identify external interfaces
- HTTP endpoints (REST, GraphQL)
- File upload handlers
- Webhook receivers
- OAuth/SSO integrations
Trace data flows
- How does user input enter the system?
- Where is sensitive data stored?
- What external services are called?
Step 2: Identify Trust Boundaries
Define security zones:
Public Zone (untrusted)
- All external HTTP endpoints
- Public APIs without authentication
- User-uploaded files
Authenticated Zone (partially trusted)
- Endpoints requiring valid session/token
- User-specific data access
- Rate-limited APIs
Internal Zone (trusted)
- Service-to-service communication
- Admin-only endpoints
- Database connections
- Secrets management
Step 3: Inventory Critical Assets
Classify data by sensitivity:
PII (Personally Identifiable Information)
- User emails, names, addresses, phone numbers
- Document protection measures
Credentials & Secrets
- Password hashes, API keys, OAuth tokens
- JWT signing keys, encryption keys
Business-Critical Data
- Transaction records, customer data
- Proprietary algorithms, trade secrets
Step 4: Apply STRIDE Analysis
For each major component, analyze threats:
S - Spoofing Identity
- Can attackers impersonate users or services?
- Are authentication mechanisms secure?
T - Tampering with Data
- Can attackers modify data in transit or at rest?
- Look for: SQL injection, XSS, mass assignment, missing input validation
R - Repudiation
- Can users deny actions they performed?
- Look for: missing audit logs, insufficient logging
I - Information Disclosure
- Can attackers access data they shouldn't?
- Look for: IDOR, verbose errors, hardcoded secrets
D - Denial of Service
- Can attackers disrupt service availability?
- Look for: missing rate limits, resource exhaustion
E - Elevation of Privilege
- Can attackers gain unauthorized access levels?
- Look for: missing authorization checks, role manipulation
Step 5: Document Vulnerability Patterns
Create a library of code patterns specific to this codebase's tech stack.
Step 6: Generate Output Files
Create two files:
1. .factory/threat-model.md
Comprehensive threat model with:
- System overview with architecture description
- Trust boundaries and security zones
- Attack surface inventory
- Critical assets classification
- STRIDE threat analysis for each component
- Vulnerability pattern library
- Security testing strategy
- Assumptions and accepted risks
- Version changelog
2. .factory/security-config.json
{
"threat_model_version": "1.0.0",
"last_updated": "<ISO timestamp>",
"security_team_contacts": [],
"compliance_requirements": [],
"scan_frequency": "on_commit",
"severity_thresholds": {
"block_merge": ["CRITICAL"],
"require_review": ["HIGH", "CRITICAL"],
"notify_security_team": ["CRITICAL"]
},
"vulnerability_patterns": {
"enabled": [
"sql_injection",
"xss",
"command_injection",
"path_traversal",
"auth_bypass",
"idor"
]
}
}
Success Criteria
Example Invocations
Generate initial threat model:
Generate a threat model for this repository.
Update existing threat model:
Update the threat model - we added a new payments service.
Generate with compliance requirements:
Generate a threat model for this repository. We need to comply with SOC2 and GDPR.
1---2name: threat-model-generation3description: Generate a STRIDE-based security threat model for a repository. Use when setting up security monitoring, after architecture changes, or for security audits.4---56# Threat Model Generation78Generate a comprehensive security threat model for a repository using the STRIDE methodology.910## When to Use This Skill1112- **First-time setup** - New repository needs initial threat model13- **Architecture changes** - Significant changes to components, APIs, or data flows14- **Security audit** - Periodic review or compliance requirement15- **Manual request** - Security team requests updated threat model1617## Inputs1819| Input | Description | Required |20| ----------------------- | ------------------------------------------------------- | -------------------------------- |21| Repository path | Root directory to analyze | Yes (default: current directory) |22| Existing threat model | Path to existing `.factory/threat-model.md` if updating | No |23| Compliance requirements | Frameworks to consider (SOC2, GDPR, HIPAA, etc.) | No |2425## Instructions2627### Step 1: Analyze Repository Structure2829Scan the codebase to understand the system:30311. **Identify languages and frameworks**32 - Check `package.json`, `requirements.txt`, `go.mod`, `Cargo.toml`, etc.33 - Note the primary tech stack34352. **Map components and services**36 - Look for `apps/`, `services/`, `packages/` directories37 - Identify entry points: API routes, CLI commands, web handlers38 - Note databases, caches, message queues39403. **Identify external interfaces**41 - HTTP endpoints (REST, GraphQL)42 - File upload handlers43 - Webhook receivers44 - OAuth/SSO integrations45464. **Trace data flows**47 - How does user input enter the system?48 - Where is sensitive data stored?49 - What external services are called?5051### Step 2: Identify Trust Boundaries5253Define security zones:54551. **Public Zone** (untrusted)56 - All external HTTP endpoints57 - Public APIs without authentication58 - User-uploaded files59602. **Authenticated Zone** (partially trusted)61 - Endpoints requiring valid session/token62 - User-specific data access63 - Rate-limited APIs64653. **Internal Zone** (trusted)66 - Service-to-service communication67 - Admin-only endpoints68 - Database connections69 - Secrets management7071### Step 3: Inventory Critical Assets7273Classify data by sensitivity:74751. **PII (Personally Identifiable Information)**76 - User emails, names, addresses, phone numbers77 - Document protection measures78792. **Credentials & Secrets**80 - Password hashes, API keys, OAuth tokens81 - JWT signing keys, encryption keys82833. **Business-Critical Data**84 - Transaction records, customer data85 - Proprietary algorithms, trade secrets8687### Step 4: Apply STRIDE Analysis8889For each major component, analyze threats:9091#### S - Spoofing Identity92- Can attackers impersonate users or services?93- Are authentication mechanisms secure?9495#### T - Tampering with Data96- Can attackers modify data in transit or at rest?97- Look for: SQL injection, XSS, mass assignment, missing input validation9899#### R - Repudiation100- Can users deny actions they performed?101- Look for: missing audit logs, insufficient logging102103#### I - Information Disclosure104- Can attackers access data they shouldn't?105- Look for: IDOR, verbose errors, hardcoded secrets106107#### D - Denial of Service108- Can attackers disrupt service availability?109- Look for: missing rate limits, resource exhaustion110111#### E - Elevation of Privilege112- Can attackers gain unauthorized access levels?113- Look for: missing authorization checks, role manipulation114115### Step 5: Document Vulnerability Patterns116117Create a library of code patterns specific to this codebase's tech stack.118119### Step 6: Generate Output Files120121Create two files:122123#### 1. `.factory/threat-model.md`124125Comprehensive threat model with:126- System overview with architecture description127- Trust boundaries and security zones128- Attack surface inventory129- Critical assets classification130- STRIDE threat analysis for each component131- Vulnerability pattern library132- Security testing strategy133- Assumptions and accepted risks134- Version changelog135136#### 2. `.factory/security-config.json`137138```json139{140 "threat_model_version": "1.0.0",141 "last_updated": "<ISO timestamp>",142 "security_team_contacts": [],143 "compliance_requirements": [],144 "scan_frequency": "on_commit",145 "severity_thresholds": {146 "block_merge": ["CRITICAL"],147 "require_review": ["HIGH", "CRITICAL"],148 "notify_security_team": ["CRITICAL"]149 },150 "vulnerability_patterns": {151 "enabled": [152 "sql_injection",153 "xss",154 "command_injection",155 "path_traversal",156 "auth_bypass",157 "idor"158 ]159 }160}161```162163## Success Criteria164165- [ ] `.factory/threat-model.md` exists with all sections populated166- [ ] `.factory/security-config.json` exists with valid JSON167- [ ] All major components have STRIDE analysis168- [ ] Vulnerability patterns match the tech stack169- [ ] Document is written in natural language (LLM-readable)170- [ ] No placeholder text remains171172## Example Invocations173174**Generate initial threat model:**175```176Generate a threat model for this repository.177```178179**Update existing threat model:**180```181Update the threat model - we added a new payments service.182```183184**Generate with compliance requirements:**185```186Generate a threat model for this repository. We need to comply with SOC2 and GDPR.187```