Learn Security Engineering

Start with assets and capabilities, trace data and identity across trust boundaries, run the safe attack path, then design prevention, detection, recovery and a residual-risk statement.

Security Fundamentals

Assets, threats, trust boundaries, blast radius, least privilege, defense in depth — and why no system is ever called "secure".

What Security Engineering Actually Is
▶ lab

Security engineering is not a checklist of vulnerabilities; it is the discipline of deciding what you value, who can reach it, what you are trusting, and what happens when one of those assumptions turns out to be wrong.

Boundary · Every place where data or control passes from something you do not control into something you do.
Confidentiality, Integrity, Availability — Practically
▶ lab

Three questions that classify any security failure: who can read it, who can change it, and can legitimate users still work — plus the three that modern systems need alongside them: authenticity, accountability and privacy.

Boundary · The boundary between "identity that is allowed this operation on this record" and "identity that is not".
Trust Boundaries
▶ lab

A trust boundary is any point where data or control crosses from something you do not control into something you do — and every one of them is a place where an assumption must be re-validated rather than inherited.

Boundary · This lesson is about the boundary itself: where it is, what it must validate, and what goes wrong when it is drawn on a diagram but not enforced in code.
Attack Surface
▶ lab

The attack surface is the set of places an attacker can send input or trigger behaviour — and reducing it is usually cheaper, more durable and more measurable than defending every entry you leave open.

Boundary · The outermost boundary — everything that answers a request from somewhere you do not control.
Least Privilege
▶ lab

Give every identity — human, service, job or agent — exactly the permissions its job requires, because the permissions you grant are the definition of how bad a compromise of that identity can be.

Boundary · The authorization boundary attached to the identity itself, evaluated by whatever system grants the capability: the database, the cloud provider, the API, the operating system.
Defense in Depth
▶ lab

Design so that no single control failing is enough to lose the asset — because every control will eventually fail, and the question that matters is what the next layer does about it.

Boundary · Several, deliberately: each layer is a boundary that re-checks something the previous one was supposed to have handled.
Secure Defaults
▶ lab

The default configuration is the configuration most of your system will actually run, so the security question is not "can it be configured safely?" but "what happens when nobody configures it at all?"

Boundary · The boundary between "explicitly decided" and "whatever the framework did", which is where most production exposure lives.
Fail Open vs Fail Closed
▶ lab

When the control cannot make a decision — the policy service is down, the token cannot be verified, the rate limiter is unreachable — the system must do something, and choosing which way it fails is a design decision with no universally right answer.

Boundary · The authorization or validation boundary, at the moment it cannot answer.
Risk, Residual Risk and Honest Reporting
▶ lab

Security is risk management, so the output of security work is not "secure" but four lists: identified controls, known risks we accepted, residual risks that survive our controls, and unknowns we have not examined.

Boundary · The boundary between what has been examined and what has not — the most under-communicated fact in most security reporting.
Threat Modeling

System → assets → actors → entry points → trust boundaries → threats → mitigations. STRIDE, attack surface mapping, attack trees, and how to run a security review on a real architecture.

Threat Modeling: The Process
▶ lab

System → assets → actors → entry points → trust boundaries → threats → mitigations: a repeatable hour of structured thinking that finds design flaws no scanner will ever find, because they are not bugs.

Boundary · Every boundary in the system, which is the artefact the process is designed to make visible.
STRIDE — One Structured Method
▶ lab

Six prompts — spoofing, tampering, repudiation, information disclosure, denial of service, elevation of privilege — applied to each element of a diagram, which converts "think of what could go wrong" into a finite, checkable list.

Boundary · Applied at each data flow crossing a trust boundary, which is where the six prompts produce their best results.
Attack Trees
▶ lab

Start from the attacker's goal and decompose it into every path that achieves it, so you can see which defense covers several branches at once and which branch nothing covers at all.

Boundary · Each branch crosses different boundaries, which is what makes the tree useful — it exposes paths that a component-by-component review keeps separate.
Mapping the Attack Surface of a Real System
▶ lab

Take an architecture diagram and colour every node by exposure — public, authenticated, internal, privileged, highly sensitive — because the pattern that appears is usually more informative than any individual finding.

Boundary · Every edge between two differently-coloured nodes is a boundary, and the colouring is what makes them countable.
Security Review Mode: Any Architecture, Ten Questions
▶ lab

A repeatable interrogation you can run against any system diagram — yours, a candidate's, a vendor's — that produces specific findings in under an hour without needing to know the codebase.

Boundary · All of them — the review is largely an exercise in making boundaries explicit and then asking what each one validates.
Identity & Authentication

Who are you? Credentials, password storage, credential stuffing, MFA, passkeys — and one login followed all the way from a browser to a database row.

Authentication vs Authorization
▶ lab

Authentication answers "who are you?"; authorization answers "what are you allowed to do?" — and the overwhelming majority of real access-control bugs are systems that did the first one correctly and skipped the second.

Boundary · The boundary between "this request has an identity" and "this identity may perform this action on this resource".
Authentication as a Lifecycle
▶ lab

Authentication is not a login form: it is registration, credential storage, login, second factors, session establishment, re-authentication, recovery, device management and revocation — and attackers reliably target the least-defended stage, which is almost always recovery.

Boundary · The boundary between anonymous and identified — crossed at login, and crossed again, less carefully, at every recovery and re-authentication path.
Follow a Login
▶ lab

One login traced end to end at four zoom levels — browser to TLS to password verification to session to cookie to the authorized read — naming at every stage what is sent, what boundary is crossed, what must be protected, and what an attacker would try.

Boundary · Five in sequence — network, application edge, credential store, session store, and resource authorization — each with a distinct threat and a distinct control.
Password Storage
▶ lab

The database should never contain the password, and it should not contain a fast hash of the password either — because the entire threat model is what an attacker does with a copy of the table.

Boundary · The boundary between "the database was disclosed" and "user accounts elsewhere were compromised" — a boundary made entirely of the hash function you chose.
How Passwords Are Actually Attacked
▶ lab

Offline guessing against a stolen table, online credential stuffing with passwords from other breaches, and targeted attempts against one account — three different attacks with three different defenses, only one of which is the hash function.

Boundary · The login boundary for the online attacks; no boundary at all for the offline one, which is why the offline defense must be built into the stored value itself.
Multi-Factor Authentication
▶ lab

Requiring a second, independent kind of evidence — something you have or something you are, alongside something you know — with the honest ranking of which factors resist phishing and which merely resist password reuse.

Boundary · The login boundary, crossed a second time with a different kind of evidence — and, critically, the recovery boundary where that requirement is most often dropped.
Passkeys and WebAuthn
▶ lab

Public-key authentication in the browser: the device keeps a private key, the server stores only the public key, and the signature is bound to the origin — which removes the shared secret and makes relayed credentials worthless.

Boundary · The origin boundary, enforced by the browser and cryptographically embedded in the signature rather than checked by a human reading a URL bar.
Sessions & Tokens

How the server keeps remembering you: session IDs, cookie attributes, hijacking, rotation, revocation, and what JWTs actually buy and cost.

Sessions
▶ lab

Authentication happens once; the session is what makes the next thousand requests work — a random opaque identifier that maps to server-side state you can inspect, expire and revoke.

Boundary · The boundary between an anonymous request and an identified one, re-crossed on every single request for the life of the session.
Cookies and Their Attributes
▶ lab

Six attributes decide whether a cookie is a reasonable place to keep a session or a liability: `Secure`, `HttpOnly`, `SameSite`, `Domain`, `Path` and lifetime — and each one maps to a specific attack.

Boundary · The browser's origin and site model, which is the only thing deciding who can read the cookie and which requests carry it.
Session Hijacking
▶ lab

The attacker does not need the password: possession of the session token is possession of the account, and every defense is either about preventing the token from escaping or about limiting what it is worth once it has.

Boundary · The boundary between the user's browser and everywhere else — a boundary that leaks through logs, referrers, third-party scripts and shared screens.
JWT — What It Is and What It Costs
▶ lab

A signed, self-contained token that lets a service verify a claim without a lookup — which buys statelessness and pays for it with revocation you have to engineer separately.

Boundary · The verification boundary: everything after it treats the claims as true, so the correctness of the check is the whole of the security.
JWT Failure Modes
▶ lab

The specific ways token validation goes wrong — trusting the header's algorithm, skipping issuer and audience, over-long expiry, treating signed as confidential — and the verification routine that closes all of them.

Boundary · The verification function — a boundary that is a handful of lines and is trusted absolutely by everything behind it.
OAuth & OIDC

Delegated authorization, the authorization code flow with PKCE, and the identity layer on top — with the "OAuth is not login" distinction taken seriously.

Authorization

What are you allowed to do? Ownership checks, RBAC, ABAC and policy, broken access control, tenant isolation, and where enforcement must live.

Authorization Models
▶ lab

Ownership checks, roles, permissions, attribute policies, scopes and tenant isolation are different tools for the same question — and most real systems need three of them at once, layered in a specific order.

Boundary · Between the identity established by authentication and the action performed on a specific resource.
Role-Based Access Control
▶ lab

Users get roles, roles get permissions — simple to reason about, easy to audit, and prone to a predictable failure when the role set grows to match every feature.

Boundary · Between the identity and the set of verbs it may perform.
ABAC and Policy-Based Authorization
▶ lab

Decide by evaluating a rule over the requester's attributes, the resource's attributes, the action and the environment — expressive where roles are not, and dangerous when the rules become unreadable.

Boundary · Between the policy decision point and the code that enforces it.
Broken Access Control (IDOR / BOLA)
▶ lab

`GET /invoices/100` works; `GET /invoices/101` also works and it is not yours. Authentication succeeded, authorization was never asked — the most common serious vulnerability in web applications and APIs.

Boundary · The record-level boundary between requester and resource owner.
Multi-Tenant Isolation
▶ lab

A `tenant_id` column is not isolation. Isolation is that column enforced consistently across queries, caches, queues, storage, search, logs and AI context — every place a copy of the data exists.

Boundary · The tenant boundary, which exists in every subsystem and is enforced in each one separately.
Where Authorization Must Live
▶ lab

Not in the frontend, not only at the gateway, and not as an optional call in each handler — but at the point where the resource is loaded, structured so it cannot be skipped.

Boundary · The point of enforcement — which must sit on every path to the data.
Cryptography & TLS

Hashing vs encryption vs encoding, symmetric and asymmetric keys, signatures, TLS as a security boundary, and certificate trust chains.

Cryptography Fundamentals
▶ lab

Plaintext, ciphertext, keys, hashes, MACs, signatures, nonces and randomness — the vocabulary you need to use cryptography correctly, plus the one rule that matters most: use established libraries and protocols, never your own.

Boundary · Between "protected by a key" and "protected by a mechanism that only looked like a key".
Hashing vs Encryption vs Encoding
▶ lab

Encoding is reversible without a secret, hashing is one-way, encryption is reversible with a key — three different tools that are routinely confused, and the confusion produces real vulnerabilities.

Boundary · Between representation, integrity and confidentiality.
Symmetric Encryption
▶ lab

One shared key encrypts and decrypts — fast enough for bulk data, and the whole difficulty is getting that key to both parties and keeping it from everyone else.

Boundary · Between key holders and everyone else.
Asymmetric Cryptography
▶ lab

A public key anyone may hold and a private key only one party holds — enabling key exchange without a shared secret, signatures anyone can verify, and identity that does not require pre-sharing anything.

Boundary · Between "holder of the private key" and everyone else, verifiable by everyone.
Digital Signatures
▶ lab

Sign with a private key, verify with the public key: proof that a message is unmodified and came from the key holder — the mechanism behind JWTs, webhooks, signed artefacts and passkeys.

Boundary · Between a claim and a verifiable claim.
TLS as a Security Boundary
▶ lab

Networking explains how the handshake works; here the question is what TLS actually guarantees — server authentication, confidentiality and integrity for one hop — and the many things "we use HTTPS" does not cover.

Boundary · The network hop between client and the TLS-terminating endpoint — and not one byte further.
Certificate Trust Chains

A client accepts a server certificate only when the hostname, validity and signatures form a chain through an intermediate to a locally trusted root.

Boundary · Presented server identity → client trust store
Web Security

The browser is an execution environment an attacker can reach. XSS, CSRF, CORS and the origin model that decides what any of them mean.

Web Security: Browser to Database
▶ lab

Map browser execution, origins, cookies, API decisions and database interpretation onto one end-to-end path.

Boundary · Browser → web application → API → database
Cross-Site Scripting (XSS)
▶ lab

XSS exists when attacker-controlled data crosses into an HTML, attribute, URL or JavaScript context and the browser interprets it as behavior.

Boundary · Untrusted data → browser execution context
XSS Defense by Output Context
▶ lab

Escaping rules depend on whether data enters HTML text, an attribute, a URL or JavaScript; validation alone cannot solve every context.

Boundary · Application output → specific browser parser
Content Security Policy

CSP limits which code a browser may execute, buying a second boundary after an output-encoding defect.

Boundary · Rendered document → executable resource
Cross-Site Request Forgery (CSRF)
▶ lab

A browser can attach ambient credentials to a request initiated by another site; the server mistakes possession of a cookie for user intent.

Boundary · Attacker-controlled origin → credentialed application request
CSRF Defense

Choose defenses from the authentication style: ambient cookies create CSRF exposure; explicit authorization headers change the browser behavior and threat.

Boundary · Cross-origin request → state-changing handler
CORS Without the Myths
▶ lab

CORS is a browser-enforced cross-origin response-reading policy, not server authentication and not protection from non-browser clients.

Boundary · One browser origin → another origin’s response
Injection & Untrusted Input

The same bug in six costumes: data crossing a boundary and being interpreted as instructions — SQL, shell, paths, URLs, serialized objects.

API Security

Authentication, object-level authorization, rate limits, replay, webhooks, mass assignment and file uploads — the boundary most systems actually expose.

API Security as a Boundary
▶ lab

Every API operation must parse, validate, authenticate, authorize, limit and record—especially when a request names a resource.

Boundary · Network request → application capability
Parse, Validate, Authorize, Process
▶ lab

Validation answers “is this value well-formed and meaningful?”; authorization separately answers “may this principal perform this action?”

Boundary · Untrusted request → typed application data
Mass Assignment and Over-Posting
▶ lab

Binding an arbitrary request object onto a model lets the caller edit fields the UI never exposed, including roles, owners and prices.

Boundary · Request object → persistent model
Rate Limiting as a Security Control
▶ lab

Rate limits make guessing and resource abuse more expensive, but they are not authentication and can be distributed around.

Boundary · Repeated requests → finite compute or attempt budget
Replay Attacks
▶ lab

A valid request can still be harmful when captured and repeated; authenticity does not automatically imply freshness or exactly-once effect.

Boundary · Previously valid message → current state change
Secure Webhooks
▶ lab

A public webhook endpoint must verify who sent the exact body, when it was sent, and whether the event was already processed.

Boundary · External provider → privileged application event
File Upload Security
▶ lab

A file crosses several boundaries—request, parser, storage, scanner, processor and serving path—and each interprets different metadata.

Boundary · Untrusted file → parsers, storage and public serving
Data & Database Security

Database privileges, data classification, encryption at rest versus in transit, and the copies of your data you forgot about: backups, replicas, logs.

Network, OS & Container Security

Segmentation, firewall rules, egress control, process isolation, privilege separation, sandboxing — and why a container is not a security boundary you can lean on.

Network Security Boundaries
▶ lab

Network design controls reachability and blast radius; it does not turn an internal caller into a trusted identity.

Boundary · Public, application, database and management networks
Network Segmentation
▶ lab

Internet → public layer → application network → database network → management network: crossings are explicit and narrow.

Boundary · One network zone → a more privileged zone
Firewalls and Security Groups
▶ lab

A rule is source, destination, port, protocol and action; every broad wildcard is an explicit expansion of attack surface.

Boundary · Network source → destination socket
Egress Security
▶ lab

Security also asks what a compromised service can call outward; unrestricted egress enables SSRF, command-and-control and exfiltration.

Boundary · Workload → internal services and internet destinations
Operating System Security

Processes, users, file permissions, privileges, patching and resource limits decide what a compromised application can do next.

Boundary · Process identity → kernel-mediated resources
Privilege Separation

A web server should run as a restricted user; administrative setup and runtime request handling should not share one authority.

Boundary · Restricted runtime identity → host administration
Unix-Style File Permissions

Owner, group and others each receive read, write and execute; the effective service identity determines which boundary actually exists.

Boundary · Process user/group → filesystem object
Sandboxing Untrusted Workloads
▶ lab

A sandbox constrains files, network, CPU, memory, syscalls and credentials so untrusted computation cannot spend or reach everything.

Boundary · Untrusted workload → host and network capabilities
Container Security and Its Limits
▶ lab

Containers package and isolate processes but share a host kernel; privileged mode, host mounts and broad capabilities erase much of the boundary.

Boundary · Container namespace/cgroup → shared host kernel
Cloud & IAM Security

Identity → policy → action → resource. Machine identities, short-lived credentials, and the full lifecycle of a secret from creation to revocation.

Cloud Security Fundamentals
▶ lab

Cloud security is identity and policy first, then reachable networks, resource policies, secrets, encryption and evidence.

Boundary · Cloud identity → policy → action → resource
Identity and Access Management (IAM)
▶ lab

An IAM decision binds a principal, action, resource and conditions; a wildcard in any dimension expands blast radius.

Boundary · Authenticated identity → authorized cloud API action
Human vs Machine Identities

People, services, CI/CD, agents and automation need separate identities so access can be scoped, attributed and revoked independently.

Boundary · Distinct actor → distinct credential and policy
Short-Lived Credentials
▶ lab

A workload exchanges its identity for a temporary credential that expires, reducing the useful lifetime of theft and eliminating manual rotation.

Boundary · Workload identity → temporary delegated capability
Secrets Management
▶ lab

A secret should not live everywhere: applications retrieve or receive narrowly scoped values from a controlled system with audit and rotation.

Boundary · Secret manager → authorized workload
The Secret Lifecycle
▶ lab

Create → store → distribute → use → rotate → revoke → audit: weakness in any stage determines the effective protection.

Boundary · Secret material → each storage, delivery and use location
Infrastructure Secret Injection

A committed .env file or secret baked into an image turns version control and every image copy into credential stores.

Boundary · Deployment control plane → runtime workload
Supply Chain Security

Your code is a minority of what you ship. Dependencies, lockfiles, provenance, malicious packages, CI/CD permissions and build integrity.

Secure Software Design

Secure defaults, fail closed, complete mediation, minimal trusted computing base, error handling that does not leak, and audit logs that answer questions.

Detection & Response

Prevention fails. Telemetry → detection → alert → investigation → containment → recovery → learning, plus vulnerability management that prioritises exposure over CVSS.

Security Testing

SAST, DAST, dependency and secret scanning, fuzzing, penetration testing — what each finds, what each misses, and the security tests that belong in CI.

AI & Agent Security

Prompt injection, untrusted tool output, over-privileged tools, poisoned retrieval and memory — and the one rule: the model is never the authorization layer.

AI and Agent Security
▶ lab

Agents combine untrusted language, retrieved data, memory, models and tools; capability boundaries—not model obedience—control the outcome.

Boundary · Untrusted context → model proposal → privileged tool
Agent Trust Boundaries
▶ lab

User, model, retrieval, memory, tools and external content have different trust and privilege; mark every flow explicitly.

Boundary · User/RAG/memory/tool output → model context → tool request
Direct and Indirect Prompt Injection
▶ lab

A user or retrieved document supplies language that the model may confuse with authority; the robust defense is to constrain capabilities and decisions outside it.

Boundary · Untrusted language → model instruction-following behavior
Agent Tool Capability Security
▶ lab

A tool schema is a capability interface: make it narrow, bind it to a principal, enforce policy outside the model and record the result.

Boundary · Model-generated arguments → deterministic privileged operation
The Model Is Not the Authorization Layer
▶ lab

The agent proposes an action; deterministic code evaluates principal, action, resource and policy. Natural-language confidence is never permission.

Boundary · Probabilistic model output → deterministic authorization decision
Human Approval for High-Risk Agent Actions
▶ lab

Money transfer, deletion, external communication and permission changes should pause at an explicit risk gate with a comprehensible diff.

Boundary · Agent proposal → external side effect
Tool Output Is Untrusted
▶ lab

A website, API or integration can return text that is false or malicious; tool data must not become higher-priority authority simply because a tool fetched it.

Boundary · External tool result → model context
RAG and Agent Memory Security
▶ lab

Retrieval and memory add durable, searchable copies of data where poisoning, tenant-filter mistakes, retention and sensitive recall become security boundaries.

Boundary · Document/memory write → retrieval → another decision or user
Agent Sandboxing
▶ lab

Code execution gets limited files, network, CPU, memory and scoped credentials; the sandbox must constrain the capability, not just the process tree.

Boundary · Agent-generated workload → host and infrastructure