Purpose of Helmet middleware in Express
Awareness of HTTP security headers and defense in depth.
Helmet sets safe response headers like X-Content-Type-Options, HSTS, and CSP, mitigating MIME-sniffing, clickjacking, and protocol downgrade.
WHAT THIS TESTS: Whether you know that browsers honor security-relevant HTTP headers, that Express ships without them, and that headers are a cheap layer of defense in depth, not a silver bullet.
A GOOD ANSWER COVERS: Helmet is Express middleware that sets a bundle of HTTP response headers to safer defaults with a single app.use call. Key headers it manages: X-Content-Type-Options: nosniff prevents browsers from MIME-sniffing a response into an unintended content type, which can turn an uploaded file into executable script. Strict-Transport-Security (HSTS) tells browsers to only connect over HTTPS, mitigating protocol downgrade and SSL-stripping. X-Frame-Options or the CSP frame-ancestors directive mitigates clickjacking by forbidding the page from being embedded in a frame. Helmet can also set a Content-Security-Policy and removes the X-Powered-By header so you stop advertising Express. Crucially, these headers harden the client side; they do not validate input or fix application logic.
COMMON WRONG ANSWERS: Saying Helmet sanitizes user input or prevents SQL injection (it does not). Claiming installing Helmet makes the app secure on its own. Confusing it with CORS configuration. Disabling its CSP and assuming the rest still protects you fully.
LIKELY FOLLOW-UPS: Which header stops clickjacking and how? What does nosniff actually prevent? Why might you customize Helmet's default CSP? What is the risk of leaking X-Powered-By?
ONE CONCRETE EXAMPLE: An app serves user-uploaded files. Without X-Content-Type-Options: nosniff, a browser might sniff a file declared as text/plain and execute it as HTML/JavaScript, enabling XSS. Helmet's nosniff header forces the browser to respect the declared content type, closing that vector.
Read the original → helmet.js.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.