Menu

The seven security headers, and copy-paste config for nginx, Express and Next.js
📰

The seven security headers, and copy-paste config for nginx, Express and Next.js

DEV Community: nextjs·Anas Charfi·3 days ago
#OmTKFEEd
#devtonextjs#devto#dev#policy#origin
Long article (988 words) — no AI summary yet.
Reading 0:00
15s threshold

In our study of 4,326 top websites , the average homepage sent 2.78 of the seven browser security headers, and 23% sent none. Most of the gap is not hard engineering. It's five to ten lines of config nobody got around to.

This post is the config. For each header: what it does, a safe starting value, and the one thing that can break.

1. Strict-Transport-Security (HSTS)

Tells the browser to use HTTPS for your domain for the next N seconds, even if someone types http:// .

Strict-Transport-Security: max-age = 31536000 ; includeSubDomains

Enter fullscreen mode

Exit fullscreen mode

Can break: any subdomain that still serves plain HTTP. Start with max-age=300 and no includeSubDomains if you're unsure, then raise it. Only add preload once you mean it: removal from the preload list takes months.

2. Content-Security-Policy (CSP)

Restricts where scripts, styles, images and frames may load from.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.