Skip to content

Threat Modeling Guide

FieldValue
TypeSkill Resource
Source~/.copilot/skills/security/references/appsec/threat-modeling-guide.md
DescriptionNot specified

Source Content

Threat Modeling Guide

Systematic approaches for identifying, analyzing, and mitigating security threats.


Table of Contents


Threat Modeling Process

Workflow: Conduct Threat Model

  1. Define the scope and objectives:
    • System boundaries
    • Assets to protect
    • Trust levels
  2. Create data flow diagram:
    • External entities
    • Processes
    • Data stores
    • Data flows
    • Trust boundaries
  3. Identify threats using STRIDE:
    • Apply STRIDE to each DFD element
    • Document threat scenarios
  4. Analyze and prioritize risks:
    • Score using DREAD
    • Rank by severity
  5. Define mitigations:
    • Map controls to threats
    • Identify gaps
  6. Validate and iterate:
    • Review with team
    • Update as system evolves
  7. Document in threat model report
  8. Validation: All DFD elements analyzed; threats documented; mitigations mapped; residual risks accepted

Threat Model Template

THREAT MODEL REPORT
System: [System Name]
Version: [Version]
Date: [Date]
Author: [Name]
1. SYSTEM OVERVIEW
- Purpose: [Description]
- Users: [User types]
- Data: [Data classification]
2. SCOPE
- In Scope: [Components included]
- Out of Scope: [Components excluded]
- Assumptions: [Security assumptions]
3. DATA FLOW DIAGRAM
[DFD image or ASCII representation]
4. THREATS IDENTIFIED
| ID | Element | STRIDE | Threat | DREAD | Mitigation |
|----|---------|--------|--------|-------|------------|
5. RESIDUAL RISKS
[Accepted risks with justification]
6. RECOMMENDATIONS
[Prioritized security improvements]

STRIDE Framework

Categorization model for identifying threats.

STRIDE Categories

CategoryDescriptionViolated Property
SpoofingPretending to be someone/something elseAuthentication
TamperingModifying data or codeIntegrity
RepudiationDenying actions occurredNon-repudiation
Information DisclosureExposing data to unauthorized partiesConfidentiality
Denial of ServiceMaking system unavailableAvailability
Elevation of PrivilegeGaining unauthorized accessAuthorization

STRIDE per Element

DFD ElementApplicable Threats
External EntityS, R
ProcessS, T, R, I, D, E
Data StoreT, R, I, D
Data FlowT, I, D

STRIDE Analysis Template

STRIDE ANALYSIS
Element: User Authentication Service
Type: Process
┌─────────────────────────────────────────────────────────────────┐
│ SPOOFING │
├─────────────────────────────────────────────────────────────────┤
│ Threat: Attacker uses stolen credentials to impersonate user │
│ Attack Vector: Phishing, credential stuffing, session hijack │
│ Likelihood: High │
│ Impact: High - Full account access │
│ Mitigation: MFA, session binding, anomaly detection │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ TAMPERING │
├─────────────────────────────────────────────────────────────────┤
│ Threat: Attacker modifies authentication request in transit │
│ Attack Vector: Man-in-the-middle, request manipulation │
│ Likelihood: Medium │
│ Impact: High - Bypass authentication │
│ Mitigation: TLS 1.3, request signing, HSTS │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ REPUDIATION │
├─────────────────────────────────────────────────────────────────┤
│ Threat: User denies performing privileged action │
│ Attack Vector: Claim account was compromised │
│ Likelihood: Medium │
│ Impact: Medium - Dispute resolution difficulty │
│ Mitigation: Comprehensive audit logging, log integrity │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ INFORMATION DISCLOSURE │
├─────────────────────────────────────────────────────────────────┤
│ Threat: Password hashes exposed via SQL injection │
│ Attack Vector: SQLi, backup exposure, error messages │
│ Likelihood: Medium │
│ Impact: Critical - Mass credential compromise │
│ Mitigation: Parameterized queries, encryption, error handling │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ DENIAL OF SERVICE │
├─────────────────────────────────────────────────────────────────┤
│ Threat: Brute force attacks overwhelm authentication service │
│ Attack Vector: Credential stuffing, distributed attacks │
│ Likelihood: High │
│ Impact: High - Users cannot authenticate │
│ Mitigation: Rate limiting, CAPTCHA, account lockout │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ ELEVATION OF PRIVILEGE │
├─────────────────────────────────────────────────────────────────┤
│ Threat: Regular user gains admin privileges │
│ Attack Vector: JWT manipulation, IDOR, role confusion │
│ Likelihood: Medium │
│ Impact: Critical - Full system compromise │
│ Mitigation: Server-side authorization, signed tokens, RBAC │
└─────────────────────────────────────────────────────────────────┘

Threat Mitigation Matrix

STRIDE CategoryStandard Mitigations
SpoofingAuthentication (passwords, MFA, certificates)
TamperingIntegrity controls (signing, hashing, checksums)
RepudiationAudit logging, digital signatures, timestamps
Information DisclosureEncryption, access controls, data masking
Denial of ServiceRate limiting, redundancy, filtering
Elevation of PrivilegeAuthorization, least privilege, input validation

Attack Trees

Visual representation of attack paths to a specific goal.

Attack Tree Structure

ATTACK TREE: Compromise User Account
┌─────────────────────┐
│ GOAL: Access User │
│ Account │
└──────────┬──────────┘
┌───────────────────┼───────────────────┐
│ │ │
┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐
│ Obtain │ │ Bypass │ │ Exploit │
│ Credentials │ │ Auth │ │ Session │
│ [OR] │ │ [OR] │ │ [OR] │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
┌─────┼─────┐ ┌─────┼─────┐ ┌─────┼─────┐
│ │ │ │ │ │ │ │ │
┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐
│Phi│ │Crd│ │Key│ │SQL│ │JWT│ │Pwd│ │XSS│ │Fix│ │Sid│
│sh │ │Stf│ │Log│ │ i │ │Frg│ │Rst│ │ │ │tn │ │Hj │
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘
Legend:
- Phi: Phishing
- CrdStf: Credential Stuffing
- KeyLog: Keylogger
- SQLi: SQL Injection
- JWTFrg: JWT Forgery
- PwdRst: Password Reset Flaw
- XSS: Cross-Site Scripting
- Fixtn: Session Fixation
- SidHj: Session Hijacking

Attack Tree Analysis

Attack PathDifficultyDetectionPriority
Phishing → Credential theftLowMediumHigh
SQL Injection → Auth bypassMediumHighCritical
XSS → Session stealMediumMediumHigh
JWT forgery → Privilege escalationHighLowCritical

Calculating Attack Probability

def calculate_attack_probability(attack_tree_node):
"""
Calculate cumulative probability of attack success.
For OR nodes: P = 1 - (1-P1)(1-P2)...(1-Pn)
For AND nodes: P = P1 * P2 * ... * Pn
"""
if node.is_leaf:
return node.probability
child_probs = [calculate_attack_probability(c) for c in node.children]
if node.operator == 'OR':
# At least one path succeeds
prob_all_fail = 1
for p in child_probs:
prob_all_fail *= (1 - p)
return 1 - prob_all_fail
elif node.operator == 'AND':
# All paths must succeed
prob_all_succeed = 1
for p in child_probs:
prob_all_succeed *= p
return prob_all_succeed

DREAD Risk Scoring

Quantitative risk assessment for prioritizing threats.

DREAD Components

FactorDescriptionScale
DamageHow bad is the impact?1-10
ReproducibilityHow easy to reproduce?1-10
ExploitabilityHow easy to exploit?1-10
Affected UsersHow many users impacted?1-10
DiscoverabilityHow easy to find?1-10

DREAD Scoring Guide

Damage Potential:

ScoreDescription
10Complete system compromise, data destruction
7-9Large data breach, significant financial loss
4-6Partial data exposure, service degradation
1-3Minor information disclosure, low impact

Reproducibility:

ScoreDescription
10Always reproducible, automated
7-9Reproducible most of the time
4-6Reproducible with some effort
1-3Difficult to reproduce, timing dependent

Exploitability:

ScoreDescription
10No skills required, exploit exists
7-9Basic skills, tools available
4-6Moderate skills required
1-3Advanced skills, custom exploit needed

Affected Users:

ScoreDescription
10All users
7-9Large subset of users
4-6Some users
1-3Few or individual users

Discoverability:

ScoreDescription
10Publicly documented, obvious
7-9Easy to find via scanning
4-6Requires investigation
1-3Obscure, requires insider knowledge

DREAD Calculation

def calculate_dread_score(damage, reproducibility, exploitability,
affected_users, discoverability):
"""
Calculate DREAD risk score.
Returns: Float between 1-10
Risk Levels:
8-10: Critical
6-7.9: High
4-5.9: Medium
1-3.9: Low
"""
score = (damage + reproducibility + exploitability +
affected_users + discoverability) / 5
return round(score, 1)
def get_risk_level(dread_score):
if dread_score >= 8:
return 'Critical'
elif dread_score >= 6:
return 'High'
elif dread_score >= 4:
return 'Medium'
else:
return 'Low'

DREAD Assessment Example

THREAT: SQL Injection in Login Form
| Factor | Score | Justification |
|--------|-------|---------------|
| Damage | 9 | Full database access, credential theft |
| Reproducibility | 9 | Consistent, automated tools exist |
| Exploitability | 8 | Well-documented attack, easy tools |
| Affected Users | 10 | All users with accounts |
| Discoverability | 7 | Scanners detect easily |
DREAD Score: (9+9+8+10+7)/5 = 8.6
Risk Level: CRITICAL
Priority: Immediate remediation required

Data Flow Diagrams

Visual representation of system data movement for security analysis.

DFD Elements

SymbolElementSecurity Considerations
RectangleExternal EntityTrust boundary crossing
Circle/OvalProcessAll STRIDE threats apply
Parallel LinesData StoreTampering, disclosure, DoS
ArrowData FlowTampering, disclosure, DoS
Dashed LineTrust BoundaryAuthentication required

DFD Levels

LevelDescriptionUse Case
Level 0 (Context)Single process, external entitiesExecutive overview
Level 1Major processes expandedArchitecture review
Level 2Detailed subprocessesDetailed threat modeling

Example: E-Commerce DFD

LEVEL 0: CONTEXT DIAGRAM
┌──────────────────┐
│ │
┌────────────┐ │ E-Commerce │ ┌────────────┐
│ │ Orders │ System │ Payment │ │
│ Customer │──────────▶│ │──────────▶│ Payment │
│ │◀──────────│ │◀──────────│ Gateway │
└────────────┘ Status │ │ Result └────────────┘
│ │
└──────────────────┘
│ Fulfillment
┌────────────────┐
│ Warehouse │
│ System │
└────────────────┘
LEVEL 1: EXPANDED VIEW
┌─────────────────────────────────────────────────────────────────────┐
│ TRUST BOUNDARY │
│ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ │ │ Web │ │ Order │ │ Payment │ │
│ │ CDN │──────▶│ Server │──────▶│ Service │──────▶│ Service │ │
│ │ │ │ │ │ │ │ │ │
│ └─────────┘ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ╔═══════════╗ ╔═══════════╗ ╔═══════════╗ │
│ ║ Session ║ ║ Orders ║ ║ Payment ║ │
│ ║ Store ║ ║ DB ║ ║ DB ║ │
│ ╚═══════════╝ ╚═══════════╝ ╚═══════════╝ │
│ │
└─────────────────────────────────────────────────────────────────────┘
│ Crosses Trust Boundary
┌───────────┐
│ Payment │
│ Gateway │
│ (External)│
└───────────┘

Trust Boundary Analysis

Boundary CrossingAuthenticationAuthorizationEncryption
Customer → Web ServerSession cookie-TLS 1.3
Web Server → Order ServicemTLSService accountInternal TLS
Order Service → DBConnection poolDB user rolesTLS
Payment Service → GatewayAPI key + HMACIP whitelistTLS 1.3

Common Attack Patterns

OWASP Top 10 Mapping

RankVulnerabilitySTRIDECommon Attack
A01Broken Access ControlEIDOR, privilege escalation
A02Cryptographic FailuresIWeak encryption, exposed keys
A03InjectionT, ESQLi, XSS, command injection
A04Insecure DesignAllLogic flaws, missing controls
A05Security MisconfigurationI, EDefault creds, verbose errors
A06Vulnerable ComponentsAllOutdated libraries, CVEs
A07Authentication FailuresS, ECredential stuffing, weak passwords
A08Software/Data IntegrityTUnsigned updates, CI/CD attacks
A09Logging FailuresRMissing logs, log injection
A10SSRFI, TInternal service access

Attack Pattern Catalog

ATTACK PATTERN: SQL Injection (A03)
Threat: T (Tampering), E (Elevation of Privilege)
Attack Vector:
1. Identify input fields that construct SQL queries
2. Test for injection: ' OR '1'='1' --
3. Extract data: UNION SELECT password FROM users
4. Escalate: Execute stored procedures, write files
Detection:
- WAF rules for SQL patterns
- Prepared statement verification
- Database query logging
Mitigation:
- Parameterized queries (primary)
- Input validation (secondary)
- Least privilege database accounts
- Web application firewall
Test Cases:
- Single quote injection: '
- Boolean-based: ' OR 1=1 --
- Time-based: '; WAITFOR DELAY '0:0:5' --
- UNION-based: ' UNION SELECT NULL, username, password FROM users --

Threat Intelligence Integration

SourcePurposeUpdate Frequency
CVE/NVDKnown vulnerabilitiesDaily
MITRE ATT&CKAttack techniquesQuarterly
OWASPWeb application threatsAnnual
Industry ISACsSector-specific threatsReal-time