All jobs / Frontend / web developer / Security
Frontend / web developer interview question · 3–5 years
You need a small inline boot script but CSP forbids unsafe-inline. What do you do?
The strongest answer
Give that script a nonce or hash; keep unsafe-inline and eval off; load analytics only after consent
Why it works
CSP is doing its job. Nonce- or hash-based allowlists are the supported door.
What a good answer covers
- Keep a strict CSP.
- Nonce or hash the boot script.
- No eval, no unsafe-inline.
- Third-party tags wait for consent.
Answers that fall short
- Close, but not the strongest: Turn unsafe-inline back on for one script
unsafe-inline for one is unsafe-inline for all inline. - Weak: Disable CSP in production
No CSP is not a launch plan. - Red flag: Check in a static nonce that never changes
A static nonce is a public password.
Who gets asked this
More Security questions
- 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?
- 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?