All jobs / Frontend / web developer / Security
Frontend / web developer interview question · 1–3 years
A cookie-session SPA posts state-changing requests. What do you do in the browser about CSRF?
The strongest answer
Use SameSite=Lax or Strict cookies, send a CSRF token or a custom header on mutations, and don't assume Origin is always present
Why it works
Cookie auth means CSRF is your problem: SameSite plus a token or custom header on POST/PUT/DELETE.
What a good answer covers
- Cookie sessions need CSRF defenses.
- SameSite on the cookie.
- Token or custom header on mutations.
- Don't 'fix' CSRF by moving secrets into JS storage without owning XSS.
Answers that fall short
- Close, but not the strongest: Rely on SameSite alone even though we still allow a cross-site embed
SameSite helps; embeds and some older browsers are why teams still send a token. - Weak: Move the token to localStorage so 'CSRF is not a thing', and skip talking about XSS
localStorage tokens dodge CSRF and become XSS loot — name that trade-off if you choose it. - Red flag: Disable SameSite and CORS to make every tool work
Turning platform security off is not an architecture.
Who gets asked this
More Security questions
- Auth token in localStorage versus an httpOnly cookie for a SPA — how do you argue it?
- You need a small inline boot script but CSP forbids unsafe-inline. What do you do?
- Two 401s trigger two refresh calls and one of them logs the user out. How do you design the client?
- Product wants full click tapes plus form field values in the frontend logger. How do you respond?
- Legal says marketing pixels cannot run before consent. How do you architect the frontend?
- A junior's PR works but has an XSS hole and no tests. How do you mentor in review?
- How do you keep consent state consistent across web, a WebView, and a pixel manager?
- Marketing wants to render a CMS HTML snippet in React. Strongest answer?