Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 38 ยท Getting Started

Threat Modeling and Security Thinking

Learn the security mindset: the CIA triad, assets, attackers, attack surface and STRIDE, then build a small STRIDE checklist for a web application in your browser.

Before fixing individual bugs you need a way of thinking about what can go wrong. Security people call it the attacker mindset: instead of asking "does this feature work?", you ask "how could someone misuse this feature?" Threat modeling turns that question into a repeatable habit that fits in a short meeting.

This lesson introduces the vocabulary used in the rest of the track: assets, threats, vulnerabilities, controls, trust boundaries, and the STRIDE method for finding threats.

The CIA triad

Most security goals fall into three groups:

  • Confidentiality: only the right people can read the data (customer emails, API keys).
  • Integrity: data and code cannot be changed without permission (an order total, a software update).
  • Availability: the system works when people need it (a login page that survives a traffic spike).

Each Top 10 category harms at least one of these. Broken access control and cryptographic failures mostly attack confidentiality, injection and integrity failures attack integrity, and many misconfigurations attack availability.

Key words

Term Meaning Example
Asset Something worth protecting Customer database, admin session
Threat actor Who might attack Curious user, criminal, insider
Threat What could go wrong Someone reads another user's orders
Vulnerability A weakness that allows a threat Order endpoint skips the owner check
Exploit The way the weakness is used Changing the id in the URL
Control Something that reduces risk Authorization check, logging
Attack surface Everything reachable by an attacker Every route, parameter, file upload, dependency

A shrinking attack surface is the cheapest security win: a feature you do not ship cannot be attacked.

Trust boundaries

A trust boundary is a line where data moves between areas with different levels of trust. The browser is outside your control: everything it sends (forms, headers, cookies, even "hidden" fields) can be changed by the user. Data coming from a third-party API, a message queue or a file upload also crosses a boundary.

flowchart LR
  U["Browser (untrusted)"] -->|"HTTPS request"| W["Web server"]
  W --> A["Application code"]
  A --> D[("Database")]
  A -->|"HTTP call"| X["Third-party API (partly trusted)"]
  classDef untrusted fill:#fee2e2,stroke:#b91c1c;
  class U untrusted;

The rule of thumb: validate and authorize at every boundary, and never trust anything that crossed one.

STRIDE: a checklist of threats

STRIDE, created at Microsoft, gives six threat types. Each one violates a security property:

Letter Threat Violated property Typical control
S Spoofing identity Authentication Strong login, MFA
T Tampering Integrity Validation, signatures
R Repudiation Non-repudiation Audit logs
I Information disclosure Confidentiality Encryption, access control
D Denial of service Availability Rate limits, quotas
E Elevation of privilege Authorization Least privilege, role checks

To threat-model a feature, draw its data flow (boxes for components, arrows for data, dashed lines for trust boundaries) and ask the six STRIDE questions for every arrow and box. Write down the answers; the unanswered ones are your to-do list.

Python A STRIDE checklist generator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real tools (such as Microsoft's Threat Modeling Tool or OWASP Threat Dragon) do the same thing with diagrams. The value is in the conversation, not the software.

From threats to controls

Once you list threats, decide what to do with each one:

  1. Mitigate: add a control (the usual choice).
  2. Eliminate: remove the feature or the data.
  3. Transfer: move the risk (for example, use a payment provider so you never store card numbers).
  4. Accept: knowingly leave it, with a written owner and reason.
Python Mapping threats to Top 10 categories

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that one STRIDE letter can map to different Top 10 categories and vice versa. The two lists are two views of the same problems: STRIDE helps you find issues during design, while the Top 10 helps you recognise them in code and tests.

Security principles to keep in mind

  • Least privilege: grant only the rights needed for the task.
  • Defense in depth: layer controls so one failure is not fatal.
  • Fail securely: on error, deny access rather than allow it.
  • Secure by default: the safe option is the one you get without configuring anything.
  • Keep it simple: complex code hides bugs; fewer features mean fewer holes.
  • Never rely on obscurity: a secret URL is not an access control (see forced browsing).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A user can edit a hidden form field before submitting. What does that show?

    The client is outside your control. Validate and authorize again on the server for every request.
  2. 2. In STRIDE, which letter covers a user gaining admin rights they should not have?

    E is Elevation of privilege. S is spoofing, R is repudiation and D is denial of service.
  3. 3. Which choice is an example of transferring risk?

    Transferring moves the risk to another party. Mitigating adds a control, eliminating removes the feature, and accepting means leaving it knowingly.
  4. 4. Which principle says an error should deny access instead of granting it?

    Fail securely (fail closed): when something unexpected happens, the safe outcome is to refuse.

Summary

  • Security thinking asks how a feature could be misused; threat modeling makes that a routine.
  • The CIA triad (confidentiality, integrity, availability) names what you protect.
  • Trust boundaries mark where data stops being trustworthy; check data at every boundary.
  • STRIDE gives six questions per data flow: spoofing, tampering, repudiation, information disclosure, denial of service, elevation of privilege.
  • Threats are mitigated, eliminated, transferred or knowingly accepted.
  • Apply least privilege, defense in depth, secure defaults and fail-closed behavior everywhere.

Next: HTTP, Sessions and Where Web Apps Break