Security javascript Intermediate

Helmet.js Config for Express

Production-ready Helmet.js configuration with CSP, HSTS and other security headers.

javascript
const helmet = require('helmet');
app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      scriptSrc:  ["'self'", "'unsafe-inline'"],
      styleSrc:   ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],
    },
  },
  hsts: { maxAge: 63072000, includeSubDomains: true, preload: true },
  frameguard: { action: 'sameorigin' },
}));

Prerequisites

  • helmet >= 7
  • express >= 4

Pro Tips

  • → Test CSP in report-only mode first.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
javascript
Level
Intermediate
Read time
3 min
Published
Feb 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.