Catalog My learning Blog
Application Security for Developers: Secure Coding Course · Phase 1 · Lesson 1 · 4 min read

Threat Modeling and the CIA Triad Explained

On this page
  1. What is the security mindset?
  2. The CIA triad: confidentiality, integrity, availability
  3. Threat modeling in four questions
  4. Example: threat modeling a password reset feature
  5. Which threats first?
  6. Making threat modeling routine
  7. Check yourself

What is the security mindset?

Most developers test whether a feature works. Attackers test how it breaks: what happens with a negative quantity, a reused link, a million requests, someone else's ID. The security mindset is asking those questions yourself, early, when fixes are cheap.

The CIA triad: confidentiality, integrity, availability

Three properties describe what security protects:

PropertyMeansBroken by
ConfidentialityOnly the right people can read dataData leaks, stolen credentials, overly broad access
IntegrityData and systems aren't changed improperlyTampered requests, injection, unauthorized edits
AvailabilityThe system works when neededDDoS, resource exhaustion, ransomware

Every vulnerability in this course harms at least one of them. Two more properties often join them: authenticity (you know who did something) and non-repudiation (they can't deny it later), supported by authentication and audit logs.

Threat modeling in four questions

Threat modeling is structured thinking about what could go wrong. Adam Shostack's four questions are enough to start:

  1. What are we working on? Sketch the feature: components, data, who talks to whom, and trust boundaries (where data crosses from less trusted to more trusted, such as browser to server).
  2. What can go wrong? Brainstorm threats; the STRIDE checklist helps (Day 28).
  3. What are we going to do about it? For each threat, mitigate it (add a control), accept it (low risk, written down), transfer it (insurance, or a provider who handles it) or avoid it (drop the risky feature).
  4. Did we do a good job? Review, test, and revisit when the design changes.
Threat modeling asks what you're building, what can go wrong, what you'll do about it, and whether it worked, measured against confidentiality, integrity and availability.
Threat modeling asks what you're building, what can go wrong, what you'll do about it, and whether it worked, measured against confidentiality, integrity and availability.

Example: threat modeling a password reset feature

Twenty minutes of threat modeling, written down:

Code
Threat model notes: password reset

Asset: the reset token (single use, maps to exactly one account)
Trust boundary: email link -> browser -> our API

Threat: token is guessable              -> 256-bit random token from a CSPRNG (crypto.randomBytes(32))
Threat: token works forever             -> 15-minute expiry, single use, invalidated on login
Threat: token stolen from our database  -> store only a hash of the token
Threat: email enumeration via responses -> same response and timing whether or not the email exists
Threat: reset spam / email bombing      -> rate limit per email and per IP
Threat: token leaks via Referer header  -> Referrer-Policy: no-referrer on the reset page
Threat: attacker resets, victim unaware -> notify the account owner; end other sessions on reset

A CSPRNG is a cryptographically secure random number generator, such as crypto.randomBytes in Node or secrets in Python. Ordinary Math.random() is predictable enough that attackers can sometimes work out the next value.

Each line names a threat and a specific mitigation a developer can implement and test. Notice the threats span the triad: guessing and leaking tokens (confidentiality), taking over the account (integrity), email bombing (availability).

Which threats first?

A list of fifteen threats needs an order. Rate each one quickly on two scales, how likely and how bad, and start with the threats that score high on both:

ThreatLikely?ImpactPriority
Reset token works foreverMediumAccount takeoverHigh
Email enumerationHighHelps later attacksMedium
Reset spamMediumAnnoyed usersLow to medium

Rough is fine. The point is to spend the first hour on account takeover, not on the annoying-but-harmless threat.

Making threat modeling routine

  • Threat model new features and significant changes, not the whole system once a year.
  • Keep it lightweight: a whiteboard sketch and a list in the design doc beats a formal process nobody follows.
  • Focus on trust boundaries, where most vulnerabilities live: user input, third-party APIs, uploaded files, internal services that trust each other.
  • Turn mitigations into tests and tickets, so they don't stay as notes.

Check yourself

Availability. A DDoS floods the system with traffic so legitimate users can't reach it, even though no data is read or changed. Confidentiality and integrity are untouched, which is why availability needs its own controls like rate limiting and CDNs.

If the database leaks, attackers can't use the stored hashes to reset accounts, because they need the original token that was emailed to the user. It's the same reasoning as password hashing, and a fast hash like SHA-256 is fine here because tokens are long and random.

A point where data passes between parts with different trust levels, such as user input reaching a server; that's where validation and checks are needed and most vulnerabilities appear.

Rate each threat by likelihood and impact, and fix the ones high on both first; accept and document the low-risk ones.