factory-ai/threat-model-generation
Generate a STRIDE-based security threat model for a repository. Use when setting up security monitoring, after architecture changes, or for security audits.
npx skills add https://github.com/Factory-AI/factory-plugins --skill threat-model-generation
Generate a comprehensive security threat model for a repository using the STRIDE methodology. This skill analyzes the codebase architecture and produces an LLM-optimized threat model document that other security skills can reference.
Before running this skill, gather or confirm:
| 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 |
| Security contacts | Email addresses for security team notifications | No |
Follow these steps in order:
Scan the codebase to understand the system:
package.json, requirements.txt, go.mod, Cargo.toml, etc.apps/, services/, packages/ directoriesDefine security zones:
Document where trust boundaries exist and what validates transitions between zones.
Classify data by sensitivity:
For each major component, analyze threats in all six categories:
For each identified threat:
Create a library of code patterns specific to this codebase's tech stack:
# Example: SQL Injection patterns for Python
# VULNERABLE
sql = f"SELECT * FROM users WHERE id = {user_id}"
# SAFE
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
Include patterns for:
Create two files:
.factory/threat-model.mdUse the template in stride-template.md to generate a comprehensive threat model with:
The document should be written in natural language with code examples, optimized for LLM comprehension.
.factory/security-config.jsonGenerate configuration metadata:
{
"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"
],
"custom_patterns_path": null
}
}
Customize based on:
The skill is complete when:
.factory/threat-model.md exists with all sections populated.factory/security-config.json exists with valid JSONRun these checks before completing:
# Verify threat model exists and is non-empty
test -s .factory/threat-model.md && echo "✓ Threat model exists"
# Verify config is valid JSON
cat .factory/security-config.json | jq . > /dev/null && echo "✓ Config is valid JSON"
# Check threat model has key sections
grep -q "## 1. System Overview" .factory/threat-model.md && echo "✓ Has System Overview"
grep -q "## 5. Threat Analysis" .factory/threat-model.md && echo "✓ Has Threat Analysis"
grep -q "## 6. Vulnerability Pattern Library" .factory/threat-model.md && echo "✓ Has Pattern Library"
Generate initial threat model:
Generate a threat model for this repository using the threat-model-generation skill.
Update existing threat model after architecture change:
Update the threat model - we added a new payments service in services/payments/.
Generate with compliance requirements:
Generate a threat model for this repository. We need to comply with SOC2 and GDPR.
stride-template.md (in this skill directory)Take factory-ai/threat-model-generation from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.