Helmet
Express middleware that sets security-related HTTP headers such as CSP, HSTS, frame protection, and referrer policy with configurable defaults.
Official Documentation ↗Helmet 7.x/8.x; header defaults change between major versions and should be reviewed on upgrade. Check the official docs for the latest API surface.Installation
npm install helmetpnpm add helmetyarn add helmetMethods
No methods match this filter.
Helmet sets security-related response headers for Express. It is a collection of small middlewares, not an application firewall. Review each header, test it against the real frontend, and keep the policy as strict as the product allows.
Content Security Policy
CSP is the highest-value header and the easiest to break. Start in report-only mode, collect violations, then enforce. Prefer nonces or hashes for scripts, restrict frame-src to known embed providers, and avoid unsafe-inline for scripts.
Headers need context
HSTS requires HTTPS and a plan for every subdomain. frameguard and CSP frame-ancestors protect against clickjacking but can break legitimate embedding. Referrer policy and cross-origin policies affect third-party resources. Test in staging with the actual page, not only an API health check.
Security notes
Quoted from the official documentation (https://helmetjs.github.io/); this is not a complete threat model.
- It sets HTTP response headers such as Content-Security-Policy and Strict-Transport-Security . (https://helmetjs.github.io/)
- See MDN’s introductory article on Content Security Policy . (https://helmetjs.github.io/)
- See “Referer header: privacy and security concerns” and the header’s documentation on MDN for more. (https://helmetjs.github.io/)
FAQ
- Does Helmet make an application secure?
- No. It sets useful response headers. Authentication, authorization, input validation, dependency updates, and secure cookies remain application responsibilities.
- Why did enabling Helmet break my inline scripts?
- The default Content-Security-Policy blocks inline scripts. Use nonces or hashes, move scripts to files, and scope the policy instead of adding unsafe-inline broadly.
- Should I enable HSTS preload immediately?
- No. Preload is difficult to reverse and requires every subdomain to be HTTPS-only. Start with a short max-age, verify, then increase and consider preload deliberately.
Report a problem with this API docOpens a pre-filled issue on GitHub.