IntermediateBEHAVIORAL
Describe a time you introduced or improved security practices in a Next.js application (e.g., handling auth tokens, XSS, CSRF, or protecting API routes). What prompted the change and how did you ensure the team adopted it?
Next.js Developer
General

Sample Answer

At my last company, we had a Next.js dashboard where auth tokens were stored in localStorage and passed to API routes via headers. During a quick internal security review, I demonstrated how easy it was for an XSS to exfiltrate tokens. That was the catalyst to tighten things up. I proposed moving to HttpOnly, secure cookies managed by NextAuth and enforcing server-side session checks in getServerSideProps and API routes. I also added a default Content Security Policy via next-safe and locked down allowed origins. We created a short 30-minute security walkthrough for the frontend team, plus code snippets in our internal docs showing the “new way” to access user state. Within one sprint, we migrated 90% of flows, eliminated token access from the client, and passed an external pen test with zero high-severity findings.

Keywords

Identified concrete risk with tokens in localStorage and XSS exposureMoved to HttpOnly cookies and server-side session validation in Next.jsImplemented CSP and documented secure patterns for the teamMeasured impact via migration coverage and pen test results