Practical insights
HSTS & CSP - quick security wins
Practical improvements in minutes: basic controls that help reduce common attack risks.
Published:
Why headers matter
Security headers are inexpensive, verifiable controls that can improve protection. They do not replace input validation or authentication design, but can reduce exposure and limit the impact of mistakes.
Five quick wins
- HSTS - enforces HTTPS and helps prevent protocol downgrades and cookie exposure.
- X-Frame-Options or frame-ancestors (in CSP) - helps prevent clickjacking by restricting embedding.
- X-Content-Type-Options: nosniff - prevents MIME type sniffing.
- Referrer-Policy - limits disclosure of sensitive URL parameters.
- Content-Security-Policy - a minimal, restrictive policy for scripts, frames and resource sources.
A practical starting point for CSP
Content-Security-Policy:
default-src 'self';
script-src 'self' 'strict-dynamic' 'nonce-<random>';
object-src 'none';
base-uri 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
Use nonces for initial scripts, avoid wildcards and add reporting during rollout.
Verification and deployment
- Start CSP in report-only mode in staging.
- Automate CI checks for headers and the TLS profile.
- Record expected behavior with production smoke tests.
Key takeaways
- Headers can offer useful protection with limited implementation effort.
- Avoid weak defaults and strengthen them incrementally.
- Support header changes with appropriate fixes in the application code and files.