Security
XSS, CSRF, CORS, cookies and keeping tokens and users safe.
35 lessons 58 practice questions about 3 hours of reading
Chapter 1, beginner
Foundations
What it is and how it works, the questions every round starts with.
- 01Authentication vs authorization: what is the difference?
Lesson, 4 min read, then 5 questions to practise
- Design authentication and authorization for an internal admin console
- Design a multi-tenant SaaS admin dashboard: RBAC, tenant isolation, white-labelling, audit logs and entitlements
- Build login, register and a protected dashboard without a router library: AuthProvider, useAuth and redirects
- Design SPA authentication: OAuth PKCE, token storage, refresh rotation and multi-tab refresh
- Refactor a withAuth HOC and a render-prop loader into hooks without changing behaviour
- 02Can you hide an API key in frontend code?
Lesson, 5 min read, then 4 questions to practise
- Load runtime config from /config.json instead of build-time env vars
- Design one build promoted across environments: runtime config, secrets, previews and rollback
- Diagnose a failing CORS preflight and write the server's CORS handler
- Write a fetch wrapper that sends the CSRF token only where it belongs: unsafe same-origin requests, a cookie or <meta> token, and one refresh on 403
- 03Client-side vs server-side validation: why do you need both?
Lesson, 5 min read, then 7 questions to practise
- Build a small Zod-style schema validator
- Design a form library for a large app: validation, async checks, field arrays, performance and server errors
- Validate a form with the Constraint Validation API: setCustomValidity, custom messages and aria-invalid
- Build a sign-up form with useActionState: field errors, kept values, pending and success
- Check username availability in a signup form: debounce, ignore stale responses and re-check on submit
- Write type guards and assertion functions that narrow unknown API data
- Build a controlled form with dynamic validation
- 04Hashing vs encryption vs encoding: what is the difference?
Lesson, 5 min read, then 5 questions to practise
- Design an approval audit trail the UI cannot forge: events, hash chains and exports
- Build a password generator that guarantees each chosen character type
- Build an accessible password-strength meter
- Design passkey (WebAuthn) sign-in without trusting the client
- Protect a web app from CSRF with signed tokens, Origin checks and SameSite cookies
- 06What is reverse tabnabbing and how do you prevent it?
Lesson, 4 min read, then 4 questions to practise
Chapter 2, intermediate
In depth
How it behaves under the hood, and the follow-ups that come next.
- 07Access token vs refresh token: what is the difference?
Lesson, 5 min read, then 3 questions to practise
- 08How do you use postMessage safely between windows and iframes?
Lesson, 4 min read, then 5 questions to practise
- Implement a secure postMessage communication protocol between a parent page and embedded iframe
- Design a checkout SDK's internals like Razorpay Checkout: iframe isolation, postMessage protocol, UPI intent, 3-D Secure and callbacks
- Design a plugin system like Figma's: sandboxing plugin code, the API surface, permissions and UI in iframes
- Implement a sandboxed JavaScript execution environment using an isolated iframe or worker, with a clearly defined security boundary
- Audit a page for DOM security mistakes: inline handlers, javascript: URLs, reverse tabnabbing, iframe sandboxes and HTTP forms
- 10How does single sign-on (SSO) work?
Lesson, 4 min read
- 11Iframe cookies: how do cookies work in a cross-site iframe?
Lesson, 9 min read, then 2 questions to practise
- 12SameSite cookies: Strict vs Lax vs None explained
Lesson, 4 min read
- 13Session cookies vs JWT: how should a frontend handle auth?
Lesson, 4 min read
- 14Should you store a JWT in localStorage or a cookie?
Lesson, 4 min read
- 15Symmetric vs asymmetric encryption: what is the difference?
Lesson, 5 min read
- 16What are passkeys and how does WebAuthn work?
Lesson, 5 min read, then 1 question to practise
- 18What does the OWASP Top 10 mean for frontend developers?
Lesson, 5 min read, then 2 questions to practise
- 19What is a Content Security Policy (CSP)?
Lesson, 4 min read, then 3 questions to practise
- Roll out a strict Content Security Policy for an app with inline scripts and third-party analytics
- Evaluate a Content-Security-Policy: 'self', nonces, hashes, wildcards, default-src fallback and 'strict-dynamic'
- Design resilient third-party script loading so a slow or broken vendor never breaks checkout
- 20What is a man-in-the-middle attack and how does HTTPS stop it?
Lesson, 4 min read, then 1 question to practise
- 21What is an open redirect and how do you prevent it?
Lesson, 4 min read, then 1 question to practise
- 22What is clickjacking, and how do you prevent it?
Lesson, 4 min read
- 23What is CSRF, and how do you prevent it?
Lesson, 5 min read
- 24What is HSTS and why does it matter?
Lesson, 4 min read
- 25What is JSONP and why did CORS replace it?
Lesson, 5 min read
- 26What is session hijacking and how do you prevent it?
Lesson, 5 min read, then 1 question to practise
- 27What is Subresource Integrity (SRI)?
Lesson, 4 min read, then 1 question to practise
- 28What is XSS, and how do you prevent it?
Lesson, 4 min read, then 1 question to practise
- 29Which HTTP security headers should every site send?
Lesson, 4 min read, then 1 question to practise
- 30XSS vs CSRF: what is the difference?
Lesson, 4 min read
Chapter 3, advanced
Senior level
Trade-offs, edge cases and the questions senior rounds end on.
- 31How do you protect a frontend from npm supply-chain attacks?
Lesson, 5 min read, then 3 questions to practise
- 32How do you safely render user-generated HTML?
Lesson, 5 min read, then 2 questions to practise
- 33OAuth 2.0 and OpenID Connect explained for frontend developers
Lesson, 5 min read
- 34What are Trusted Types and how do they stop DOM XSS?
Lesson, 5 min read
- 35What is prototype pollution and how do you prevent it?
Lesson, 4 min read, then 1 question to practise