Skip to lesson content
Web Technologies β€Ί Level 28
LEVEL 28 Β· WEB SECURITY

Web Security

Protect identity, permissions, state changes and browser output at their correct boundaries.

πŸ›‘οΈ Trust boundariesπŸ”‘ Identity + access🎟️ Protected writesπŸ§ͺ Lab + MCQs
01

Learning Objectives

Boundary

Controls belong where untrusted data reaches a protected operation.

02

Trust Boundaries and Threat Models

Model

Browser β†’ server β†’ data store: each arrow needs a defined contract.

asset: private note
caller: anonymous / owner / other user
actions: read / update
expected denial: no private note returned
Follow a trust boundary
Caller

Supplies untrusted input

Backend

Enforces identity and permission

Store

Persists only accepted changes

03

Authentication β€” Establish Identity

Identity

Successful identity verification supplies trusted server-side identity.

identity = authentication_service.verify(credentials)
session = session_service.create(identity)
# Use maintained libraries; do not invent a password hash.
04

Authorization β€” Check Every Object

Ownership

User A β†’ A note allowed; user A β†’ B note denied.

SELECT id, text FROM notes
WHERE id = :note_id AND owner_id = :trusted_user_id;
05

Sessions and Cookies

Lifecycle

Create β†’ rotate β†’ expire; a stale browser cookie cannot revive an invalid session.

Set-Cookie: session=<opaque-id>; Path=/; Secure; HttpOnly; SameSite=Lax
06

CSRF β€” Protect State-Changing Requests

Write gate

Authenticated session + authorization + CSRF checks precede mutation.

resolve_active_session()
authorize_requested_note()
verify_framework_csrf_protection()
validate_writable_fields()
apply_authorized_update()
A write requires every gate
Session

Active trusted identity

Ownership

Allowed object and action

CSRF

Accepted protected request

07

XSS β€” Render for the Correct Context

Text

Markup-looking note text stays visible text in the local preview.

const paragraph = document.createElement("p");
paragraph.textContent = note.text;
preview.replaceChildren(paragraph);
08

Injection β€” Separate Values from Instructions

Query boundary

Fixed query structure + separately bound values.

UPDATE notes SET text = :text
WHERE id = :id AND owner_id = :trusted_user;
09

Validation and Writable Fields

Exact shape

The note lab accepts exactly one text field.

{"text":"Review trust boundaries"}

Reject: {"text":"New note","owner":"B","role":"admin"}
10

TLS and Browser Policy

Layers

TLS, CSP and CORS solve different boundary problems.

TLS: is every protected request encrypted?
CORS: which browser origins may read responses?
CSP: which scripts may execute?
Authorization: may this caller access this object?
11

Secrets, Dependencies and Configuration

Secret location

Anything shipped to a browser is accessible to its user.

browser: public API URL, display options
backend: scoped database credential, signing secret
operations: secret rotation and dependency update process
12

Uploads, URLs and Server Fetches

Indirect access

A backend fetch can reach resources the browser cannot.

allowed extension + verified content
size limit + generated storage name
controlled storage + authorized retrieval
13

Abuse and Resource Limits

Budget

Bound bytes, work, frequency and stored results.

input bytes: bounded at server boundary
request work: bounded per operation
attempt frequency: appropriate caller/account scope
concurrent work: controlled upstream and backend
14

Logs, Errors and Privacy

Observability

Public message and private diagnostic detail have different audiences.

public: This note is not available to this caller.
protected log: operation + correlation ID + permitted diagnostic
never: password, session token, CSRF token
15

Verify the Security Boundary

Negative tests

Try the request a caller should not be permitted to perform.

anonymous read β†’ deny
owner read β†’ allow
other-owner write β†’ deny
owner write + stale token β†’ deny
owner write + valid gates β†’ allow
16

Premium Visualizer β€” A Protected Note Update

Follow an owned-note update through trusted session lookup, object authorization, CSRF checks, validation and safe presentation. This player models policy decisions without a server.

WEB SECURITY POLICY TRACE
Step 1 of 5
STEP 01

Resolve trusted session identity

An active server-side session identifies user A.

session β†’ user A

What is happening?

A request body cannot choose its own trusted identity.

17

Premium Interactive β€” Protected Note Policy

Idle. Fictional policy model.

Teaching state Β· never expose real session secrets this way

Simulated input

No request yet.

Decision trace

No trace yet.

Public decision Β· policy outcome, not HTTP status

No response yet.

Returned note Β· literal JSON

No returned note.

Safe note preview

No result yet.
18

Debugging β€” Find the First Failed Gate

19

Interview Questions β€” Flip to Explain

QUESTION

Authentication versus authorization?

Click or press Enter to explain
ANSWER

Identity verification establishes who; authorization decides which action on which object is allowed.

QUESTION

Why check ownership on GET?

Click or press Enter to explain
ANSWER

Private data must be protected on reads as well as writes.

QUESTION

Does CORS authenticate callers?

Click or press Enter to explain
ANSWER

No. Backend identity and permission checks remain necessary.

QUESTION

Is SameSite the whole CSRF defense?

Click or press Enter to explain
ANSWER

No. Use the framework’s CSRF defenses and suitable additional origin/cookie controls.

QUESTION

Does HttpOnly eliminate XSS?

Click or press Enter to explain
ANSWER

No. Script may still act within the page even without reading the cookie.

QUESTION

Why not concatenate SQL?

Click or press Enter to explain
ANSWER

Untrusted values can alter query structure; use the driver’s bound parameters.

QUESTION

Does validation replace output handling?

Click or press Enter to explain
ANSWER

No. Accepted data still needs handling appropriate to its destination context.

QUESTION

What do these passing local tests prove?

Click or press Enter to explain
ANSWER

The specified local decision behavior; they do not verify a deployed backend or real session system.

20

MCQ Practice β€” Explain Security Decisions

PRACTICE

1. Who supplies trusted identity?

PRACTICE

2. A signed-in A requests B’s private note. What happens?

PRACTICE

3. Which operation should be read-only?

PRACTICE

4. What is a CSRF token in production?

PRACTICE

5. Which layer can undermine CSRF defenses?

PRACTICE

6. How should plain note text be rendered?

PRACTICE

7. Which SQL pattern separates values?

PRACTICE

8. An extra owner field is submitted. What happens here?

PRACTICE

9. What does HttpOnly restrict?

PRACTICE

10. Expired session plus correct old token means?

PRACTICE

11. What must a rejected update do?

PRACTICE

12. Does this lab certify website security?

21

Extra Practice β€” Predict the Security Decision

Owned read

A reads note1: allow; no mutation.

Other owner

A requests note2: access denied, no note returned.

Anonymous

Anonymous note1: session rejection.

Expired

Expire A then read: session rejection.

Wrong origin

Owned POST with another origin: deny, unchanged note.

Stale token

Rotate A; old token denied; current token may pass remaining checks.

Extra field

Add owner or role to valid JSON: reject, unchanged note.

Literal text

Write <Demo> & notes: allowed text stays literal. Reset restores fixtures.

22

Quick Revision

Identity: Trusted authentication.
Permission: Per-action and per-object.
Session: Rotate and expire server-side.
CSRF: Protect state changes.
XSS: Context-appropriate safe output.
Injection: Separate data from instructions.
Validation: Bound shape, type and size.
Browser policy: Additional tested layers.
Logs: Protect sensitive information.
Verification: Test denial and unchanged state.
23

Glossary β€” Flip to Learn

TERM

Authentication

Click to see meaning
DEFINITION

Authentication

Verifying a claimed identity.

TERM

Authorization

Click to see meaning
DEFINITION

Authorization

Deciding whether an action on a resource is permitted.

TERM

Session

Click to see meaning
DEFINITION

Session

State connecting subsequent requests to a verified identity.

TERM

CSRF

Click to see meaning
DEFINITION

CSRF

An unwanted authenticated action induced through browser request behavior.

TERM

XSS

Click to see meaning
DEFINITION

XSS

Untrusted executable content running in a page’s security context.

TERM

Injection

Click to see meaning
DEFINITION

Injection

Untrusted input altering an interpreted instruction’s structure.

TERM

Mass assignment

Click to see meaning
DEFINITION

Mass assignment

Unintended modification of fields through broad input mapping.

TERM

Least privilege

Click to see meaning
DEFINITION

Least privilege

Granting only the permissions necessary for an intended task.

TERM

Trust boundary

Click to see meaning
DEFINITION

Trust boundary

A point where data or control moves between different trust levels.

TERM

Defense in depth

Click to see meaning
DEFINITION

Defense in depth

Complementary protections across multiple boundaries.

24

Final Challenge β€” Protect a Private Note Feature

25

Level 28 Complete?

Explain identity versus permission, reproduce rejected requests with unchanged notes, and describe safe output and bound query values. Identify why the fictional lab is not production authentication. Completion is a local study marker.