Web Security
Beginner
1 min read
Threat Modeling: Identifying and Prioritising Risks
Example
# threat_model.py — lightweight STRIDE checklist generator
from dataclasses import dataclass, field
from typing import List
STRIDE = {
'S': 'Spoofing',
'T': 'Tampering',
'R': 'Repudiation',
'I': 'Information Disclosure',
'D': 'Denial of Service',
'E': 'Elevation of Privilege',
}
@dataclass
class DataFlow:
name: str
source: str
destination: str
crosses_trust_boundary: bool
threats: List[str] = field(default_factory=list) # STRIDE codes
def report(self) -> str:
lines = [f"Data Flow: {self.name} ({self.source} -> {self.destination})"]
if self.crosses_trust_boundary:
lines.append(" [!] Crosses trust boundary — all STRIDE categories apply")
for code in self.threats:
lines.append(f" Threat [{code}] {STRIDE[code]}")
return '\n'.join(lines)
flows = [
DataFlow('User Login', 'Browser', 'Auth Service', True, ['S', 'T', 'I']),
DataFlow('DB Query', 'App Server', 'Database', True, ['T', 'I', 'E']),
DataFlow('Password Reset','Email', 'Browser', False, ['S', 'R']),
]
for flow in flows:
print(flow.report())
print()
Related Resources
Web Security Reference
Complete tag & property list
Web Security How-To Guides
Step-by-step practical guides
Web Security Exercises
Practice what you've learned
More in Web Security