Back to 20 Concepts
sessions-cookies • Beginner
HTTP Security Headers: HSTS, X-Content-Type-Options & Permissions-Policy
Security headers instruct browsers to enforce strict transport encryption, prevent MIME-sniffing drive-by downloads, and disable unused device hardware APIs (Camera, Microphone, Geolocation).
Intuitive Mental Model
The Building Safety Regulations: Security headers are the fire safety codes and exit signs posted in the building lobby; the browser follows these rules automatically to protect visitors from rogue construction.
Architecture Blueprint & CodeProduction Standard
// Helmet.js Security Headers Configuration:
import helmet from 'helmet';
app.use(helmet({
strictTransportSecurity: {
maxAge: 31536000, // 1 Year HSTS
includeSubDomains: true,
preload: true
},
noSniff: true, // X-Content-Type-Options: nosniff
xssFilter: true,
frameguard: { action: 'deny' } // X-Frame-Options: DENY (Stops clickjacking!)
}));Key Architectural Takeaways
- •HSTS (Strict-Transport-Security): Forces browsers to connect exclusively over HTTPS, preventing SSL-stripping Man-in-the-Middle attacks.
- •X-Frame-Options: DENY: Prevents malicious sites from embedding your application inside invisible iframes (Clickjacking defense).
Common Architectural Pitfall
Deploying web applications over HTTPS without HSTS headers, allowing initial unencrypted HTTP redirect requests to be intercepted.
Production Best Practice
Configure Strict-Transport-Security: max-age=31536000; includeSubDomains; preload.