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.
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.
Similar Modules
TOTP Two-Factor Auth
Generate and verify time-based one-time passwords (TOTP) compatible with Google Authenticator.
python
·
Advanced
Express CSRF Protection with Double Submit
Implement double-submit CSRF protection in Express without server-side session storage.
javascript
·
Intermediate
ClamAV Malware Scanner Cron
Run ClamAV on upload directory and quarantine infected files automatically.
bash
·
Advanced