Web platform · 19 concepts
Web security
Explain how real browser attacks work (XSS, CSRF, clickjacking, supply chain) and defend a web app against them.
Asked in these mock interviews
Part 1 · 3 concepts
The browser's security model
- 01
Origin, site and the same-origin policy
An origin is scheme + host + port, a site is scheme + registrable domain (eTLD+1), and the same-origin policy stops a page from READING another origin's responses, DOM…
- 02
CORS exactly: simple requests, preflight and credentials
CORS is a way for a SERVER to tell the browser which other origins may read its responses, using Access-Control-* headers; non-simple requests get an OPTIONS preflight…
- 03
HTTPS, HSTS and the other security headers
HTTPS protects data in transit, HSTS forces browsers to use HTTPS for your domain, and a short list of response headers (CSP, X-Content-Type-Options, Referrer-Policy…
Part 2 · 5 concepts
XSS and injection in the browser
- 04
XSS: stored, reflected and DOM-based; sources and sinks
Cross-site scripting is when attacker-controlled data runs as code in your page's origin, either stored on the server, reflected from the request, or created by your…
- 05
XSS in React and Next.js: what React protects and where it does not
React escapes text you render in JSX, so most XSS needs an escape hatch: dangerouslySetInnerHTML, user-controlled URLs, server-rendered JSON in a script tag, refs that…
- 06
Content Security Policy: strict CSP with nonces, hashes and strict-dynamic
A strict CSP allows only scripts that carry a per-response nonce or a known hash, uses 'strict-dynamic' so those trusted scripts can load others, blocks plugins and…
- 07
Trusted Types: locking down DOM XSS sinks
With the CSP directive require-trusted-types-for 'script', dangerous DOM sinks like innerHTML and script.src stop accepting plain strings and only accept typed values…
- 08
Prototype pollution
Prototype pollution happens when code copies attacker-controlled keys like proto into objects (deep merge, set-by-path, query-string parsing), adding properties to…
Part 3 · 6 concepts
Cookies, CSRF and cross-window attacks
- 09
Cookies in depth: attributes, SameSite, prefixes, partitioning
A session cookie should be HttpOnly (no JS access), Secure (HTTPS only), SameSite=Lax or Strict (not sent on most cross-site requests), host-only with the __Host…
- 10
CSRF: how the attack works, step by step
Cross-site request forgery tricks a logged-in user's browser into sending a state-changing request to your site from another site; it works because the browser attaches…
- 11
CSRF defences: tokens, SameSite, Fetch Metadata and Origin checks
Defend every state-changing endpoint with a check the attacker cannot pass: a CSRF token tied to the session (synchronizer or signed double-submit), or a Fetch Metadata…
- 12
Clickjacking and frame-ancestors
Clickjacking loads your page in an invisible iframe on an attacker's page so the user clicks your buttons without knowing; you stop it with the CSP frame-ancestors…
- 13
Iframes, sandboxing and postMessage origin checks
When you embed or are embedded, sandbox untrusted iframes, send postMessage only to an exact targetOrigin, and in every message listener check event.origin against an…
- 14
Open redirects and URL validation
An open redirect lets an attacker use your trusted domain to send users anywhere (/login?next=https://evil.example), which powers phishing and OAuth token theft; you…
Part 4 · 2 concepts
Authentication in the frontend
- 15
Where to keep sessions and tokens: cookie, memory, localStorage, BFF
There is no perfect place: localStorage is readable by any XSS, in-memory tokens are lost on reload, HttpOnly cookies hide the token from JS but need CSRF defences, and…
- 16
OAuth 2.0 and OpenID Connect with PKCE, at a frontend level
OAuth gives an app an access token to call an API on the user's behalf, OpenID Connect adds an ID token that says who the user is, and browser and mobile apps must use…
Part 5 · 3 concepts
Code you did not write, and secrets you should not ship
- 17
Supply-chain risk: npm, lockfiles, install scripts and SRI
Most of your bundle is other people's code, so a compromised package or CDN runs with full access to your page and your CI; you reduce the risk with lockfiles and…
- 18
Secrets in frontend bundles and source maps
Everything shipped to the browser or an app binary is public, so only publishable keys (restricted by domain, app id or scope) may be in client code, environment…
- 19
OWASP Top 10 (2025) from a frontend engineer's view
The OWASP Top 10:2025 lists the most important web app risk categories, from Broken Access Control (still #1) to the new Software Supply Chain Failures (#3) and…
Your first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.