identity = authentication_service.verify(credentials)
session = session_service.create(identity)
# Use maintained libraries; do not invent a password hash.
Authentication flow β conceptual pseudocode: Keep credential verification separate from later object permissions.
A valid password cannot decide which note an account owns.
04
π‘οΈAuthorization β Check Every Object
Deny by default and check the requested action and object on every request.
A signed-in user is not allowed to read all notes.
Query and update within the permitted ownershipscope; never accept a submitted owner or role as authority.
π
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;
Ownership scope β conceptual database fragment: Bind both values using the actual driver.
Obtain trusted_user_id from validated server identity, not submitted JSON.
Scope writes similarly and check affected rows.
05
πͺSessions and Cookies
Use unpredictable session identifiers, regenerate on login and relevant privilege changes, and expire sessions server-side on logout and time limits.
For cookie sessions configure Secure, HttpOnly and suitable SameSite and scope.
HttpOnly restricts script access to cookies; it does not make XSS harmless.
Avoid session identifiers in URLs.
β³
Lifecycle
Create β rotate β expire; a stale browsercookie cannot revive an invalid session.
Writable JSON contract: The lab rejects extra fields even when text is valid.
In a real endpoint, parse only explicitly writable fields and apply domain rules after authentication and authorization.
10
πTLS and Browser Policy
Use HTTPS and secure transport throughout the deployment.
CORS controls browser cross-origin response access; it does not authenticate callers.
A carefully tested Content Security Policy can limit script execution as an additional layer.
Use frame-ancestors for a deliberate embedding policy.
Develop CSP for the actual site and test reports rather than pasting a policy that breaks legitimate scripts.
π§±
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?
Policy questions: Answer each question separately.
Restrictive CORS cannot stop a non-browser client from sending requests to an inadequately protected backend.
11
πSecrets, Dependencies and Configuration
Keep private keys and backend secrets out of frontend bundles and repositories.
Use scoped secrets and rotate exposed credentials.
Review dependencies and update vulnerable packages.
Disable unnecessary services and debug endpoints; development settings are not automatically safe for production.
ποΈ
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
Configuration separation: A variable called SECRET in client JavaScript remains public.
Restrict secret access and provide an operational rotation path.
12
πUploads, URLs and Server Fetches
For uploads combine size limits, allowed types, content inspection, safe generated names, controlled storage and authorization.
A claimed MIME type is untrusted.
For serverURL fetching prevent access to internal addresses and constrain redirects; use a maintained SSRF protection approach.
Validate redirects against an explicit destination policy.
π§
Indirect access
A backendfetch can reach resources the browser cannot.
Upload review checklist: No single check is enough.
A filename, extension or client-supplied MIME label cannot establish that a file is harmless or authorized for public serving.
13
β±οΈAbuse and Resource Limits
Limit attempts and resource use at relevant boundaries.
Consider account, caller and operation scope, expensive requests, concurrency and storage limits.
A frontend maxlength is convenience; the server must enforce its own bounds.
Avoid trusting arbitrary forwarding headers when determining callers.
π
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
Resource budget worksheet: Test the outcome when each budget is exhausted.
The visible textarea limit does not prevent a caller from crafting a larger direct request.
14
πLogs, Errors and Privacy
Use stable public errors and protected operational logs.
Do not log passwords, session tokens or CSRF tokens.
Avoid revealing whether another userβs private object exists.
Retain only necessary data and protect log access.
The lab state panel exposes fictional teaching data; it is not a pattern for a production debug endpoint.
π
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
Public versus protected diagnostic: The lab deliberately uses the same public access message for a missing note and another ownerβs note.
Its fictional state panel is teaching instrumentation only.
15
π§ͺVerify the Security Boundary
Test anonymous, expired and valid sessions, different owners, missing or stale tokens and malformed bodies.
Confirm rejection leaves data unchanged.
Test actual backendauthorization, cookies, HTTPS, CSRF middleware and database operations independently.
Successful local tests cannot certify a deployed application.
π
Negative tests
Try the request a caller should not be permitted to perform.
Negative-case matrix: For every denied case snapshot stored state before and after.
Add real integration checks for framework sessioncookies, CSRF middleware, database scope and concurrent writes.
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
This local model has fictional notes owned by A and B.
Select a trusted session fixture to simulate server-side identity: the selector itself is not real authentication.
GET reads an owned note; POST updates it.
DELETE is unsupported.
Unknown and non-owned notes share one public access-denied message.
POST requires exact expected origin https://learn.example and the selected active sessionβs current CSRF token.
The visible predictable demo tokens teach matching and rotation only; production tokens must use the frameworkβs secure generation and verification.
GET ignores origin, token and body and never mutates.
POST accepts raw JSON up to 1,000 JavaScript code units, exactly text as a string trimmed to 1β120 Unicode code points without C0/C1 controls or lone surrogates.
JSON.parse uses the last duplicate key; this model does not detect duplicate JSON keys.
Rotate/expire clear previous results; reset restores all fixtures.
No network, cookies, passwords or real accounts are used.
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
Check route and method, then session validity, object ownership, write origin/token and input contract.
A valid token never grants access to another ownerβs note.
Fix the rejected boundary rather than removing the protection.
After token rotation, copy the new token from the fictional state panel; an old token must fail.
Expiration invalidates the fixture even if a token still appears in the input.
An error must clear the previous note preview.
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.
ποΈ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
Specify identity, ownership and writable fields for read and update.
Use maintained session and CSRF infrastructure, bind database values, and render plain text safely.
Keep logs and public errors appropriate to their audiences.
Write negative tests for anonymous, expired, other-owner, wrong-origin, stale-token and invalid-body requests.
Assert both denial and unchanged stored data.
Implement authorization and mutation within the appropriate backend transaction or atomic operation.
Verify actual cookies, HTTPS, origin handling, backend queries and deployment policy independently.
Success means explaining which boundary each defense protects.
Next: Level29 β Web Performance and Deployment.
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.