CMPUT-331 · Lesson 1 of 12 · 36 min

Security principles and threat modeling

Computer security is the discipline of keeping systems doing what their owners intend while someone else is trying to make them do something else. That second clause is what separates security from ordinary reliability engineering. A bridge engineer designs for wind, load and corrosion, which follow physical laws and do not adapt. A security engineer designs for an adversary who reads the design, probes for the weakest point and changes tactics when one door closes. This course takes the computer scientist's view: how the mechanisms that protect systems actually work, why they fail, and how to reason about them precisely. Every lesson includes small programs that run for real, so you can see a hash collide, a cipher leak a pattern or an injection succeed and then be fixed.

The course builds on earlier ones. CMPUT-313 explained how networks carry data; CMPUT-201 showed how C manages memory and where buffer overflows come from; CMPUT-291 covered SQL injection and database permissions; CMPUT-272 introduced modular arithmetic and a toy RSA; and CMPUT-301 placed security inside the software development life cycle. The CISSP track (CISSP-110 to CISSP-117) covers the same ground from a manager's point of view: governance, risk programs, audits and certification. Here we stay close to the code and the mathematics. Throughout the course every vulnerability is shown in a tiny, self-contained toy program running on this machine, next to its fix. Nothing here is a tool for attacking real systems, and the final lesson discusses the law and ethics that apply to security work.

Confidentiality, integrity and availability

The classic goals of security are confidentiality, integrity and availability, known as the CIA triad. Confidentiality means information is disclosed only to those authorized to see it: your marks, your medical file, a company's source code. Integrity means information and systems are changed only in authorized ways, and that unauthorized changes are detected: a bank balance, a firmware image, a grade. Availability means authorized users can use the system when they need it: a hospital records system during an emergency, a course registration site in the first week of term. The three pull against each other. Encrypting a disk improves confidentiality but threatens availability if the key is lost; adding replicas improves availability but creates more copies to protect.

Several further properties are often added. Authenticity means we can verify who or what originated a message. Accountability means actions can be traced to the party responsible, which needs logging and reliable identification; its legal cousin is non-repudiation, where a party cannot credibly deny having performed an action. Privacy, which Lesson 11 treats in depth, concerns individuals' control over information about themselves and is broader than confidentiality: a system can keep data perfectly confidential from outsiders and still violate privacy by using it for purposes the person never agreed to.

Assets, threats, vulnerabilities and risk

Security reasoning starts with a vocabulary. An asset is anything of value: data, computing capacity, reputation, the safety of people. A threat is a potential cause of harm, often a threat actor with a motive and capability: a curious student, a criminal group selling stolen data, an insider with a grudge, a state agency. A vulnerability is a weakness that a threat could use: a missing access check, an unpatched library, a password stored in plain text. An exploit is a specific technique that uses a vulnerability. A control, or countermeasure, reduces risk by preventing, detecting or limiting harm. Risk combines how likely a harmful event is with how bad it would be.

Threat actors differ enormously in skill, resources and persistence, and a design should state which ones it defends against. Protecting a student club's website from automated scanning bots is a different problem from protecting a power grid from a well-funded foreign intelligence service. The threat model is the explicit statement of what we are defending, against whom, and under what assumptions. A good threat model also says what is out of scope: for example, that the cloud provider's hypervisor is trusted, or that physical theft of servers is handled by the data center rather than by the application.

Saltzer and Schroeder's design principles

In 1975 Jerome Saltzer and Michael Schroeder published a set of design principles for protecting information in computer systems. Half a century later they remain the best short guide to building secure systems, and later lessons keep returning to them. Economy of mechanism says keep the design small and simple, because complex mechanisms hide flaws and are hard to review. Fail-safe defaults says base access decisions on permission rather than exclusion: if the code is unsure, deny. Complete mediation says check every access to every object, every time, rather than trusting an earlier check. Open design says the security of a mechanism should not depend on its design being secret; this is the computing form of Kerckhoffs' principle, which Lesson 2 discusses.

Separation of privilege says require more than one condition to grant access when the stakes are high, such as two keys or two people. Least privilege says every program and user should operate with the smallest set of privileges needed for the task, so that an accident or a compromise does limited damage. Least common mechanism says minimize mechanisms shared between users, because every shared mechanism is a potential channel between them. Psychological acceptability says the protection must be easy enough to use that people use it correctly; a mechanism that users routinely bypass provides no protection. Two later additions are widely used: defense in depth, which layers independent controls so that one failure is not fatal, and secure by default, which ships the safe configuration rather than leaving it as an option.

An attack tree. The root goal, read another student's grades, is an OR node with four children: steal a session, an AND node needing an XSS flaw and a lure; guess a weak password; abuse the API, an AND node needing endpoint discovery and changing the id in the URL; and bribe a teaching assistant. The API path is highlighted as the cheapest, at 50 dollars.
An attack tree for the grade-viewing goal; the highlighted path is cheapest because the API performs no access check

Threat modeling with STRIDE

Threat modeling is a structured way of asking, before and during development, what could go wrong. Adam Shostack summarizes it as four questions: what are we working on, what can go wrong, what are we going to do about it, and did we do a good job? The first question is usually answered with a data flow diagram that shows external entities (users, other systems), processes (the code), data stores (databases, files) and data flows between them, with trust boundaries drawn wherever data crosses from a less trusted to a more trusted zone. The internet-facing edge of a web application is a trust boundary; so is the line between the application server and the database, and the line between the kernel and a user process.

For the second question, Microsoft's STRIDE mnemonic gives six categories, each the negation of a security property: Spoofing violates authenticity, Tampering violates integrity, Repudiation violates accountability, Information disclosure violates confidentiality, Denial of service violates availability, and Elevation of privilege violates authorization. Walking each element of the data flow diagram through the six categories produces a list of candidate threats far more complete than unstructured brainstorming. Each threat is then ranked and assigned a response: mitigate it with a control, eliminate the feature, transfer the risk (insurance, a contract) or accept it with a documented reason.

Ranking STRIDE threats for a toy registration app by likelihood times impact
# Ranking threats for a small course-registration web app
# risk = likelihood (1-5) x impact (1-5); ties broken by impact
threats = [
    ("Spoofing",               "attacker logs in with a stolen password",          4, 4),
    ("Tampering",              "student edits a grade field in a hidden form input", 3, 5),
    ("Repudiation",            "instructor denies changing a mark; no audit log",     2, 3),
    ("Information disclosure", "error page prints the database connection string",   3, 4),
    ("Denial of service",      "login endpoint flooded during registration week",     3, 3),
    ("Elevation of privilege", "student reaches /admin because only the link is hidden", 3, 5),
]
ranked = sorted(threats, key=lambda t: (t[2] * t[3], t[3]), reverse=True)
print(f"{'rank':<5}{'STRIDE category':<24}{'L':>2}{'I':>3}{'risk':>6}  example")
for i, (cat, ex, l, imp) in enumerate(ranked, 1):
    print(f"{i:<5}{cat:<24}{l:>2}{imp:>3}{l*imp:>6}  {ex}")
Output
rank STRIDE category          L  I  risk  example
1    Spoofing                 4  4    16  attacker logs in with a stolen password
2    Tampering                3  5    15  student edits a grade field in a hidden form input
3    Elevation of privilege   3  5    15  student reaches /admin because only the link is hidden
4    Information disclosure   3  4    12  error page prints the database connection string
5    Denial of service        3  3     9  login endpoint flooded during registration week
6    Repudiation              2  3     6  instructor denies changing a mark; no audit log

The ranking above is deliberately simple. Real teams use richer schemes such as DREAD (now largely abandoned because its scores were too subjective), the Common Vulnerability Scoring System for known vulnerabilities, or quantitative estimates of expected annual loss. What matters is that the reasoning is written down and reviewed. Note how two of the top threats, tampering with a hidden form field and reaching an admin page whose link is merely hidden, both violate complete mediation: the server trusted the client to behave. Lesson 9 shows both in code.

Attack trees

Bruce Schneier popularized attack trees in 1999. The root is the attacker's goal. Each child is a way of achieving its parent: an OR node is satisfied if any child is, an AND node only if all children are. Leaves are concrete actions and can be annotated with cost, required skill, probability of detection or time. Evaluating the tree from the leaves up tells you which path an economically rational attacker would choose, and therefore where a defender's money buys the most. The tree in the figure is evaluated by the next program.

Evaluating an attack tree: OR takes the cheapest child, AND adds the children
# An attack tree: OR nodes need any child, AND nodes need all children.
# Each leaf has an estimated attacker cost in dollars; the tree gives the cheapest attack.
tree = ("OR", "Read another student's grades", [
    ("AND", "Steal a session", [
        ("LEAF", "Find an XSS flaw", 2000),
        ("LEAF", "Lure the victim to the page", 200),
    ]),
    ("LEAF", "Guess a weak password (no rate limit)", 300),
    ("AND", "Abuse the API", [
        ("LEAF", "Discover the /api/grades endpoint", 50),
        ("LEAF", "Change the student id in the URL (no access check)", 0),
    ]),
    ("LEAF", "Bribe a teaching assistant", 5000),
])

def cost(node, depth=0):
    kind, name = node[0], node[1]
    if kind == "LEAF":
        c = node[2]
    else:
        costs = [cost(ch, depth + 1) for ch in node[2]]
        c = min(costs) if kind == "OR" else sum(costs)
    print("  " * depth + f"{kind:<4} {name}: ${c:,}")
    return c

cheapest = cost(tree)
print("cheapest attack costs about", f"${cheapest:,}")
Output
    LEAF Find an XSS flaw: $2,000
    LEAF Lure the victim to the page: $200
  AND  Steal a session: $2,200
  LEAF Guess a weak password (no rate limit): $300
    LEAF Discover the /api/grades endpoint: $50
    LEAF Change the student id in the URL (no access check): $0
  AND  Abuse the API: $50
  LEAF Bribe a teaching assistant: $5,000
OR   Read another student's grades: $50
cheapest attack costs about $50

The cheapest path costs about fifty dollars because the grades API checks only that the caller is logged in, not that the requested record belongs to them. This class of flaw, called an insecure direct object reference or broken object-level authorization, tops the OWASP lists discussed in Lesson 9. Fixing it raises the cheapest attack to three hundred dollars (password guessing), and adding rate limiting and multifactor authentication raises it again. Security is rarely about making attacks impossible; it is about making them more expensive than the asset is worth to the attacker.

The attacker's advantage and the economics of security

Defenders must protect every path; attackers need only one. This asymmetry explains why simple, small systems are easier to secure than large ones, and why reducing the attack surface (the set of entry points an attacker can reach) is so effective: every disabled service, closed port and removed feature is one less thing to get right. Security also has an economic dimension. A vulnerability in a widely used library is worth finding for criminals because it opens many systems at once; the vendor may underinvest in fixing it because the cost of breaches falls on customers. Ross Anderson's work on security economics argues that many failures are failures of incentives rather than of technology.

Worked problem

Writing a threat model for a library book-return kiosk

A public library installs a self-service kiosk that scans returned books, updates the catalog database over the library network and prints a receipt. Identify the assets, draw the trust boundaries in words and list one STRIDE threat for each category with a mitigation.

Show solution
  1. Assets: the integrity of loan records, patrons' borrowing history (personal information), the kiosk's availability during opening hours, and the library network it connects to.
  2. Trust boundaries: between the public (anyone can touch the screen and the scanner) and the kiosk software; between the kiosk and the library network; between the network and the catalog database server.
  3. Spoofing: a person scans a book on someone else's card to clear a fine; mitigate by never letting the kiosk clear fines and by logging the card used. Tampering: a USB keyboard plugged into an exposed port types commands; mitigate with locked ports and a kiosk-mode operating system. Repudiation: a patron claims a book was returned; mitigate with a timestamped receipt and server-side log.
  4. Information disclosure: the receipt prints the full borrowing history; print only the items returned now. Denial of service: the scanner is jammed; mitigate with a staffed return slot as backup. Elevation of privilege: escaping the kiosk app to a desktop gives network access; mitigate with application allow-listing and placing kiosks on a separate network segment with access only to the return API.

Answer: The main risks are integrity of loan records and escape from the kiosk application into the library network. Lock down the physical ports, run a locked kiosk mode, segment the network and keep the kiosk's database rights to the minimum needed to record returns.

Worked problem

Applying least privilege to a backup job

A nightly script copies the course database to cloud storage. It currently runs as the database superuser with cloud credentials that can create and delete any storage bucket. What should change?

Show solution
  1. The script only needs to read the database: give it a role with SELECT (or the database's backup privilege) and nothing else.
  2. In the cloud, it only needs to write new objects into one bucket: give it a credential limited to that action on that bucket, with no delete permission, so a compromised script cannot erase old backups.
  3. Enable object versioning or write-once retention on the bucket so even a mistaken overwrite is recoverable; this is defense in depth against ransomware that seeks out backups.

Answer: Replace the superuser and all-powerful cloud key with a read-only database role and a write-only credential for a single versioned bucket. A compromise of the backup host then cannot alter the live database or destroy existing backups.

Worked problem

Fail-safe defaults in an access check

A developer writes: if user.role == "banned": deny() else: allow(). Explain the risk and rewrite the rule.

Show solution
  1. The rule lists what is forbidden and allows everything else. Any new role, a typo in a role name, or a missing role value (None) is allowed by default.
  2. Rewrite to list what is permitted: if user.role in ALLOWED_ROLES_FOR_THIS_ACTION: allow() else: deny().
  3. Add a test that a user with no role and a user with an unknown role are both denied.

Answer: Use an allow list and deny by default; the original deny list fails open whenever the data is unexpected.

Security as a process

No design is secure once and for all. Software changes, new attacks are discovered, configurations drift and people make mistakes. Mature organizations treat security as a continuous cycle: identify assets and risks, protect them, detect incidents, respond, and recover, which is the structure of the NIST Cybersecurity Framework (version 2.0, released in 2024, which added a sixth function, govern). Engineers contribute at every stage, from threat modeling in design to writing logs that make detection possible. The rest of this course works through the mechanisms: cryptography in Lessons 2 to 6, authentication and access control in Lesson 7, software vulnerabilities in Lessons 8 and 9, operating systems and networks in Lesson 10, privacy in Lesson 11, and an end-to-end capstone in Lesson 12.

Common mistakes

  • MistakeSecurity is a product you can buy and install.

    InsteadSecurity is a property of the whole system and the process that maintains it; tools help only when they fit a threat model.

  • MistakeIf the attacker does not know how the system works, it is safe.

    InsteadAssume the design is known (open design); secrecy of the design is at best a speed bump.

  • MistakeThreat modeling is done once, at the start.

    InsteadRevisit the threat model whenever the design, the data or the threat landscape changes.

  • MistakeA deny list of known bad inputs or roles is enough.

    InsteadUse allow lists and fail-safe defaults; deny lists fail open for anything unanticipated.

  • MistakeHiding a link or a button protects the page behind it.

    InsteadEvery request must be checked on the server (complete mediation); hidden links are found by guessing or reading the code.

Summary and key terms

  • Security protects confidentiality, integrity and availability against adaptive adversaries; authenticity, accountability and privacy are closely related goals.
  • Risk combines likelihood and impact; threats exploit vulnerabilities in assets, and controls reduce risk.
  • Saltzer and Schroeder's principles, such as least privilege, fail-safe defaults and complete mediation, still guide secure design.
  • Threat modeling asks what we are building, what can go wrong, what we will do about it and whether we did a good job.
  • STRIDE applied to a data flow diagram with trust boundaries gives a systematic list of threats.
  • Attack trees show which path is cheapest for an attacker and where defense pays off most.
  • Security is a continuing process, not a one-time feature.
CIA triad
Confidentiality, integrity and availability, the three classic goals of security.
Threat
A potential cause of harm, often an actor with a motive and capability.
Vulnerability
A weakness that a threat could use to cause harm.
Exploit
A specific technique that uses a vulnerability.
Threat model
An explicit statement of what is being protected, from whom, and under which assumptions.
Trust boundary
A point where data or control passes between zones of different trust.
STRIDE
Spoofing, tampering, repudiation, information disclosure, denial of service and elevation of privilege.
Attack tree
A tree of AND and OR nodes describing the ways an attacker could reach a goal.
Least privilege
Giving each user or program only the privileges it needs for its task.
Complete mediation
Checking authorization on every access rather than relying on an earlier check.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Give an example of a control that improves confidentiality but harms availability.

    Show answer

    Full-disk encryption: if the key or password is lost, the data is unreadable even to its owner.

  2. Which STRIDE category does a forged email that appears to come from the registrar belong to?

    Show answer

    Spoofing, because it falsifies the identity of the sender.

  3. Why is open design compatible with strong security?

    Show answer

    Security rests on secret keys, not secret algorithms; public designs get reviewed and their flaws found and fixed.

  4. An AND node has children costing 400 and 900 dollars; an OR node above it has another child costing 1,000. What is the cheapest cost?

    Show answer

    The AND node costs 1,300, so the OR node takes the cheaper 1,000.

  5. What is the attack surface of a web application?

    Show answer

    The set of entry points an attacker can reach: URLs, form fields, APIs, file uploads, open ports and administrative interfaces.

  6. A mobile app stores the user's role in the app and sends it with each request. Which principle is violated?

    Show answer

    Complete mediation (and fail-safe defaults): the server must look up the role itself, not trust the client.

  7. Name the four responses to a ranked threat.

    Show answer

    Mitigate, eliminate, transfer or accept.

  8. Why do defenders face an asymmetry?

    Show answer

    They must protect all paths, while an attacker needs to find just one that works.

  9. Describe one threat that is usually declared out of scope for a web application's threat model.

    Show answer

    Compromise of the cloud provider's physical data center or hypervisor, which is handled by the provider.

  10. What does the govern function in NIST CSF 2.0 add?

    Show answer

    Organizational context, roles, policy and oversight of cybersecurity risk, placed at the center of the other five functions.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz