Security & Best Practices Interview Questions (Node.js)
10 Security & Best Practices questions from the Node.js track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Mid-level
How do symmetric (HS256) and asymmetric (RS256) signing algorithms differ for JWTs in Node.js?
HS256 uses the same shared secret to sign and verify, while RS256 uses a private key to sign and a public key, which can be shared, to verify.
Read the full explanation - Senior
How do you implement Refresh Token Rotation and secure storage in cookies?
Store the Refresh Token in a Cookie protected by HttpOnly and SameSite; each use invalidates the current token and creates a new pair, and reuse of a revoked token invalidates the user's entire token family.
Read the full explanation - Junior
Why should you never use SHA-256 functions to hash passwords, and why are Argon2 or bcrypt preferred?
SHA functions are fast and designed for general-purpose hashing, making billions of GPU guesses practical; bcrypt and Argon2 are deliberately slow and resistant to GPU and memory attacks.
Read the full explanation - Mid-level
How do Cross-Site Request Forgery (CSRF) attacks work, and how do you protect Node.js applications from them?
They occur when a malicious site tricks a victim's browser into sending your site an unauthorized request with the victim's cookies; protection includes a CSRF Token and SameSite=Lax/Strict.
Read the full explanation - Junior
What is Cross-Origin Resource Sharing (CORS), and what are Preflight Requests?
CORS is a browser security mechanism that prevents external sites from reading your data; a Preflight is an OPTIONS request the browser sends before the actual request to check whether it is allowed.
Read the full explanation - Junior
What is the Helmet package, and which essential security headers does it add to a Node.js application?
It is middleware that adds standard security headers such as Content-Security-Policy, Strict-Transport-Security, and X-Frame-Options, and hides the X-Powered-By header.
Read the full explanation - Senior
What is JavaScript Prototype Pollution, and how do you avoid it in Node.js?
It is a vulnerability that lets an attacker inject malicious properties into the shared Object.prototype through deeply merged objects containing __proto__, changing application behavior.
Read the full explanation - Junior
How do you manage environment variables and Secrets safely in Node.js projects?
Store them in system environment variables (process.env) instead of source code or Git, and validate that they exist at startup with a strict schema.
Read the full explanation - Senior
What are Timing Attacks, and why should crypto.timingSafeEqual be used to compare sensitive tokens?
These attacks measure the server's response time in nanoseconds to infer how many characters matched before failure; timingSafeEqual prevents this by comparing bytes in constant time.
Read the full explanation - Mid-level
How do you protect a Node.js project from Supply Chain Attacks in the npm ecosystem?
Use npm audit, pin exact versions, enable --ignore-scripts, scan dependencies with static analysis tools, and rely on a trusted lockfile.
Read the full explanation