Threat Modeling Skill v3.3.0 (20261130b)
AI-native automated software risk analysis skill. LLM-driven, Code-First approach for comprehensive security risk assessment, threat modeling, security testing, penetration testing, and compliance checking.
Paths: commands below use ${CLAUDE_SKILL_DIR} (expanded at load time by Claude Code). On Codex, Antigravity CLI (agy), in referenced files, and after compaction, resolve ${CLAUDE_SKILL_DIR} to the directory containing this loaded SKILL.md; "Bash" means the host shell. Only the skill-loading read of SKILL.md precedes S-Init; read this file and each reference (WORKFLOW.md, phases/P1..P8R.md, assets/contracts/data-model.yaml) to its end (agy caps single reads at 46,080 bytes; phases/P2-DFD-ANALYSIS.md and assets/contracts/data-model.yaml exceed that limit).
After a compaction: Read Risk_Assessment_Report/.phase_working/{SESSION_ID}/task_queue.yaml, _session.yaml, and Risk_Assessment_Report/.phase_working/_session_meta.yaml first, re-read this SKILL.md in full so paths, gates, and mirror rules stay in context, reconcile the host task list if mirrored, and resume from the saved TESM + workflow phase (S1..S4, P1..P8).
Version Banner
━━━ 🛡️ Threat Modeling Skill v3.3.0 (20261130b) ━━━
Command Line Flags
| Flag | Description | Default |
|---|---|---|
--debug | Publish internal YAML data files, KB queries, coverage validation, and evaluation report | OFF |
--lang=xx | Set output language (en, zh, ja, ko, es, fr, de, pt, ru) | Auto-detect |
--detailed | Auto-trigger P8R (detailed per-VR analysis reports) after P8 completes | OFF |
Usage: /threat-model @my-project [--debug] [--lang=zh] [--detailed]
S-Init
- S-Init a (Session + Queue): Run
python3 "${CLAUDE_SKILL_DIR}/scripts/phase_data.py" --init --project <PROJECT> --path . [--detailed] --root .(createsRisk_Assessment_Report/.phase_working/{SESSION_ID}/and auto-seedstask_queue.yamlwithT-01..T-08, orT-01..T-09with--detailed). - S-Init b (Verify State): Run
python3 "${CLAUDE_SKILL_DIR}/scripts/task_state.py" --state "Risk_Assessment_Report/.phase_working/{SESSION_ID}/task_queue.yaml" --summaryto confirm active queue and DAG dependencies. - S-Init c (Conditional Host Mirror): Follow Task Surface Sync below only if your current tool definitions include a complete host task-list interface.
Task Surface Sync (TESM ↔ Host Task UI)
task_state.py YAML is the single source of truth; a host task list is a view of it, kept only where the host offers one (WORKFLOW.md "Host task list"; read it before mirroring).
- Capability: mirror only when the tool definitions in your current context include a task-list interface with every tool its procedure needs (
TaskCreate+TaskUpdate+TaskList; orTodoWrite; or Codex'supdate_plan; or agy'supdate_steps;manage_taskandTaskStopare not task lists). A tool the host lists by name as deferred, with its schema not yet loaded, counts as offered: load its schema with the host's tool-search call (Claude Code:ToolSearchwithselect:TaskCreate,TaskUpdate,TaskList) before its first call, and never call it unloaded. Loading a schema is not a probe. Never call an absent tool to find out. A call answered "no such tool", "disabled" or a permission refusal ends the mirror: do not retry it for later tasks or through a subagent. After a resume or a compaction, look at the tool definitions again. - Ownership: a
TaskCreatecarries the subjectT-NN [<session-id>] <description>,TESM: <abs task_queue.yaml>on line 1 of description and anactiveForm(e.g.S3 executing: Analyzing P2 data flows); change or delete only an entry you can show is this session's (subject and TESM path); leave any other alone. - When: once a transition is saved (exit 0, or
phase_statesaved), mirror it (start →in_progress, complete →completedorupdate_steps'sdone; also after S-Init c,--set-phase, pause, block, unblock and skip). Update-before-dispatch: when mirroring, mark the ACTIVE taskin_progressbefore long-running work (a subagent, a Skill, Bash > 5s). Reconcile (with the Task tools: a loneTaskListcall first, then create what is missing but never a SKIPPED task, and correct each status) after S-Init c, after a resume or compaction, and before the final report. - No usable tool: TESM alone is the record; at the final summary say once, with the reason, that the host task list was not kept in step (if it stopped midway: earlier entries may be stale).
- Single writer: only the Lead runs
task_state.py/phase_data.pyand the mirror; parallel sub-agents (e.g. P2 traversal workers, P4 reviewers) return results to the Lead, which records them. Each command that writes locks its state file, so concurrent writes are serialized instead of lost; read-only queries (--summary,--next,--query,--verify) take no write lock. The order of transitions is still the Lead's to decide.
⚠️ CRITICAL: Data vs Report Separation
PRINCIPLE: Markdown is for reports (human-readable), YAML is for data (machine-readable). Writing reports AFTER YAML is MANDATORY!
| Output Layer | Format & Order | Purpose | Path |
|---|---|---|---|
| 1. DATA (PRIMARY) | .yaml written FIRST | Structured machine-readable phase input (FORBIDDEN: scraping .md prose/tables as YAML; fenced ```yaml:{block} extraction via --phase-end supported) | Risk_Assessment_Report/.phase_working/{SESSION_ID}/data/P{N}_*.yaml |
| 2. REPORT (SECONDARY) | .md written AFTER .yaml | Human-readable review & deliverables (illustrative YAML or fenced ```yaml:{block} blocks only) | Risk_Assessment_Report/.phase_working/{SESSION_ID}/reports/P{N}-*.md |
§1 Execution Model
Mode: Full Assessment Only — P1→P8 executed sequentially, synchronized with TESM step FSM (S1-THINKING → S2-PLANNING → S3-EXECUTING → S4-REFLECTING) per phase.
Phase Gate Protocol:
textFOR N in [1..8] (and P8R if --detailed): 1. Task start: task_state.py --start --id T-0N --state .../task_queue.yaml (+ --set-phase S1-THINKING -> S2-PLANNING -> S3-EXECUTING) 2. Read: ${CLAUDE_SKILL_DIR}/phases/P{N}-*.md (read to end!) + previous YAML data/P{N-1}_*.yaml 3. Write PRIMARY: Risk_Assessment_Report/.phase_working/{SESSION_ID}/data/P{N}_*.yaml 4. Write SECONDARY: Risk_Assessment_Report/.phase_working/{SESSION_ID}/reports/P{N}-*.md 5. Gate: python3 ${CLAUDE_SKILL_DIR}/scripts/phase_data.py --phase-end --phase N --session-id {SESSION_ID} --root . 6. IF exit != 0: keep phase cursor fixed, resolve blocking issues, re-run --phase-end (use task_state.py --reopen --phase N when replaying changed DONE phases; phase_data.py --p8r-open for late P8R) 7. IF exit == 0: task_state.py --set-phase S4-REFLECTING -> --complete --id T-0N (mirror if enabled), advance to N+1
§2 Output Convention
Output Modes
| Mode | Published Deliverables | Internal Data (Risk_Assessment_Report/.phase_working/) |
|---|---|---|
| Default | 4 required reports (RISK-ASSESSMENT, RISK-INVENTORY, MITIGATION-MEASURES, PENETRATION-TEST-PLAN) + 7 phase reports (P1..P7-*.md) | Kept internal (_session.yaml, task_queue.yaml, data/*.yaml, reports/*.md) |
--debug | All 8 reports (+ ARCHITECTURE-ANALYSIS, DFD-DIAGRAM, COMPLIANCE-REPORT, ATTACK-PATH-VALIDATION) + 7 phase reports + EVALUATION-REPORT.md | Published with data/*.yaml, P5_knowledge_base_queries.yaml, P8_coverage_validation.yaml |
Directory Structure
text{PROJECT_ROOT}/Risk_Assessment_Report/ ├── {PROJECT}-RISK-ASSESSMENT-REPORT.md ← Required (P8); DEBUG adds ARCHITECTURE-ANALYSIS, DFD-DIAGRAM, ├── {PROJECT}-RISK-INVENTORY.md ← Required (P6) COMPLIANCE-REPORT, ATTACK-PATH-VALIDATION ├── {PROJECT}-MITIGATION-MEASURES.md ← Required (P7) ├── {PROJECT}-PENETRATION-TEST-PLAN.md ← Required (P6) ├── P1-PROJECT-UNDERSTANDING.md .. P7-MITIGATION-PLAN.md ← Published phase reports ├── [--detailed] detailed/VR-001-{slug}.md ← Per-VR detailed reports (P8R) ├── [--debug] EVALUATION-REPORT.md ← Internal evaluation summary ├── html/{index.html, *.html, detailed/} ← HTML batch output (report_generator.py) └── .phase_working/ ← Internal state (published only with --debug) ├── _session_meta.yaml ← Global active/completed session index └── {SESSION_ID}/ ├── {_session.yaml, task_queue.yaml} ├── data/P{1..8,P8R}_*.yaml ← PRIMARY machine-readable phase artifacts (+ P5/P8 aux YAMLs) └── reports/P{1..8}-*.md ← Working phase reports before final publish
Naming Convention
- PROJECT: Uppercase, max 30 chars, format:
^[A-Z][A-Z0-9-]{0,29}$ - Example:
OPEN-WEBUI,MY-PROJECT,STRIDE-DEMO
Session ID Format
- SESSION_ID:
{PROJECT_NAME}_{YYYYMMDD_HHMMSS} - Example:
OPEN-WEBUI_20260130_143022
Session Metadata
yaml# File: Risk_Assessment_Report/.phase_working/{SESSION_ID}/_session.yaml # Global index: Risk_Assessment_Report/.phase_working/_session_meta.yaml schema_version: "3.3.0" session_id: "OPEN-WEBUI_20260130_143022" project_name: "OPEN-WEBUI" project_path: "/path/to/project" skill_version: "3.3.0 (20261130b)" current_phase: 1 phases_completed: []
§3 Core Data Model
See @assets/contracts/data-model.yaml for complete schema definitions.
Entity Types
| Entity | ID Format | Phase | Description |
|---|---|---|---|
| Module | M-{Seq:03d} | P1 | Code modules/components |
| Finding | F-P{N}-{Seq:03d} | P1-P3 | Security observations (factual) |
| Gap | GAP-{Seq:03d} | P4 | Security control deficiencies |
| Threat | T-{STRIDE}-{Element}-{Seq} | P5 | STRIDE threats |
| ValidatedRisk | VR-{Seq:03d} | P6 | Verified risks |
| Mitigation | MIT-{Seq:03d} | P7 | Remediation measures |
| POC | POC-{Seq:03d} | P6 | Proof of concept |
| AttackPath | AP-{Seq:03d} | P6 | Attack vectors (single path) |
| AttackChain | AC-{Seq:03d} | P6 | Multi-step attack sequences |
| TestCase | TC-{Seq:03d} | P8 | Penetration test cases |
| DetailedRiskRpt | (uses VR-{Seq:03d}) | P8R | Per-VR analysis report |
Finding vs Gap Semantic Boundary
-
Finding (F-P{N}-xxx): A factual observation from phases 1-3 that MAY have security implications. Findings are objective facts about architecture, data flows, or boundaries. Example: "API endpoint uses HTTP instead of HTTPS"
-
Gap (GAP-xxx): A security control deficiency identified in P4 after analyzing findings against security domains. Gaps represent missing or inadequate controls. Example: "Missing TLS enforcement (NETWORK domain)"
Transition Rule: Findings from P1-P3 feed into P4 analysis. P4 evaluates findings against 16 security domains and produces Gaps where controls are deficient.
DFD Element IDs
| Element Type | Prefix | Format | Example |
|---|---|---|---|
| External Interactor | EI | EI-{NNN} | EI-001 |
| Process | P | P-{NNN} | P-001 |
| Data Store | DS | DS-{NNN} | DS-001 |
| Data Flow | DF | DF-{NNN} | DF-001 |
| Trust Boundary | TB | TB-{NNN} | TB-001 |
Count Conservation (P5→P6 Threat Accounting)
P5.threat_count = P6.verified + P6.theoretical + P6.pending + P6.excluded
All threats from P5 must be accounted for in P6 (no threat loss).
Semantic Distinction:
- Count Conservation: P5→P6 threat accounting (threats flow from P5 to P6 dispositions)
- Element Coverage Verification: P2→P5 element coverage (every DFD element has STRIDE analysis)
§4 Security Knowledge Architecture
See @knowledge/ for complete reference materials (~11 MB, 113 files).
- Security Control Set (What to do): 16 Security Domains (
AUTHN,AUTHZ,INPUT, ...), Control Sets (18 files, 107 controls), OWASP (74 items), Compliance (14 frameworks). - Threat Pattern Set (What to know): CWE (974), CAPEC (615), ATT&CK (835), CVE/KEV (323K+).
- Verification Set (How to test): WSTG (109), MASTG (92), ASVS (345).
- 11 Security Principles:
DID(Defense in Depth),LP(Least Privilege),ZT(Zero Trust),FS(Fail Secure),SOD(Separation of Duties),SBD(Secure by Default),CM(Complete Mediation),EOM(Economy of Mechanism),OD(Open Design),IV(Input Validation),LA(Least Agency — limit AI agent autonomy).
STRIDE Categories
| STRIDE | Name | CWEs | CAPEC |
|---|---|---|---|
| S | Spoofing | CWE-287, 290, 307 | CAPEC-151, 194, 600 |
| T | Tampering | CWE-20, 77, 78, 89 | CAPEC-66, 88, 248 |
| R | Repudiation | CWE-117, 223, 778 | CAPEC-93 |
| I | Information Disclosure | CWE-200, 209, 311 | CAPEC-116, 157 |
| D | Denial of Service | CWE-400, 770, 918 | CAPEC-125, 227 |
| E | Elevation of Privilege | CWE-269, 284, 862 | CAPEC-122, 233 |
§5 Knowledge Base Queries
bashKB="${CLAUDE_SKILL_DIR}/kb" # unified_kb_query.py accepts --kb-path PATH to override DB location "$KB" --stride spoofing && "$KB" --stride-controls S && "$KB" --cwe CWE-89 "$KB" --full-chain CWE-89 && "$KB" --capec CAPEC-89 && "$KB" --attack-technique T1078 "$KB" --stride-tests S && "$KB" --wstg-category ATHN "$KB" --all-llm && "$KB" --ai-component llm_inference_service
§6 Language Adaptation
Output language follows context language unless --lang=xx specified.
| Context | File Names | Content |
|---|---|---|
| Chinese | P1-项目理解.md | 中文 |
| English | P1-PROJECT-UNDERSTANDING.md | English |
Supported: en, zh, ja, ko, es, fr, de, pt, ru
§7 Progressive Context Loading
- Always Loaded:
SKILL.md+WORKFLOW.md(orchestration & Host task list) at session start (S-Init a/b/c). - Per Phase: Load
${CLAUDE_SKILL_DIR}/phases/P{N}-*.mdon entry; writedata/P{N}_*.yamlthenreports/P{N}-*.md; gate via--phase-end. - Post-P8 (Optional): With
--detailedor confirmation, load${CLAUDE_SKILL_DIR}/phases/P8R-DETAILED-REPORT.md.
§8 Reference Files
| Path | Purpose |
|---|---|
| @WORKFLOW.md | Orchestration contracts, phase gates, Host task list |
| @phases/P{1-8}-*.md | Phase-specific instructions |
| @assets/contracts/data-model.yaml | Entity schemas |
| @knowledge/security-design.yaml | 16 security domains |
| @knowledge/security-principles.yaml | 11 security principles |
| @knowledge/sast-rules.yaml | SAST tool configs and STRIDE mappings |
| @scripts/task_state.py | TESM step FSM (S1..S4) & locked task_queue.yaml manager |
| @scripts/module_discovery.py | P1 three-layer module discovery |
| @scripts/phase_data.py | Phase validation, session management, coverage checks |
| @scripts/unified_kb_query.py | Knowledge base queries |
| @scripts/report_generator.py | MD→HTML batch converter |
| @phases/P8R-DETAILED-REPORT.md | Optional per-VR detailed reports |
| @docs/TASK-SURFACE-MIRROR-AND-ARCH-DESIGN.md | v3.3.0 architecture & tri-host task mirror design |
| @skill_path.sh | POSIX skill directory resolution helper |
§9 Quick Start
Invoke /threat-model @my-project (--detailed for P8R per-VR reports, --debug for YAML + coverage artifacts, --lang=zh for Chinese). Run S-Init a/b/c, load WORKFLOW.md, then execute P1..P8 sequentially into Risk_Assessment_Report/.
§10 Core Execution Constraints (Invariants)
PRINCIPLE: The quality of threat modeling depends on execution rigor. The following constraints are INVIOLABLE.
Three Absolute Prohibitions
| Constraint | Description | Violation Consequence |
|---|---|---|
| ❌ NO MOCK DATA | All analysis must be based on real code evidence | Analysis results invalid |
| ❌ NO SIMPLIFIED IMPLEMENTATIONS | Each phase must be fully executed | Coverage requirements not met |
| ❌ NO BYPASSING PROBLEMS | Must diagnose root cause when blocked | Data chain broken |
Phase Execution Invariant
∀ Phase N ∈ [1..8]: - Input: P{N-1}_*.yaml (except P1) - Output: P{N}_*.yaml (PRIMARY) + P{N}-*.md (SECONDARY) - Gate: phase_data.py --phase-end must return exit 0 - Transition: Only proceed to N+1 after gate passes
Execution Protocol Details: See WORKFLOW.md §2 Phase Execution Protocol
§11 Phase Isolation Constraints
INVARIANT: Each Phase is an independent execution unit. FSM state transitions MUST follow strict sequential order.
Forbidden State Transitions
| Illegal Transition | Reason |
|---|---|
| Pn → Pn+2 (skip) | Violates FSM order invariant (S1) |
| Pn → Pn+1 (unvalidated) | Violates data contract completeness (S2) |
| Parallel Phase execution | Data dependencies cannot be satisfied |
Complete FSM Specification: See WORKFLOW.md §1 Formal Properties: See docs/SKILL-ARCHITECTURE-DESIGN.md §0.2
End of SKILL.md (~540 lines, ~5.5K tokens)


