Security headers protect your website from XSS, clickjacking and data injection attacks. Learn what each header does and how to implement them β with a free checker.
HTTP security headers are one of the most overlooked aspects of website security. They're simple lines in your server configuration that can prevent a wide range of attacks β yet most websites are missing several of them. Here's everything you need to know.
Security headers are HTTP response headers that instruct browsers on how to handle your site's content. They tell the browser whether to allow embedding in iframes, which external resources to trust, and whether to enforce HTTPS connections. They're set at the server level and take effect on every page load.
CSP is the most powerful β and most complex β security header. It defines which sources of content (scripts, styles, images, fonts) the browser is allowed to load. A properly configured CSP is one of the most effective defenses against Cross-Site Scripting (XSS), which is consistently in the OWASP Top 10.
HSTS tells browsers to only connect to your site over HTTPS β even if the user types 'http://' or clicks an HTTP link. This prevents SSL stripping attacks and ensures all connections are encrypted.
X-Frame-Options prevents your site from being embedded in iframes on other domains β protecting against clickjacking attacks, where attackers overlay invisible frames to trick users into clicking malicious content.
This header prevents browsers from 'sniffing' the MIME type of a response and interpreting files differently from what your server declared. Without it, a browser might execute a file uploaded as an image but containing JavaScript. Always set: X-Content-Type-Options: nosniff.
Controls how much referrer information is included when users navigate away from your site. Without this header, the full URL (including query parameters that might contain user IDs or tokens) is sent to external sites. Recommended: Referrer-Policy: strict-origin-when-cross-origin.
Formerly known as Feature-Policy, this header controls which browser features and APIs your page can use β camera, microphone, geolocation, payment, etc. Restricting these protects users if your site is compromised by a malicious third-party script.
Check which security headers your website is missing with Scanlei's free security scanner. Get a detailed report with remediation steps in under 60 seconds.
Scan your website freeAdd a headers() function to your next.config.js or next.config.ts to apply security headers to all routes. This is the recommended approach for Next.js applications and takes effect on every server response.
Add a headers array to vercel.json with source patterns and header key-value pairs. Changes deploy automatically on your next push and apply globally to your deployment.
Use add_header directives in your server block. Apply them at the server level to ensure headers are sent with all responses, including static files.