HTTP → HTTPS redirect
Plain http:// requests should be sent to https:// with a permanent redirect.
Without it, a visitor who types your domain can land on an unencrypted page that can be read or changed on the way.
# nginx
return 301 https://$host$request_uri;
# Cloudflare: SSL/TLS → Edge Certificates → Always Use HTTPS
HSTS
The Strict-Transport-Security header tells browsers to use only HTTPS for your domain, for a set time.
It closes the gap where a first request over plain HTTP can be intercepted and downgraded.
Strict-Transport-Security: max-age=31536000; includeSubDomains
Add includeSubDomains only once every subdomain works over HTTPS.
Content-Security-Policy
A list of sources the browser may load scripts, styles and other content from.
It limits what an injected script can do. 'unsafe-inline' and 'unsafe-eval' remove most of that protection.
# 1. observe first
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self'
# 2. then enforce
Content-Security-Policy: default-src 'self'; script-src 'self'; frame-ancestors 'none'
X-Content-Type-Options
Stops browsers from guessing what kind of file they received.
Without it, a file uploaded as an image could be treated as a script.
X-Content-Type-Options: nosniff
Clickjacking protection
Controls which sites may show your page inside a frame.
Attackers can place your page invisibly under their own and trick users into clicking buttons on it.
Content-Security-Policy: frame-ancestors 'none'
# older browsers
X-Frame-Options: DENY
Referrer-Policy
Controls how much of the current address is sent to other sites when a visitor follows a link.
Full addresses can leak tokens, IDs or internal paths.
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy
Switches off browser features your site does not use.
An injected script or embedded third party then cannot ask for the camera, microphone or location.
Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
Cookies on first visit
Flags that protect cookies your site sets.
Without Secure a cookie can travel over plain HTTP, without HttpOnly scripts can read it, and without SameSite it is sent with requests from other sites.
Set-Cookie: session=…; Secure; HttpOnly; SameSite=Lax
security.txt
A small text file at /.well-known/security.txt that says where to report a security problem (RFC 9116).
Without it, someone who finds a hole in your site has to guess who to tell, and reports get lost or go public instead.
# https://yourdomain.com/.well-known/security.txt
Contact: mailto:security@yourdomain.com
Expires: 2027-11-01T00:00:00.000Z
Preferred-Languages: en, de
Expires is required. Set it less than a year ahead and renew it before it runs out.
SPF
A DNS record listing the servers allowed to send email for your domain.
Without it, receivers have no list to check, and anyone can send mail that claims to come from you.
# TXT record on yourdomain.com (example: Google Workspace)
v=spf1 include:_spf.google.com ~all
Keep exactly one SPF record per domain and end it with ~all or -all, never +all.
DMARC
A DNS record that tells receivers what to do with mail that fails SPF and DKIM.
It turns SPF and DKIM into real protection: spoofed mail goes to spam or is refused.
# TXT record on _dmarc.yourdomain.com
v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com # 1. monitor
v=DMARC1; p=quarantine # 2. spam folder
v=DMARC1; p=reject # 3. refuse
Move to quarantine and reject only once all your legitimate mail passes.