Skip to the page

Cross-cutting concerns (the O in RADIO) · senior

Frontend security in a design round

Name the threats this product has (XSS from user content, CSRF on cookie sessions, token theft, clickjacking, risky third-party code) and the defence for each: escaping and sanitising, CSP, SameSite cookies plus CSRF tokens, HttpOnly cookies, frame-ancestors, and SRI with sandboxed iframes.

The notes

What you must know

  • XSS: React escapes text, but dangerouslySetInnerHTML, javascript: URLs in href and innerHTML are open doors. Sanitise rich HTML (DOMPurify), allow-list URL schemes, add a CSP with nonces as defence in depth; Trusted Types make DOM sinks safe by default (React 19.3 supports them).
  • CSRF: another site makes the user's browser send a request with your cookies. Defences (OWASP): synchronizer or signed double-submit tokens, a custom header for API calls (forces a CORS preflight), checking Origin / Sec-Fetch-Site; SameSite=Lax/Strict cookies are defence in depth, not the whole fix. Never change state with GET. Any XSS defeats CSRF defences.
  • Tokens: prefer an HttpOnly, Secure, SameSite session cookie (JavaScript can't read it). If you must use bearer tokens, keep the access token in memory, short-lived, refreshed through an HttpOnly cookie; avoid long-lived tokens in localStorage.
  • Clickjacking: Content-Security-Policy: frame-ancestors 'none' (or X-Frame-Options: DENY).
  • Third-party code: SRI on CDN scripts, sandboxed iframes for widgets, strict postMessage origin checks, least privilege.
  • Payments: card fields live in the gateway's iframe or page (PCI scope), never in your DOM.
  • The server is the authority: validate and authorise every request; Server Actions and route handlers are public endpoints; NEXT_PUBLIC_ variables are public.
  • Supply chain and patching: lockfiles, audits, fast upgrades (Next.js ships monthly security releases; React2Shell, CVE-2025-55182, was an RSC remote-code-execution bug in December 2025).

The red pen

Common traps: mistake → fix

  • Mistake: React prevents all XSS

    Fix: not dangerouslySetInnerHTML, not javascript: URLs, not third-party scripts.

  • Mistake: SameSite=Lax alone stops CSRF

    Fix: it is defence in depth; Lax still sends cookies on top-level GET navigations.

  • Mistake: CORS protects the API from CSRF

    Fix: CORS controls who can READ responses; simple cross-site requests are still sent.

  • Mistake: Hiding the key in an env variable keeps it secret

    Fix: anything bundled into client JavaScript is public.

Easy to hard

Questions interviewers ask, easy to hard

  1. What security risks does this design have?
  2. What is CSRF? How do SameSite cookies help, and why are they not enough alone?
  3. Where do you store auth tokens in a web app and why?
  4. You embed a third-party payment widget. How do you keep both sides safe?

Practise

Practise with these questions

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.

Start your free interview