All jobs / Frontend / web developer / Security
Frontend / web developer interview question · 1–3 years
Marketing wants to render a CMS HTML snippet in React. Strongest answer?
The strongest answer
Don't put untrusted HTML through dangerouslySetInnerHTML — sanitize with a maintained library or store structured fields
Why it works
XSS is a browser issue you own. Prefer structured content; if HTML is required, sanitize on a known-good allowlist.
What a good answer covers
- Treat HTML as untrusted.
- Prefer structured fields over HTML.
- If you must render HTML, sanitize on an allowlist.
- Never mix raw user text into HTML strings.
Answers that fall short
- Close, but not the strongest: Use dangerouslySetInnerHTML and trust the CMS
CMS compromise or a confused editor is enough to lose the session. - Weak: Set innerHTML on a ref
A ref is the same hole without React's warning. - Red flag: Concatenate user comments into that HTML string
Mixing comments with HTML is a classic stored XSS path.
Who gets asked this
More Security questions
- A cookie-session SPA posts state-changing requests. What do you do in the browser about CSRF?
- 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?